VBA GetObject doesn't get all lines?

VBA GetObject doesn't get all lines?

Anonymous
Not applicable
681 Views
2 Replies
Message 1 of 3

VBA GetObject doesn't get all lines?

Anonymous
Not applicable

I have code below that contains the issue, and an image that shows the difference. The red/orange objects I have drawn, the grey ones have been imported. Why does the code only apply to the drawn lines, and how can I make it apply to ALL lines? Red = Drawn, grey = importedRed = Drawn, grey = imported

 

    Set objApp = GetObject(, "AutoCAD.Application")
    Set objDoc = objApp.ActiveDocument
    Dim ang As Double
    For Each Obj In objDoc.ModelSpace
        On Error Resume Next
        ang = Obj.Angle
        ang = Round(ang * 180 / pi, 0)
        If Err.Number <> 0 Then
            Err.Clear
            GoTo jump_nextObj
        End If
        Obj.Select
        Debug.Print ang * 180 / pi
        'If Obj.Length > 480 And ang * 180 / pi = 0 Then
        If Obj.Length > 10 Then
            If ang = 0 Or ang = 90 Or ang = 270 Then
                Obj.Color = 1
            End If
        End If
0 Likes
682 Views
2 Replies
Replies (2)
Message 2 of 3

pendean
Community Legend
Community Legend
0 Likes
Message 3 of 3

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> an image that shows the difference

Please, as you are developer, I can ask you then:

Please click into the image and let me then know if the grey lines are of type:

  • lines
  • polylines
  • splines
  • block
  • ...something else

I guess in the image you can't identify the type ... and that's the problem we have, you only show us a screenshot, but we should know which AutoCAD entity type that are... 😉

 

If we get that answer (better the dwg-file) we might be able to tell you why your code does not work.

Best I can do for now: remove the "On Error Resume Next" line or check after your line "If Err.Number ..." which <Obj> creates an exception (because it does not have a property ".angle"), and I guess your grey items fail here too.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes