Spline to Polyline (selectable splines only)

Spline to Polyline (selectable splines only)

gccdaemon
Collaborator Collaborator
1,741 Views
5 Replies
Message 1 of 6

Spline to Polyline (selectable splines only)

gccdaemon
Collaborator
Collaborator

Getting an error and not sure why.

 

(defun C:S2P (/ SP SPL)
	(vl-load-com)
	(setvar "cmdecho" 0)
	(IF	(setq SPL (ssget (list '(0 . "SPLINE"))))
		(progn	(foreach SP SPL (COMMAND "_splinedit" SP "P" "2")))
		(princ "\nNo SPLINES selected: "))
	(setvar "cmdecho" 1)
	(princ)
)
Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
0 Likes
Accepted solutions (1)
1,742 Views
5 Replies
Replies (5)
Message 2 of 6

scot-65
Advisor
Advisor
FOREACH iterates thru a LIST, not a selection set.
Try iterating using WHILE and (ssname SPL [number]).

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

Message 3 of 6

john.uhden
Mentor
Mentor
Accepted solution

You have made SPL a selection set ('PICKSET) not a list.

(foreach ... ) works only with lists.

With selection sets you often have to act on each member separately by getting each one by its numeric position in the set, starting at 0.

(sslength spl) returns the total number of entities in the set.

So, for example...

 

(setq spl# (sslength spl))
(setq i 0)
(while (< i spl#)
  (setq e (ssname spl i))
  ;; do your think to e here
  (setq i (1+ i))
)

Or, most people find it cleaner to work from the last to the first,
as in...
(repeat (setq i (sslength spl))
  (setq e (ssname spl (setq i (1- i)))
  ;; do your thing to e here
)

 

John F. Uhden

Message 4 of 6

gccdaemon
Collaborator
Collaborator

Thanks for the info guys! Here is the final code free to anyone who wants it, I claim nothing on any of my code because it's all collaborative.

 

(defun NIL (C:S2P))
(defun C:SPL2PL (/ I SP SPL)
	(vl-load-com)
	(STARTUNDO (ACADDOC))
	(setvar "cmdecho" 0)
	(IF	(setq SPL (ssget (list '(0 . "SPLINE"))))
		(progn	(repeat	(setq I (sslength spl))
				(setq SP (ssname SPL (setq I (1- I))))
				(COMMAND "_splinedit" SP "P" "2")
	)	)	)
	(setvar "cmdecho" 1)
	(ENDUNDO (ACADDOC))
	(princ)
)

(defun STARTUNDO ( doc )
	(ENDUNDO doc)
	(vla-startundomark doc)
)

(defun ENDUNDO ( doc )
	(while	(= 8 (logand 8 (getvar 'undoctl)))
		(vla-endundomark doc)
)	)

(defun ACADDOC nil
	(vl-load-com)
	(eval (list 'defun 'ACADDOC 'nil (vla-get-activedocument (vlax-get-acad-object))))
	(ACADDOC)
)
Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
Message 5 of 6

Kent1Cooper
Consultant
Consultant

@gccdaemon wrote:

....

(defun NIL (C:S2P))
...
(vl-load-com)
... (IF (setq SPL (ssget (list '(0 . "SPLINE")))) ...

A couple of comments:

 

Where's the (defun NIL ...) thing coming from, and what's it for?  I don't think you can do that -- I actually tried it [substituting a different function definition name that I use], and got a syntax error.

 

I would pull the (vl-load-com) thing outside all the (defun)'s, and have it once, anywhere in the file but not within any of those.  It will run when the file is loaded, so it will be covered, but there's no need to run it again every time the command or the ACADDOC sub-routine is called.

 

I would suggest restricting the selection to Splines not on locked Layers, because if you happen to have any that are on a locked Layer, it will fail on the first one, and not convert any subsequent ones.  Also, if the filter list doesn't include anything that needs to be evaluated [a variable, a calculation, etc.], you can just make it a quoted list, without the (list) function explicitly.

 

  (if (setq SPL (ssget "_:L" '((0 . "SPLINE"))))

Kent Cooper, AIA
Message 6 of 6

gccdaemon
Collaborator
Collaborator

Sorry, I got mixed up between the 4 lsp files I had open.

 

(defun C:S2P NIL (C:SPL2PL))
Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram