Jump to content

Script error


MisterJingles

Recommended Posts

Hi everyone

 

I have been using the script below to calculate the length of lines in a dwg for a couple of years without issue.

Today I am getting the following error ...

 

"Cannot invoke (command) from *error* without prior call to (*push-error-using-command*).

Converting (command) calls to (command-s) is recommended."

 

I am no coder so I can't see where the problem might be. Can anyone see where there is an issue?

 

Many thanks

Rob

 

 

Script Error.txt

Script Error.txt

Link to comment
Share on other sites

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • MisterJingles

    9

  • Grrr

    5

  • ReMark

    3

  • SLW210

    3

Top Posters In This Topic

Posted Images

So it turns out other users in our office are running this script without any problem, so there appears to be a different issue.

I'm stumped and running out of time.

Link to comment
Share on other sites

So I did nothing more than just to add (vl-load-com) to your "script", and rename all the "command" into "command-s", tested and working for me:

(defun dxf (n ed) (cdr (assoc n ed)))

(defun bom-code (ssfilter        /       errexit undox   restore
*error* olderr  oldcmdecho      %l      %t
sset    %i      en      ed      p1      p2
ot      a1      a2      r
)
(defun errexit (s)
(princ)
(restore)
)

(defun undox ()
(command-s "._undo" "_E")
(setvar "cmdecho" oldcmdecho)
(setq *error* olderr)
(princ)
)

(setq olderr  *error*
restore undox
*error* errexit
)
(setq oldcmdecho (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command-s "._UNDO" "_BE")
(setq %i 0
%t 0
)
(vl-load-com)
(setq sset (ssget ssfilter))
(if sset
(progn
     (princ "\nLengths:")
     (repeat (sslength sset)
		(setq en (ssname sset %i))
		(setq ed (entget en))
		(setq ot (dxf 0 ed))
		(setq curve (vlax-ename->vla-object en))
		(if (vl-catch-all-error-p
			(setq len	(vl-catch-all-apply
				'vlax-curve-getDistAtParam
				(list	curve
					(vl-catch-all-apply
						'vlax-curve-getEndParam
						(list curve)
					)
				)
			)
			)
		)
		nil
		len
		)
		(setq %l len)
		
		(setq %i (1+ %i)
			%t (+ %l %t)
		)
		(terpri)
		;(princ %l )
		(princ (rtos %l (getvar "lunits")(getvar "luprec")))
	)
     (princ "\nTotal = ")
     ;(princ %t)
     (princ (rtos %t (getvar "lunits")(getvar "luprec")))
     (textpage)
)
)
(setq sset nil)
(restore)
)

(defun bom-code-old (ssfilter        /       errexit undox   restore
*error* olderr  oldcmdecho      %l      %t
sset    %i      en      ed      p1      p2
ot      a1      a2      r
)
(defun errexit (s)
(princ)
(restore)
)

(defun undox ()
(command-s "._undo" "_E")
(setvar "cmdecho" oldcmdecho)
(setq *error* olderr)
(princ)
)

(setq olderr  *error*
restore undox
*error* errexit
)
(setq oldcmdecho (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command-s "._UNDO" "_BE")
(setq %i 0
%t 0
)
(setq sset (ssget ssfilter))
(if sset
(progn
     (princ "\nLengths:")
     (repeat (sslength sset)
		(setq en (ssname sset %i))
		(setq ed (entget en))
		(setq ot (dxf 0 ed))
		(cond
			((= ot "LINE")
				(setq p1 (dxf 10 ed)
					p2 (dxf 11 ed)
					%l (distance p1 p2)
				)
			)
			((= ot "ARC")
				(setq a1 (dxf 50 ed)
					a2 (dxf 51 ed)
					r  (dxf 40 ed)
					%l (* r (abs (- a2 a1)))
				)
			)
			(t
				(command-s "._area" "_obj" en)
				(setq %l (getvar "perimeter"))
				
			)
		)
		(setq %i (1+ %i)
			%t (+ %l %t)
		)
		(terpri)
		(princ %l)
	)
     (princ "\nTotal = ")
     (princ %t)
     (textpage)
)
)
(setq sset nil)
(restore)
)

(defun c:lmeasure ()
(initget "Lines Arcs Polylines Splines ALL")
(setq ans (getkword
	"Enter an option [Lines/Arcs/Polylines/Splines/Kill Dwayne?] : "
)
)
(cond
	((= ans "Lines") (c:bom_lines))
	((= ans "Arcs") (c:bom_arcs))
	((= ans "Polylines") (c:bom_polylines))
	((= ans "Splines") (c:bom_splines))
	(t
		(bom-code '((-4 . "<OR")
			(0 . "LINE")
			(0 . "ARC")
			(0 . "POLYLINE")
			(0 . "LWPOLYLINE")
			(0 . "SPLINE")
			(-4 . "OR>")
		)
		)
	)
)
(princ)
)

(defun c:bom_lines ()
(bom-code '((0 . "LINE")))
(princ)
)

(defun c:bom_arcs ()
(bom-code '((0 . "ARC")))
(princ)
)

(defun c:bom_polylines ()
(bom-code '((-4 . "<OR")
	(0 . "POLYLINE")
	(0 . "LWPOLYLINE")
	(-4 . "OR>")
)
)
(princ)
)

(defun c:bom_splines ()
(bom-code '((0 . "SPLINE")))
(princ)
)
(vl-load-com)

Interesting code, I might overwrite it for a practice.

Link to comment
Share on other sites

Thanks Grrr, something strange appears to be going on. I no longer get the error message but I also don't get the value. See image.

Again it gives my colleagues the desired result so there seems to be something going on with my ACADM install.

 

Capture.JPG

 

At least I know the code is right. I got it off Cadtutor some time ago and it's been invaluable to me.

Link to comment
Share on other sites

Begs the question...what happened to your system that you are the only one who cannot run a script that up until now ran flawlessly? What changed recently?

 

Did you try shutting down then restarting AutoCAD?

 

Did you recently download and use any custom lisp routines?

 

Have you had any unexplained computer problems lately?

Link to comment
Share on other sites

This is what I have racked my brain trying to figure out.

I have shutdown and restarted more than once, I have reset my ACAD settings, Imported a colleagues settings (on whose PC the script works fine) and still no joy.

Definitely not downloaded other custom lisp routines and haven't experienced any other PC issues whatsoever.

 

The only thing that I can think of is we had some Inventor training on Friday, the instructor sat at my PC, plugged in his mouse, also his HD to install some additional content libraries and then went about working on Inventor. I have spoken with him and he cannot think what could possibly have been the cause of my problems today, though it seems too coincidental.

Link to comment
Share on other sites

Mister Jingles, try the following code to determine if its a failure of the visual lisp extensions:

(defun C:test ( / s o len )
(alert "\nSelect a line to display its length. ")
(if (setq s (ssget "_+.:E:S" (list (cons 0 "LINE"))))
	(progn
		(setq o (vlax-ename->vla-object (ssname s 0)))
		(setq len (vlax-curve-getDistAtParam o (vlax-curve-getEndParam o)))
		(alert (strcat "\nLine length is: " (rtos len 2 2) " units."))
	)
)
(princ)
)
(vl-load-com)(princ)

Link to comment
Share on other sites

Grrr - I get the prompt to "Select a line to display its length", when I select the line this is what I get...

 

Capture.JPG

Edited by MisterJingles
Link to comment
Share on other sites

SLW210 - Ok tried that this morning, I created a new Windows account, opened Autocad, ran the lisp and got the same result, there is no value showing where the length would usually be indicated.

 

Not sure if it matters but the MEASURE command works fine.

Link to comment
Share on other sites

Interesting, I ran the 1st Code by Grrr on AutoCAD 2011 and got this....

 

Command: LMEASURE
Enter an option [Lines/Arcs/Polylines/Splines/Kill Dwayne?] : a
; error: An error has occurred inside the *error* functionno function 
definition: COMMAND-S

Link to comment
Share on other sites

Grrr - I get the prompt to "Select a line to display its length", when I select the line this is what I get...

 

[ATTACH=CONFIG]59307[/ATTACH]

 

Obviously your visual lisp extensions aren't loading - even after (vl-load-com)

I know only that visual lisp don't support Mac OS, but I don't know what might cause this problem. Perhaps, re-install AutoCAD?

I'm curious if the following code will work without vlisp, are you after something like this? :

[color=#8b4513]; Some vanilla lisp challenge:[/color]
[b][color=BLACK]([/color][/b]defun C:test
[b][color=FUCHSIA]([/color][/b] [color=#8b4513];| credits to: Lee Mac, Tharwat, Roy |; / [/color]
	Svars *error* SS i e enx eT len itm Lst LinesL PlinesL SplinesL ArcsL
	[color=#8b4513];| [b][color=NAVY]([/color][/b]written by Grrr[b][color=NAVY])[/color][/b] |; [/color]
[b][color=FUCHSIA])[/color][/b]

[b][color=FUCHSIA]([/color][/b]setq Svars
	[b][color=NAVY]([/color][/b]list
		[b][color=MAROON]([/color][/b]list [color=#2f4f4f]"cmdecho"[/color] [b][color=GREEN]([/color][/b]getvar 'cmdecho[b][color=GREEN])[/color][/b] 0[b][color=MAROON])[/color][/b]
		[b][color=MAROON]([/color][/b]list [color=#2f4f4f]"clipromptlines"[/color] [b][color=GREEN]([/color][/b]getvar 'clipromptlines[b][color=GREEN])[/color][/b] 2[b][color=MAROON])[/color][/b]
		[b][color=MAROON]([/color][/b]list [color=#2f4f4f]"nomutt"[/color] [b][color=GREEN]([/color][/b]getvar 'nomutt[b][color=GREEN])[/color][/b] 0[b][color=MAROON])[/color][/b]
		[b][color=MAROON]([/color][/b]list [color=#2f4f4f]"lunits"[/color] [b][color=GREEN]([/color][/b]getvar 'lunits[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]getvar 'lunits[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][color=#8b4513]; you might change this[/color]
		[b][color=MAROON]([/color][/b]list [color=#2f4f4f]"luprec"[/color] [b][color=GREEN]([/color][/b]getvar 'luprec[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]getvar 'luprec[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][color=#8b4513]; you might change this[/color]
	[b][color=NAVY])[/color][/b]
[b][color=FUCHSIA])[/color][/b]
[b][color=FUCHSIA]([/color][/b]if Svars [b][color=NAVY]([/color][/b]mapcar '[b][color=MAROON]([/color][/b]lambda [b][color=GREEN]([/color][/b]x[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setvar [b][color=BLUE]([/color][/b]car x[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]caddr x[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] Svars[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][color=#8b4513]; <- I wanted to check[/color]

[b][color=FUCHSIA]([/color][/b]defun *error* [b][color=NAVY]([/color][/b] msg [b][color=NAVY])[/color][/b]
	[b][color=NAVY]([/color][/b]if Svars [b][color=MAROON]([/color][/b]mapcar 'setvar [b][color=GREEN]([/color][/b]mapcar 'car Svars[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]mapcar 'cadr Svars[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
	[b][color=NAVY]([/color][/b]if 
		[b][color=MAROON]([/color][/b]or
			[b][color=GREEN]([/color][/b]not [b][color=BLUE]([/color][/b]member msg '[b][color=RED]([/color][/b][color=#2f4f4f]"Function cancelled"[/color] [color=#2f4f4f]"quit / exit abort"[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
			[b][color=GREEN]([/color][/b]wcmatch [color=#2f4f4f]"*BREAK,*EXIT*,*CANCEL*"[/color][b][color=GREEN])[/color][/b]
		[b][color=MAROON])[/color][/b]
		[b][color=MAROON]([/color][/b]princ [b][color=GREEN]([/color][/b]strcat [color=#2f4f4f]"\nError occured: \"[/color][color=#2f4f4f]" msg "[/color]\[color=#2f4f4f]""[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
	[b][color=NAVY])[/color][/b]
	[b][color=NAVY]([/color][/b]princ[b][color=NAVY])[/color][/b]
[b][color=FUCHSIA])[/color][/b]

[b][color=FUCHSIA]([/color][/b]prompt [color=#2f4f4f]"\nSelect lines, polylines, splines, arcs to measure their length: "[/color][b][color=FUCHSIA])[/color][/b]
[b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]setq SS [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"_:L"[/color] [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]cons 0 [color=#2f4f4f]"LINE,*POLYLINE,SPLINE,ARC"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][color=#8b4513]; prompt user only for SS and skip [b][color=NAVY]([/color][/b]getkword[b][color=NAVY])[/color][/b].[/color]
	[b][color=NAVY]([/color][/b]progn
		[b][color=MAROON]([/color][/b]defun KGA_2d_ArcLength [b][color=GREEN]([/color][/b]elst[b][color=GREEN])[/color][/b]
			[b][color=GREEN]([/color][/b]defun KGA_Math_LimitAngleRange [b][color=BLUE]([/color][/b]ang[b][color=BLUE])[/color][/b][color=#8b4513]; Change an angle to fit in the range: 0 <= angle < 2pi.[/color]
				[b][color=BLUE]([/color][/b]rem [b][color=RED]([/color][/b]+ [b][color=PURPLE]([/color][/b]rem ang [b][color=TEAL]([/color][/b]+ pi pi[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b] pi pi[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]+ pi pi[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
			[b][color=GREEN])[/color][/b]
			[b][color=GREEN]([/color][/b]* [b][color=BLUE]([/color][/b]KGA_Math_LimitAngleRange [b][color=RED]([/color][/b]- [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 51 elst[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 50 elst[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 40 elst[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
		[b][color=MAROON])[/color][/b]
		[b][color=MAROON]([/color][/b]defun CdrAssoc [b][color=GREEN]([/color][/b] key elist / [b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc key elist[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][color=#8b4513]; unnessecary function - I just wanted to utilize it[/color]
		[b][color=MAROON]([/color][/b]repeat [b][color=GREEN]([/color][/b]setq i [b][color=BLUE]([/color][/b]sslength SS[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
			[b][color=GREEN]([/color][/b]setq
				e [b][color=BLUE]([/color][/b]ssname SS [b][color=RED]([/color][/b]setq i [b][color=PURPLE]([/color][/b]1- i[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
				enx [b][color=BLUE]([/color][/b]entget e[b][color=BLUE])[/color][/b]
				eT [b][color=BLUE]([/color][/b]CdrAssoc 0 enx[b][color=BLUE])[/color][/b]
			[b][color=GREEN])[/color][/b]
			[color=#8b4513]; len [b][color=GREEN]([/color][/b]GetPropertyValue e 'length[b][color=GREEN])[/color][/b];<- this function is added in ACAD 2012 and it supports Mac OS, and doesn't require [b][color=GREEN]([/color][/b]vl-load-com[b][color=GREEN])[/color][/b][/color]
			[b][color=GREEN]([/color][/b]cond [color=#8b4513]; this cond part is taken from the original code[/color]
				[b][color=BLUE]([/color][/b][b][color=RED]([/color][/b]= [color=#2f4f4f]"LINE"[/color] eT[b][color=RED])[/color][/b]
					[b][color=RED]([/color][/b]setq len [b][color=PURPLE]([/color][/b]distance [b][color=TEAL]([/color][/b]CdrAssoc 10 enx[b][color=TEAL])[/color][/b] [b][color=TEAL]([/color][/b]CdrAssoc 11 enx[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
				[b][color=BLUE])[/color][/b]
				[b][color=BLUE]([/color][/b][b][color=RED]([/color][/b]= [color=#2f4f4f]"ARC"[/color] eT[b][color=RED])[/color][/b]
					[b][color=RED]([/color][/b]setq len [b][color=PURPLE]([/color][/b]KGA_2d_ArcLength enx[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
				[b][color=BLUE])[/color][/b]
				[b][color=BLUE]([/color][/b]T
					[b][color=RED]([/color][/b]command-s [color=#2f4f4f]"_.AREA"[/color] [color=#2f4f4f]"_Object"[/color] e[b][color=RED])[/color][/b]
					[b][color=RED]([/color][/b]setq len [b][color=PURPLE]([/color][/b]getvar 'perimeter[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
				[b][color=BLUE])[/color][/b]
			[b][color=GREEN])[/color][/b][color=#8b4513]; cond[/color]
			
			[b][color=GREEN]([/color][/b]setq 
				itm [b][color=BLUE]([/color][/b]list eT len[b][color=BLUE])[/color][/b]
				Lst [b][color=BLUE]([/color][/b]cons itm Lst[b][color=BLUE])[/color][/b]
			[b][color=GREEN])[/color][/b][color=#8b4513]; setq[/color]
		[b][color=MAROON])[/color][/b][color=#8b4513]; repeat[/color]
		[b][color=MAROON]([/color][/b]foreach x Lst
			[b][color=GREEN]([/color][/b]cond
				[b][color=BLUE]([/color][/b][b][color=RED]([/color][/b]= [color=#2f4f4f]"LINE"[/color] [b][color=PURPLE]([/color][/b]car x[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
					[b][color=RED]([/color][/b]setq LinesL [b][color=PURPLE]([/color][/b]cons [b][color=TEAL]([/color][/b]cadr x[b][color=TEAL])[/color][/b] LinesL[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
				[b][color=BLUE])[/color][/b]
				[b][color=BLUE]([/color][/b][b][color=RED]([/color][/b]or [b][color=PURPLE]([/color][/b]= [color=#2f4f4f]"POLYLINE"[/color] [b][color=TEAL]([/color][/b]car x[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=PURPLE]([/color][/b]= [color=#2f4f4f]"LWPOLYLINE"[/color] [b][color=TEAL]([/color][/b]car x[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
					[b][color=RED]([/color][/b]setq PlinesL [b][color=PURPLE]([/color][/b]cons [b][color=TEAL]([/color][/b]cadr x[b][color=TEAL])[/color][/b] PlinesL[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
				[b][color=BLUE])[/color][/b]
				[b][color=BLUE]([/color][/b][b][color=RED]([/color][/b]= [color=#2f4f4f]"SPLINE"[/color] [b][color=PURPLE]([/color][/b]car x[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
					[b][color=RED]([/color][/b]setq SplinesL [b][color=PURPLE]([/color][/b]cons [b][color=TEAL]([/color][/b]cadr x[b][color=TEAL])[/color][/b] SplinesL[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
				[b][color=BLUE])[/color][/b]
				[b][color=BLUE]([/color][/b][b][color=RED]([/color][/b]= [color=#2f4f4f]"ARC"[/color] [b][color=PURPLE]([/color][/b]car x[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
					[b][color=RED]([/color][/b]setq ArcsL [b][color=PURPLE]([/color][/b]cons [b][color=TEAL]([/color][/b]cadr x[b][color=TEAL])[/color][/b] ArcsL[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
				[b][color=BLUE])[/color][/b]
			[b][color=GREEN])[/color][/b][color=#8b4513]; cond [/color]
		[b][color=MAROON])[/color][/b]
		
		[b][color=MAROON]([/color][/b]alert [color=#8b4513]; display the result:[/color]
			[b][color=GREEN]([/color][/b]strcat
				[b][color=BLUE]([/color][/b]if LinesL 
					[b][color=RED]([/color][/b]setq LinesL [b][color=PURPLE]([/color][/b]strcat [color=#2f4f4f]"\nLines total length: "[/color] [b][color=TEAL]([/color][/b]rtos [b][color=OLIVE]([/color][/b]apply '+ LinesL[b][color=OLIVE])[/color][/b] [b][color=OLIVE]([/color][/b]getvar 'lunits[b][color=OLIVE])[/color][/b] [b][color=OLIVE]([/color][/b]getvar 'luprec[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b] [color=#2f4f4f]" units."[/color] [b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
					[b][color=RED]([/color][/b]setq LinesL [color=#2f4f4f]"\nNo Lines selected! "[/color][b][color=RED])[/color][/b]
				[b][color=BLUE])[/color][/b]
				[b][color=BLUE]([/color][/b]if PlinesL 
					[b][color=RED]([/color][/b]setq PlinesL [b][color=PURPLE]([/color][/b]strcat [color=#2f4f4f]"\nPolylines total length: "[/color] [b][color=TEAL]([/color][/b]rtos [b][color=OLIVE]([/color][/b]apply '+ PlinesL[b][color=OLIVE])[/color][/b] [b][color=OLIVE]([/color][/b]getvar 'lunits[b][color=OLIVE])[/color][/b] [b][color=OLIVE]([/color][/b]getvar 'luprec[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b] [color=#2f4f4f]" units."[/color] [b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
					[b][color=RED]([/color][/b]setq PlinesL [color=#2f4f4f]"\nNo Polylines selected! "[/color][b][color=RED])[/color][/b]
				[b][color=BLUE])[/color][/b]
				[b][color=BLUE]([/color][/b]if SplinesL
					[b][color=RED]([/color][/b]setq SplinesL [b][color=PURPLE]([/color][/b]strcat [color=#2f4f4f]"\nSplines total length: "[/color] [b][color=TEAL]([/color][/b]rtos [b][color=OLIVE]([/color][/b]apply '+ SplinesL[b][color=OLIVE])[/color][/b] [b][color=OLIVE]([/color][/b]getvar 'lunits[b][color=OLIVE])[/color][/b] [b][color=OLIVE]([/color][/b]getvar 'luprec[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b] [color=#2f4f4f]" units."[/color] [b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
					[b][color=RED]([/color][/b]setq SplinesL [color=#2f4f4f]"\nNo Splines selected! "[/color][b][color=RED])[/color][/b]
				[b][color=BLUE])[/color][/b]
				[b][color=BLUE]([/color][/b]if ArcsL 
					[b][color=RED]([/color][/b]setq ArcsL [b][color=PURPLE]([/color][/b]strcat [color=#2f4f4f]"\nArcs total length: "[/color] [b][color=TEAL]([/color][/b]rtos [b][color=OLIVE]([/color][/b]apply '+ ArcsL[b][color=OLIVE])[/color][/b] [b][color=OLIVE]([/color][/b]getvar 'lunits[b][color=OLIVE])[/color][/b] [b][color=OLIVE]([/color][/b]getvar 'luprec[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b] [color=#2f4f4f]" units."[/color] [b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
					[b][color=RED]([/color][/b]setq ArcsL [color=#2f4f4f]"\nNo Arcs selected! "[/color][b][color=RED])[/color][/b]
				[b][color=BLUE])[/color][/b]
			[b][color=GREEN])[/color][/b][color=#8b4513]; strcat[/color]
		[b][color=MAROON])[/color][/b][color=#8b4513]; alert[/color]
	[b][color=NAVY])[/color][/b][color=#8b4513]; progn[/color]
[b][color=FUCHSIA])[/color][/b][color=#8b4513]; if SS[/color]
[b][color=FUCHSIA]([/color][/b]if Svars [b][color=NAVY]([/color][/b]mapcar 'setvar [b][color=MAROON]([/color][/b]mapcar 'car Svars[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]mapcar 'cadr Svars[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

[b][color=FUCHSIA]([/color][/b]princ[b][color=FUCHSIA])[/color][/b]
[b][color=BLACK])[/color][/b][color=#8b4513]; defun			[/color]

Edited by Grrr
Link to comment
Share on other sites

@ Grrr:

Just a small remark regarding the calculation of the length of an arc.

The code you use (taken from code the OP has provided) will not give the correct length if the end angle is smaller than the start angle of the arc:

(setq len (* (CdrAssoc 40 enx) (abs (- (CdrAssoc 51 enx) (CdrAssoc 50 enx)))))

Try something like this instead:

; Change an angle to fit in the range: 0 <= angle < 2pi.
(defun KGA_Math_LimitAngleRange (ang)
 (rem (+ (rem ang (+ pi pi)) pi pi) (+ pi pi))
)

(defun KGA_2d_ArcLength (elst)
 (* (KGA_Math_LimitAngleRange (- (cdr (assoc 51 elst)) (cdr (assoc 50 elst)))) (cdr (assoc 40 elst)))
)

Link to comment
Share on other sites

@ Grrr:

Just a small remark regarding the calculation of the length of an arc.

The code you use (taken from code the OP has provided) will not give the correct length if the end angle is smaller than the start angle of the arc:

(setq len (* (CdrAssoc 40 enx) (abs (- (CdrAssoc 51 enx) (CdrAssoc 50 enx)))))

Try something like this instead:

; Change an angle to fit in the range: 0 <= angle < 2pi.
(defun KGA_Math_LimitAngleRange (ang)
 (rem (+ (rem ang (+ pi pi)) pi pi) (+ pi pi))
)

(defun KGA_2d_ArcLength (elst)
 (* (KGA_Math_LimitAngleRange (- (cdr (assoc 51 elst)) (cdr (assoc 50 elst)))) (cdr (assoc 40 elst)))
)

 

Thanks Roy, I've modified the code in my previous post.

Link to comment
Share on other sites

Grrr - Okay that lisp in #16 worked fine :shock:, in fact it's better than the original in that I don't have to select only polylines or only lines at a time.

The real question though is why am I now able to run a lisp? I assume you added code which overcame whichever error I was getting as I still get no value when I run the original.

 

As a matter of interest I ran another basic lisp routine without issue.

Also interestingly, as of yesterday one of my colleagues PC's has decided to stop running the troublesome lisp too.

 

ReMark - Thanks for that, I am unable to modify that acaddoc.lsp file. I saved a copy to my lisp directory and added the recommended line of code but I am not sure how to execute the file. I can't seem to run it via the APPLOAD function.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...