This example shows an alternative method for isolating lines and polylines. The method employs a “Filter” to a select on screen call. The example also shows how to cast each entity to it’s proper type before querying the .Length property.
Note: some object properties are available while still cast only as a general AcadEntity. Some, however, are not. Casting the entity as the more specific type allows full access. And, as an additional note, Autodesk has built in a bit of confusion with the various names given to polylines in the different context.
Code:Sub GetLengths() Dim SOS As AcadSelectionSet Dim objSS As AcadSelectionSet Dim intCode(0) As Integer Dim varData(0) As Variant Dim objEnt As AcadEntity Dim entLine As AcadLine Dim entPoly As AcadPolyline Dim entLWPoly As AcadLWPolyline For Each SOS In ThisDrawing.SelectionSets If SOS.Name = "MySS" Then ThisDrawing.SelectionSets("MySS").Delete Exit For End If Next intCode(0) = 0: varData(0) = "LINE,POLYLINE,LWPOLYLINE" ThisDrawing.SelectionSets.Add ("MySS") Set objSS = ThisDrawing.SelectionSets("MySS") objSS.SelectOnScreen intCode, varData If objSS.Count < 1 Then MsgBox "No lines and polylines selected!" Exit Sub End If For Each objEnt In objSS Select Case objEnt.ObjectName Case "AcDbLine" Set entLine = objEnt MsgBox "Line is " & entLine.Length & " units long." Case "AcDb2dPolyline" Set entPoly = objEnt MsgBox "Polyline is " & entPoly.Length & " units long." Case "AcDbPolyline" Set entLWPoly = objEnt MsgBox "LightWeight Polyline is " & entLWPoly.Length & " units long." End Select Next End Sub




Reply With Quote
Bookmarks