Jump to content

get an AcadPolyline out of the AcadBlockRef.Exlplode array


Dill

Recommended Posts

i want to explode blockrefs to have a closer look at the objects inside.

what i first tried is to retrieve the coordinates of a polyline inside a blockref.

 

but i get a "Type Mismatch" error when i set a polyline-ref to an object of the explode-array. (though it has ObjectName == AcDbPolyline).

 

If varEx(i).ObjectName = "AcDbPolyline" Then
 Set pl = varEx(i) 'ERROR: Type mismatch
  '(...)
End If

 

i need an AcadPolyline object to access the Coordinates property.

How is this done?

Im not used to VB but i find its object model rather confusing...

 

here is the full code:

 

 

Public Sub Test()
   Dim bref As AcadBlockReference
   Dim ent As AcadEntity
   Dim exp As Variant
   Dim pl As AcadPolyline
   
   For Each ent In ThisDrawing.ModelSpace
      
       If ent.ObjectName = "AcDbBlockReference" Then
       
           Set bref = ent
           Debug.Print "exploding", bref.Name
           Dim i As Double
   
           varEx = bref.Explode
           
           For i = 0 To UBound(varEx)
               Debug.Print varEx(i).ObjectName
               If varEx(i).ObjectName = "AcDbPolyline" Then
                   Set pl = varEx(i) 'ERROR: Type mismatch
                   '(...)
               End If
           Next
       
       End If
   Next
End Sub

 

thank you!

Link to comment
Share on other sites


SSET2.SelectOnScreen
For Each ent In SSET2
  If (TypeOf ent Is AutoCAD.AcadLWPolyline) Then
       Set lwpl = ent
       vtxs = lwpl.Coordinates
           For idx = LBound(vtxs) To UBound(vtxs) Step 2
               List1(0).AddItem vtxs(idx)
               List1(1).AddItem vtxs(idx + 1)
           Next idx
   End If
Next ent


 

Maybe experiment with setting to an object, then set the obj to the varEx return

Link to comment
Share on other sites

did i understand you correct:

 

Dim o As AcadObject
(...)
Set o = varEx(i)
Set pl = o

 

same error.

would it help to try .net or will i be using the same lib?

 

thanks for your help.

 

EDIT:

python does it.

heres an example with a .dwg containing nothing but a bref consiting of a 3 vertices polyline.

doesnt work with older acad version, tested here on acad 11.

>>> import win32com.client
>>> acad = win32com.client.Dispatch("AutoCAD.Application")
>>> doc = acad.ActiveDocument
>>> ms = doc.ModelSpace
>>>
>>> for item in ms:
...     print item.ObjectName
...
AcDbBlockReference
>>> bref = ms[0]
>>> exp = bref.Explode()
>>> exp
(<COMObject Explode>,)
>>> e=exp[0]
>>> e.ObjectName
u'AcDbPolyline'
>>> e.Coordinates
(1000.0, 500.0, 1000.0, 600.0, 1100.0, 600.0, 1100.0, 500.0, 1000.0, 500.0)

Edited by Dill
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...