priyanka_mehta Posted December 12, 2008 Share Posted December 12, 2008 Hi all, I need a VBA code for finding the length of a selected line/polyline.. i have the code for selectonscreen and for length again object.length can be used but somehow i m not being able to integrated these two to get the length of my selected line. Please Help! Regards, Priyanka Quote Link to comment Share on other sites More sharing options...
SEANT Posted December 12, 2008 Share Posted December 12, 2008 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. 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 Quote Link to comment Share on other sites More sharing options...
priyanka_mehta Posted December 18, 2008 Author Share Posted December 18, 2008 (edited) Hey Thanks, This was exactly what I wanted.. I was using the following code: '******************* Dim line As AcadLine Dim block As AcadBlockReference Dim a As String On Error Resume Next ThisDrawing.SelectionSets("TempSSet").Delete Set objSelectionSet = ThisDrawing.SelectionSets.Add("TempSSet") 'ask user to pick entities on the screen objSelectionSet.SelectOnScreen 'change the highlight status of each entity selected For Each line In objSelectionSet MsgBox line.length Next objSelectionSet.Delete '*********** But i really required such filters.Thanks a lot Regards, Priyanka Edited September 21, 2012 by SLW210 Code Tags!! Quote Link to comment Share on other sites More sharing options...
fati sohrabi Posted September 21, 2012 Share Posted September 21, 2012 hi every body id appreciate it if some body guide me how i can have the length of polylines from start to the point of intersection with another polyline?? thank you all Quote Link to comment Share on other sites More sharing options...
MSasu Posted September 21, 2012 Share Posted September 21, 2012 Welcome to the Forum, fati sohrabi! Please tell me, are you a programmer? I mean, are you looking for an approach to calculate that value using a VBA code you have in progress? Or you just want a solution to list the said length on prompter? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 21, 2012 Share Posted September 21, 2012 Perhaps this program will help you reach your goal: http://lee-mac.com/intersectionslength.html Quote Link to comment Share on other sites More sharing options...
fati sohrabi Posted September 21, 2012 Share Posted September 21, 2012 (edited) wow wonderful lee Mac, i have two more questions, 1. how i can transfer this information(length of poly lines) to excel software? is it possible? 2. if it is possible, how i can find (distinguish) that which length is belong to which poly lines? i'd really appreciate it. Edited September 21, 2012 by fati sohrabi Quote Link to comment Share on other sites More sharing options...
fati sohrabi Posted September 22, 2012 Share Posted September 22, 2012 i am a designer of pressurized irrigation system, in our project its a lots of pipe line with two diameter that have intersect with together, so for calculate the pipe line in (27000ha): 1. i have to recognize the intersection point 2. and then calculate the length of line the lisp that lee mac introduce me is good but not enough for me because: first: how i can transfer this information to excel second: lisp is not so trustworthy look like vba code thank u if u can help me more Quote Link to comment Share on other sites More sharing options...
suns_444 Posted September 7, 2013 Share Posted September 7, 2013 hi there i am new programmer here for vba in autocad hence wanted some help for issues below: code to find the length of a given arc and code to find the area of part of circle divided by chord thanx in advance :) Regards Sunny Dedhia Quote Link to comment Share on other sites More sharing options...
abraxus Posted September 21, 2013 Share Posted September 21, 2013 look up the .IntersectWith method it will return a point array with the intersection points for any two entities which you can use in your calculation code length of an arc is simple PI math which you should be able to google - it's basic geometry Quote Link to comment Share on other sites More sharing options...
abraxus Posted September 21, 2013 Share Posted September 21, 2013 dArcLength = n(degrees)/360(degrees) * 2 * PI * radius of arc autocad stores angular values as radians tho, so you have to make sure your convert your radians to degrees or vice versa first - again, it's just basic math Quote Link to comment Share on other sites More sharing options...
abraxus Posted September 21, 2013 Share Posted September 21, 2013 this will help you visualize it http://math.about.com/od/formulas/ss/surfaceareavol_9.htm so create a function that calculates the length of the arc when you need it Function dArcLength(byval radius as double, byval nDegrees as integer) as double ' put the calculations here 'return value dArcLength = whatever you calculated ) Quote Link to comment Share on other sites More sharing options...
ceyar Posted September 15, 2014 Share Posted September 15, 2014 hi all its been a long time this thread strated but i would like to try my luck. whenever i try "SEANT's" code i always counter with the errror runtime error 424 on the line "For Each SOS In ThisDrawing.SelectionSets" i am using excel 2010 and as you can see autocad 2007. does anyone know the reason. thanks in advance. Quote Link to comment Share on other sites More sharing options...
SEANT Posted September 15, 2014 Share Posted September 15, 2014 (edited) Where are you running the code, Excel or AutoCAD's VBAIDE? The "ThisDrawing" object requires it be run in AutoCAD. Edited September 15, 2014 by SEANT Added Info Quote Link to comment Share on other sites More sharing options...
ceyar Posted September 15, 2014 Share Posted September 15, 2014 Thanks god you heard me Seant i am trying to run this code on Excel. Because i am trying to measure the lengths of dwg's inside many different folders. First take their names with Excel vba than send them to Autocad and finally get their lenghts inside the Excel file. Quote Link to comment Share on other sites More sharing options...
SEANT Posted September 15, 2014 Share Posted September 15, 2014 All of that sounds possible, and can be run from either environment - provided the proper references are set. That is not to say, though, that there is not complexity. The VBAIDEs of both AutoCAD and Excel offer shortcuts whilst dealing with their respective object models. A development effort combining the two environments will require more specific referencing. Ultimately, ObjectDBX will be beneficial. It is an interface for manipulating AutoCAD drawings without having to open each one in the drawing editor. Web search discussion linking ObjectDBX and Excel - I'm sure there is plenty to explore. Quote Link to comment Share on other sites More sharing options...
akash117 Posted May 11, 2015 Share Posted May 11, 2015 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. 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 can i get the same code in vb.net... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.