Find Polyline Length with Autolisp
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
Find Polyline Length with Autolisp

 
Post new topic   Reply to topic    CADForums.net Forum Index -> Customization
Author Message
Bill H
Guest





Posted: Mon Aug 15, 2005 8:10 am    Post subject: Find Polyline Length with Autolisp Reply with quote

I want to be able to find th length of simple 2d polylines made up of lines
and arcs.
I can LIST it and the value shows up, or I can highlight it and the value
shows up in the properties box.
But I can't figure out how to use Autolisp to find this value.
Is it stored or is it calculated each time I list the polyline?

Back to top
Dr Fleau
Guest





Posted: Tue Aug 16, 2005 8:10 am    Post subject: Re: Find Polyline Length with Autolisp Reply with quote

True to internet form and protocol, "Bill H" <billharpo@hotmail.com>
said:

-->I want to be able to find th length of simple 2d polylines made up
of lines
-->and arcs.
-->I can LIST it and the value shows up, or I can highlight it and the
value
-->shows up in the properties box.
-->But I can't figure out how to use Autolisp to find this value.
-->Is it stored or is it calculated each time I list the polyline?
-->

Yo.
Cut'N'Paste this snippet into a new text file, rename the extension to
".lsp" and save it in a directory where ACAD will find it. Load using
"ap" in ACAD (application load) and type "Develop" to use. I created a
button that calls it whenever I need it.

What it does, it lets you select all the lines and arcs you want to
measure, and indicates the total length in a message window. It's
kinda hard to miss.
If you want to ditch the message box in favor of a standard
CommandLine text, change the "alert" below for "princ", and add an
extra "(princ)" after the OSMODE change code.

Note: will not work on ellipses, plines or anything other than lines
or arcs.

Free of charge, sold as seen.

Dr Fleau


(defun c:develop (/ iter devel $a total data1
stpt endpt distl strad endrad distr
)
(setvar "osmode" 0)
(setq $a nil
iter 0
devel 0.0
stpt nil
endpt nil
strad 0.0
endrad 0.0
rad 0.0
distl 0.0
distr 0.0
total 0.0
devel 0.0
)
(setq $a (ssget))
(setq total (sslength $a))
(while (< 0 total)
(progn
(setq data1 (cdr (entget (ssname $a iter))))
(cond
((= (cdr (assoc 0 data1)) "LINE")
(Progn
(setq
stpt
(cdr (assoc 10 data1))
endpt
(cdr (assoc 11 data1))
)
(setq distl (abs (distance stpt endpt)))
(setq devel (+ devel distl))
) ;_END PROGN
) ;_END COND1
((= (cdr (assoc 0 data1)) "ARC")
(Progn
(setq
strad
(cdr (assoc 50 data1))
endrad
(cdr (assoc 51 data1))
rad
(cdr (assoc 40 data1))
)
(cond
((> endrad strad)
(setq distr (* rad (- endrad strad)))
)
((setq distr (* rad (+ endrad (- (* 2 pi) strad))))
)
(t nil)
) ;_end COND
(setq devel (+ devel distr))
) ;_END PROGN
) ;_END COND2
(T nil)
) ;_END COND
(setq iter (+ 1 iter))
(setq total (- total 1))
) ;_END PROGN
) ;_END WHILE
(alert (strcat "Total length : " (rtos devel) " units "))
(setq $a nil)
(setvar "osmode" 0)
) ;_end DEFUN DEVELOP
Back to top
William Ogle
Guest





Posted: Fri Aug 19, 2005 4:10 pm    Post subject: Re: Find Polyline Length with Autolisp Reply with quote

The value is stored in the system variable "PERIMETER", so after using list,
you can access it using (getvar "perimeter"). It has the disadvantage of
needing to use the command line, but it does accurately figure arcs, etc.

Does anyone know how to set the perimeter variable without using the command
prompt?

"Bill H" <billharpo@hotmail.com> wrote in message
news:tYVLe.1162$r54.471@newssvr19.news.prodigy.com...
Quote:
I want to be able to find th length of simple 2d polylines made up of lines
and arcs.
I can LIST it and the value shows up, or I can highlight it and the value
shows up in the properties box.
But I can't figure out how to use Autolisp to find this value.
Is it stored or is it calculated each time I list the polyline?



Back to top
Bill H
Guest





Posted: Wed Aug 24, 2005 8:10 am    Post subject: Re: Find Polyline Length with Autolisp Reply with quote

Thanks.
I did not know that.
It is nice to know.
If nothing else, I can pick the pline, then pick the text, and have Autolisp
LIST the line and update the text with the perimeter value.
That gets me better than half way to whgere I am trying to go.


"William Ogle" <willogle@bellsouth.net> wrote in message
news:pSlNe.26770$XM3.7788@bignews5.bellsouth.net...
Quote:
The value is stored in the system variable "PERIMETER", so after using
list, you can access it using (getvar "perimeter"). It has the
disadvantage of needing to use the command line, but it does accurately
figure arcs, etc.

Does anyone know how to set the perimeter variable without using the
command prompt?

"Bill H" <billharpo@hotmail.com> wrote in message
news:tYVLe.1162$r54.471@newssvr19.news.prodigy.com...
I want to be able to find th length of simple 2d polylines made up of
lines and arcs.
I can LIST it and the value shows up, or I can highlight it and the value
shows up in the properties box.
But I can't figure out how to use Autolisp to find this value.
Is it stored or is it calculated each time I list the polyline?




Back to top
Bill H
Guest





Posted: Wed Aug 24, 2005 8:10 am    Post subject: Re: Find Polyline Length with Autolisp Reply with quote

I guess I should have mentioned that I want the text to update when I
stretch the polyline.
Kinda makes it a hores of a different color.
It's a simple polyline with 2 straight segments and a fixed-radius fillet in
the center.
I will probably need to write something that calculates and totals the
segment lengths.
Then I will need to create some type of object or application to make it
happen.

Thanks for the routine..I'm sure it will save me lots of time figuring the
fillet length, and it is appreciated.

Bill


"Dr Fleau" <dr_fleau-obvious-@lycos-obvious.com> wrote in message
news:qkn2g1pcpalrtj22e7kbo682voj0ptdu55@4ax.com...
Quote:
True to internet form and protocol, "Bill H" <billharpo@hotmail.com
said:

-->I want to be able to find th length of simple 2d polylines made up
of lines
-->and arcs.
-->I can LIST it and the value shows up, or I can highlight it and the
value
-->shows up in the properties box.
-->But I can't figure out how to use Autolisp to find this value.
-->Is it stored or is it calculated each time I list the polyline?
--

Yo.
Cut'N'Paste this snippet into a new text file, rename the extension to
".lsp" and save it in a directory where ACAD will find it. Load using
"ap" in ACAD (application load) and type "Develop" to use. I created a
button that calls it whenever I need it.

What it does, it lets you select all the lines and arcs you want to
measure, and indicates the total length in a message window. It's
kinda hard to miss.
If you want to ditch the message box in favor of a standard
CommandLine text, change the "alert" below for "princ", and add an
extra "(princ)" after the OSMODE change code.

Note: will not work on ellipses, plines or anything other than lines
or arcs.

Free of charge, sold as seen.

Dr Fleau


(defun c:develop (/ iter devel $a total data1
stpt endpt distl strad endrad distr
)
(setvar "osmode" 0)
(setq $a nil
iter 0
devel 0.0
stpt nil
endpt nil
strad 0.0
endrad 0.0
rad 0.0
distl 0.0
distr 0.0
total 0.0
devel 0.0
)
(setq $a (ssget))
(setq total (sslength $a))
(while (< 0 total)
(progn
(setq data1 (cdr (entget (ssname $a iter))))
(cond
((= (cdr (assoc 0 data1)) "LINE")
(Progn
(setq
stpt
(cdr (assoc 10 data1))
endpt
(cdr (assoc 11 data1))
)
(setq distl (abs (distance stpt endpt)))
(setq devel (+ devel distl))
) ;_END PROGN
) ;_END COND1
((= (cdr (assoc 0 data1)) "ARC")
(Progn
(setq
strad
(cdr (assoc 50 data1))
endrad
(cdr (assoc 51 data1))
rad
(cdr (assoc 40 data1))
)
(cond
((> endrad strad)
(setq distr (* rad (- endrad strad)))
)
((setq distr (* rad (+ endrad (- (* 2 pi) strad))))
)
(t nil)
) ;_end COND
(setq devel (+ devel distr))
) ;_END PROGN
) ;_END COND2
(T nil)
) ;_END COND
(setq iter (+ 1 iter))
(setq total (- total 1))
) ;_END PROGN
) ;_END WHILE
(alert (strcat "Total length : " (rtos devel) " units "))
(setq $a nil)
(setvar "osmode" 0)
) ;_end DEFUN DEVELOP
Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> Customization All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Powered by phpBB