add polyline lengths and pop up display inches and feet.lisp

add polyline lengths and pop up display inches and feet.lisp

mkroll9in5in
Enthusiast Enthusiast
847 Views
8 Replies
Message 1 of 9

add polyline lengths and pop up display inches and feet.lisp

mkroll9in5in
Enthusiast
Enthusiast

I have a lisp that will pop up display inches. My current units are set to decimal/unit-less. I would like the pop up display to also auto calculate and display feet next to the unit-less decimal aka inches in the same pop up display. This is the lisp I am currently working with. I'm sure it just needs a line or 2 added but not sure how to do it. LISP is the next thing on my list to learn for AutoCAD now that it is available on LT 2024, yay.

 

(defun C:TOTL ( / CurObj CurSet FltLst TmpLgt TotLgt)
(if (< (atof (getvar "ACADVER")) 15.0)
(alert " VxJoinLines requires AutoCAD 2000(i) or higher. ")
(progn
(vl-load-com)
(setq FltLst '((0 . "3DPOLY,ARC,CIRCLE,ELLIPSE,LINE,LWPOLYLINE,POLYLINE,SPLINE")
(-4 . "<NOT")
(-4 . "<OR")
(-4 . "&=") (70 . 16)
(-4 . "&=") (70 . 64)
(-4 . "OR>")
(-4 . "NOT>")
)
CurSet (cond ((ssget "I" FltLst)) ((ssget FltLst)))
TotLgt 0
)
(if CurSet
(progn
(while (setq CurEnt (ssname CurSet 0))
(setq CurObj (vlax-ename->vla-object CurEnt)
TmpLgt (vlax-curve-getDistAtParam CurObj
(vlax-curve-getEndParam CurObj)
)
TotLgt (+ TotLgt TmpLgt)
CurSet (ssdel CurEnt CurSet)
)
)
(alert (strcat "Total length of selected object(s) " (rtos TotLgt) " square inches."))
)
)
)
)
(princ)
)

0 Likes
Accepted solutions (2)
848 Views
8 Replies
Replies (8)
Message 2 of 9

paullimapa
Mentor
Mentor

Try changing the alert line in the code to this

(alert (strcat "Total length of selected object(s) " (rtos TotLgt) " square inches “and “ (rots (/ TotLgt 144) 2 2) “ square feet.”))


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

(alert

  (strcat

    "Total length of selected object(s) " (rtos TotLgt) " square inches, or"

    (rtos (/ TotLgt 144)) " square feet."

  )

)

Kent Cooper, AIA
0 Likes
Message 4 of 9

ronjonp
Mentor
Mentor

@mkroll9in5in How can you alert SQ Inches from a linear result?

 

If you really want areas AND length use the code below.

 

(defun c:totl (/ curobj curset fltlst tmplgt totlgt totarea)
  (if (< (atof (getvar "ACADVER")) 15.0)
    (alert " VxJoinLines requires AutoCAD 2000(i) or higher. ")
    (progn
      (vl-load-com)
      (setq fltlst  '((0 . "3DPOLY,ARC,CIRCLE,ELLIPSE,LINE,LWPOLYLINE,POLYLINE,SPLINE")
		      (-4 . "<NOT")
		      (-4 . "<OR")
		      (-4 . "&=")
		      (70 . 16)
		      (-4 . "&=")
		      (70 . 64)
		      (-4 . "OR>")
		      (-4 . "NOT>")
		     )
	    curset  (cond ((ssget "I" fltlst))
			  ((ssget fltlst))
		    )
	    totlgt  0
	    totarea 0
      )
      (if curset
	(progn (while (setq curent (ssname curset 0))
		 (setq totarea (+ totarea (vlax-curve-getarea curent)))
		 (setq
		   totlgt (+ totlgt (vlax-curve-getdistatparam curent (vlax-curve-getendparam curent)))
		 )
		 (ssdel curent curset)
	       )
	       (alert (strcat "Total Area ="
			      (vl-princ-to-string totarea)
			      " sq inches ( "
			      (vl-princ-to-string (/ totarea 144))
			      " sq feet )\nTotal Length = "
			      (vl-princ-to-string totlgt)
			      " inches ( "
			      (vl-princ-to-string (/ totlgt 12))
			      " feet )"
		      )
	       )
	)
      )
    )
  )
  (princ)
)

 

 

0 Likes
Message 5 of 9

mkroll9in5in
Enthusiast
Enthusiast
Accepted solution
(alert (strcat "Total length of selected object(s) " (rtos TotLgt) " linear inches, or______" (rtos (/ TotLgt 12)) " linear feet."))

You got me close, but this was what I was looking for, a calculation of all polyline lengths, not area. I wasn't sure how to have the message drop down to the next line so I added a bunch of spaces where you currently see the underscore. Now that AutoCAD LT 2024 has LISP, do you have any suggestions or books I can get to help me learn this. I'm really good at 2D LT AutoCAD over 25 years, I think LISP would put me on a different level.
0 Likes
Message 6 of 9

ronjonp
Mentor
Mentor

@mkroll9in5in THIS will give you length AND area.

0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant

@mkroll9in5in wrote:
.... what I was looking for, a calculation of all polyline lengths, not area. ....

[I was steered in the direction of area by the wording "square inches" near the end of Message 1.]

Kent Cooper, AIA
0 Likes
Message 8 of 9

mkroll9in5in
Enthusiast
Enthusiast
Sorry about that, I was going for linear inches and feet. But like I said, you got me close enough, I made it work. I will learn this lisp. I’m hacking my way through it at the moment.
0 Likes
Message 9 of 9

mkroll9in5in
Enthusiast
Enthusiast

I am trying to use a lisp in conjunction with macros. I'm fairly good at macros, isolating layers, collecting info and undoing what I did to get that info. I will need to collect my (linear feet and inches of edge) separate from my (square foot) because I'm isolating different layers then poly-lining prior to running the lisp that will be build into the macro. Before I would just run the area command, select all my closed looped poly-lines to add up the area. For linear edge I would isolate that layer, poly line everything, select all, run list command, then manually add with a calculator the linear inch of each part. Once the pop up gives me the info that I wish to collect, I hit ok and it un-does everything, putting me back to where I was. I'm good with what I have on this at the moment. Thanks for the help.

0 Likes