Qoricino
Guest
salve a tutti. :biggrin:
devo riuscire a leggere tutti i testi presenti in una polilinea chiusa che formo tramite la funzione "mantieni contorni" della "creazione retino".
premetto che sto lavorando con autocad 2007 e vba.
all'interno della polilinea, creata sul layer "aree" si trovano 2 testi: primo su layer "areetesto" ed il secondo su layer "appartamenti".
il tutto mi serve per estrapolare in excel da immensi disegni tutte le aree ed i perimetri dei singoli locali.
il codice che al momento ho testato è il seguente. funziona, ma determinate aree me le salta, e non riesco a capire perchè dato che i testi inseriti sono tutti copie degli altri, ed ho verificato che fossero tutti mtext.:frown::frown:
qualcuno può aiutarmi??
grazie!!!!
public sub areetoexcelapp()
dim scala as integer
dim str as string
str = "importante: tutte le aree ed i testi delle stanze devono essere su layer " & chr(34) & "aree" & chr(34) & vbcrlf
str = str & "la numerazione degli alloggi deve essere posizionato sul layer " & chr(34) & "appartamenti" & chr(34) & vbcrlf & vbcrlf
str = str & "1 m corrisponde a: "
scala = inputbox(str, "scala disegno", 100)
dim oent as acadentity
dim punti3d as variant
dim sset as acadselectionset
dim sset1 as acadselectionset
dim element as acadmtext
dim element1 as acadmtext
dim elmod as acadmtext
dim filtertype(0) as integer
dim filterdata(0) as variant
dim coord as variant
dim appart, msg as string
dim area, cornice as double
'creazione file excel
dim excel as object
dim excelsheet as object
on error resume next
set excel = getobject(, "excel.application")
if err <> 0 then
err.clear
set excel = createobject("excel.application")
if err <> 0 then
msgbox "could not load excel.", vbexclamation
end
end if
end if
on error resume next
excel.visible = true
excel.workbooks.add
excel.sheets("foglio1").select
set excelsheet = excel.activeworkbook.sheets("foglio1")
dim cc as integer
cc = 1
excelsheet.cells(cc, 5).value = "unità"
excelsheet.cells(cc, 1).value = "n°"
excelsheet.cells(cc, 2).value = "locale"
excelsheet.cells(cc, 3).value = "area"
excelsheet.cells(cc, 4).value = "cornice"
'excelsheet.cells(cc, 5).value = "watt"
cc = cc + 1
'tutte le entità prensenti nel modello
for each oent in thisdrawing.modelspace
'se è sul layer "aree"
if typeof oent is acadlwpolyline then
if oent.layer = "aree" then
msg = ""
appart = ""
set elmod = nothing
'se l'entità è una polilinea
'if typeof oent is acadlwpolyline then
oent.highlight true
'inizio ------
on error resume next
' delete the selection set if it exists
if not isnull(thisdrawing.selectionsets.item("element")) then
set sset = thisdrawing.selectionsets.item("element")
sset.delete
end if
set sset = thisdrawing.selectionsets.add("element")
'sset.additems (oent)
'sset.selectonscreen
'coord = sset.item(0).coordinates
coord = oent.coordinates
x = ((ubound(coord) - 1) / 2) + ubound(coord)
redim punti3d(0 to x + 1) as double
u = 0
for i = 0 to ubound(coord) step 2
punti3d(u) = coord(i)
punti3d(u + 1) = coord(i + 1)
u = u + 2
punti3d(u) = 0
u = u + 1
next i
' delete the selection set if it exists
if not isnull(thisdrawing.selectionsets.item("element1")) then
set sset1 = thisdrawing.selectionsets.item("element1")
sset1.delete
end if
set sset1 = thisdrawing.selectionsets.add("element1")
filtertype(0) = 0
filterdata(0) = "mtext"
sset1.selectbypolygon acselectionsetwindowpolygon, punti3d, filtertype, filterdata
'msgbox ("elementi selezionati:" & sset1.count)
z = 1
thisdrawing.regen acallviewports
for each element1 in sset1
if element1.layer = "appartamenti" then
appart = element1.textstring
set elmod = nothing
set elmod = element1
else
if element1.layer = "areetesto" then
if isnumeric(vba.left(element1.textstring, 1)) = false then
element1.highlight true
if vba.left(element1.textstring, 1) = "{" then
msg = puliscitesto(element1.textstring)
set elmod = element1
else
msg = element1.textstring
set elmod = element1
end if
'msgbox msg
'msgbox ("oggetto" & z & ":" & element1.name & vblf & "punto inserimento" & vblf & "x: " & element1.insertionpoint(0) & vblf & "y: " & element1.insertionpoint(1) & vblf & "rotazione: " & (element1.rotation) / pigreco * 180)
z = z + 1
element1.highlight false
else
msg = ""
end if
end if
end if
next
if msg <> "" then
if oent.area > 0 and oent.length > 0 then
excelsheet.cells(cc, 1).value = cc - 1
excelsheet.cells(cc, 2).value = msg
excelsheet.cells(cc, 3).value = arrotonda_eccesso(oent.area / scala ^ 2, 1)
excelsheet.cells(cc, 4).value = arrotonda_eccesso((oent.length - 1) / scala, 0)
excelsheet.cells(cc, 5).value = appart
'aggiungere numero stanza con pallino
elmod.textstring = cc - 1 & " - " & elmod.textstring
cc = cc + 1
end if
end if
'fine -----
oent.highlight false
end if
end if
next oent
end sub
devo riuscire a leggere tutti i testi presenti in una polilinea chiusa che formo tramite la funzione "mantieni contorni" della "creazione retino".
premetto che sto lavorando con autocad 2007 e vba.
all'interno della polilinea, creata sul layer "aree" si trovano 2 testi: primo su layer "areetesto" ed il secondo su layer "appartamenti".
il tutto mi serve per estrapolare in excel da immensi disegni tutte le aree ed i perimetri dei singoli locali.
il codice che al momento ho testato è il seguente. funziona, ma determinate aree me le salta, e non riesco a capire perchè dato che i testi inseriti sono tutti copie degli altri, ed ho verificato che fossero tutti mtext.:frown::frown:
qualcuno può aiutarmi??
grazie!!!!
public sub areetoexcelapp()
dim scala as integer
dim str as string
str = "importante: tutte le aree ed i testi delle stanze devono essere su layer " & chr(34) & "aree" & chr(34) & vbcrlf
str = str & "la numerazione degli alloggi deve essere posizionato sul layer " & chr(34) & "appartamenti" & chr(34) & vbcrlf & vbcrlf
str = str & "1 m corrisponde a: "
scala = inputbox(str, "scala disegno", 100)
dim oent as acadentity
dim punti3d as variant
dim sset as acadselectionset
dim sset1 as acadselectionset
dim element as acadmtext
dim element1 as acadmtext
dim elmod as acadmtext
dim filtertype(0) as integer
dim filterdata(0) as variant
dim coord as variant
dim appart, msg as string
dim area, cornice as double
'creazione file excel
dim excel as object
dim excelsheet as object
on error resume next
set excel = getobject(, "excel.application")
if err <> 0 then
err.clear
set excel = createobject("excel.application")
if err <> 0 then
msgbox "could not load excel.", vbexclamation
end
end if
end if
on error resume next
excel.visible = true
excel.workbooks.add
excel.sheets("foglio1").select
set excelsheet = excel.activeworkbook.sheets("foglio1")
dim cc as integer
cc = 1
excelsheet.cells(cc, 5).value = "unità"
excelsheet.cells(cc, 1).value = "n°"
excelsheet.cells(cc, 2).value = "locale"
excelsheet.cells(cc, 3).value = "area"
excelsheet.cells(cc, 4).value = "cornice"
'excelsheet.cells(cc, 5).value = "watt"
cc = cc + 1
'tutte le entità prensenti nel modello
for each oent in thisdrawing.modelspace
'se è sul layer "aree"
if typeof oent is acadlwpolyline then
if oent.layer = "aree" then
msg = ""
appart = ""
set elmod = nothing
'se l'entità è una polilinea
'if typeof oent is acadlwpolyline then
oent.highlight true
'inizio ------
on error resume next
' delete the selection set if it exists
if not isnull(thisdrawing.selectionsets.item("element")) then
set sset = thisdrawing.selectionsets.item("element")
sset.delete
end if
set sset = thisdrawing.selectionsets.add("element")
'sset.additems (oent)
'sset.selectonscreen
'coord = sset.item(0).coordinates
coord = oent.coordinates
x = ((ubound(coord) - 1) / 2) + ubound(coord)
redim punti3d(0 to x + 1) as double
u = 0
for i = 0 to ubound(coord) step 2
punti3d(u) = coord(i)
punti3d(u + 1) = coord(i + 1)
u = u + 2
punti3d(u) = 0
u = u + 1
next i
' delete the selection set if it exists
if not isnull(thisdrawing.selectionsets.item("element1")) then
set sset1 = thisdrawing.selectionsets.item("element1")
sset1.delete
end if
set sset1 = thisdrawing.selectionsets.add("element1")
filtertype(0) = 0
filterdata(0) = "mtext"
sset1.selectbypolygon acselectionsetwindowpolygon, punti3d, filtertype, filterdata
'msgbox ("elementi selezionati:" & sset1.count)
z = 1
thisdrawing.regen acallviewports
for each element1 in sset1
if element1.layer = "appartamenti" then
appart = element1.textstring
set elmod = nothing
set elmod = element1
else
if element1.layer = "areetesto" then
if isnumeric(vba.left(element1.textstring, 1)) = false then
element1.highlight true
if vba.left(element1.textstring, 1) = "{" then
msg = puliscitesto(element1.textstring)
set elmod = element1
else
msg = element1.textstring
set elmod = element1
end if
'msgbox msg
'msgbox ("oggetto" & z & ":" & element1.name & vblf & "punto inserimento" & vblf & "x: " & element1.insertionpoint(0) & vblf & "y: " & element1.insertionpoint(1) & vblf & "rotazione: " & (element1.rotation) / pigreco * 180)
z = z + 1
element1.highlight false
else
msg = ""
end if
end if
end if
next
if msg <> "" then
if oent.area > 0 and oent.length > 0 then
excelsheet.cells(cc, 1).value = cc - 1
excelsheet.cells(cc, 2).value = msg
excelsheet.cells(cc, 3).value = arrotonda_eccesso(oent.area / scala ^ 2, 1)
excelsheet.cells(cc, 4).value = arrotonda_eccesso((oent.length - 1) / scala, 0)
excelsheet.cells(cc, 5).value = appart
'aggiungere numero stanza con pallino
elmod.textstring = cc - 1 & " - " & elmod.textstring
cc = cc + 1
end if
end if
'fine -----
oent.highlight false
end if
end if
next oent
end sub