View Full Version : Run command on every object in selection
Mr Cory
2008-02-26, 10:13 PM
Hi Everyone
A couple quick (I Hope) questions
1. I have a lisp routine that works on one object at a time. But i am calling it as part of another lisp (Using... (c:otherlisp) )in which i need it to work on multiple objects. Is there anyway to run a command on each object is a selection set?
2. I have another lisp (original here (http://forums.augi.com/showthread.php?t=56709)) the triggers a different command depending on the selected object, is there anyway to adapt it so that if the selection set is nil, no objects selected, it will trigger a different command? (see below lisp)
(defun c:AS (/ ObjectType SelectObject)
(setq SelectObject (ssget "I"))
(if (not SelectObject)
(setq SelectObject (ssget ":S"))
)
(setq ObjectType (cdr (assoc 0 (entget (ssname SelectObject 0)))))
(cond ((= "AEC_DOOR" ObjectType)
(command "dooraddselected")
)
((= "AEC_WINDOW" ObjectType)
(command "WindowAddSelected")
)
((= "LWPOLYLINE" ObjectType)
(command "pline" (while (= (getvar "CMDACTIVE") 1 ) (command pause) ) "matchprop" selectobject "l" "")
)
((= "LINE" ObjectType)
(command "pline" (while (= (getvar "CMDACTIVE") 1 ) (command pause) ) "matchprop" selectobject "l" "")
)
)
(princ))
CAB2k
2008-02-26, 10:40 PM
Hi Everyone
A couple quick (I Hope) questions
1. I have a lisp routine that works on one object at a time. But i am calling it as part of another lisp (Using... (c:otherlisp) )in which i need it to work on multiple objects. Is there anyway to run a command on each object is a selection set?
(setq i -1)
(while (setq ename (ssname ss (setq i (1+ i))))
(command "SomeCommand" ename "" )
)
2. I have another lisp (original here (http://forums.augi.com/showthread.php?t=56709)) the triggers a different command depending on the selected object, is there anyway to adapt it so that if the selection set is nil, no objects selected, it will trigger a different command? (see below lisp)
(defun c:AS (/ ObjectType SelectObject)
(setq SelectObject (ssget "I"))
(if (not SelectObject)
(setq SelectObject (ssget ":S"))
)
(setq ObjectType (cdr (assoc 0 (entget (ssname SelectObject 0)))))
(cond
((null SelectObject)
(command "SomeOtherCommand")
)
((= "AEC_DOOR" ObjectType)
(command "dooraddselected")
)
((= "AEC_WINDOW" ObjectType)
(command "WindowAddSelected")
)
((= "LWPOLYLINE" ObjectType)
(command "pline"
(while (= (getvar "CMDACTIVE") 1) (command pause))
"matchprop"
selectobject
"l"
""
)
)
((= "LINE" ObjectType)
(command "pline"
(while (= (getvar "CMDACTIVE") 1) (command pause))
"matchprop"
selectobject
"l"
""
)
)
)
(princ)
)
See comments above in red.
Mr Cory
2008-02-26, 11:06 PM
Thanks for the reply Alan but i get the same error with both routines
bad argument type: lselsetp nil
Here is what i am trying for the first question
(defun c:thego ()
(vl-Load-Com)
(setq vbobj (vlax-ename->vla-object (entlast)))
(changestylename vbobj "Ext paving style 1"))
(defun changeStylename (myobj newstylename)
(if (vlax-property-available-p myobj "stylename" t)
(progn ;you can set the stylename on this object
(print (vlax-get-property myobj "stylename"))
(vlax-put-property myobj "stylename" newstylename))
(progn ;your Can Not set the stylename on this object)))
(princ))))
(defun c:go ()
(setq ss1 (ssget))
(setq i -1)
(while (setq ename (ssname ss (setq i (1+ i))))
(command "pselect" ss1 "")
(c:thego)
)
(princ))
have i used your code in the wrong order or...?
And the second one im just not sure why that didnt work, i just got that error :?
I appreciate your help :)
CAB2k
2008-02-26, 11:18 PM
(defun thego (ent)
(vl-load-com)
(changestylename (vlax-ename->vla-object ent) "Ext paving style 1")
)
(defun changeStylename (myobj newstylename)
(if (vlax-property-available-p myobj "stylename" t)
(progn ;you can set the stylename on this object
(print (vlax-get-property myobj "stylename"))
(vlax-put-property myobj "stylename" newstylename)
)
(progn ;your Can Not set the stylename on this object)))
(princ)
)
)
)
(defun c:go ()
(setq ss (ssget))
(setq i -1)
(while (setq ename (ssname ss (setq i (1+ i))))
(thego ename)
)
(princ)
)
Mr Cory
2008-02-26, 11:27 PM
Hmm i must still be doing something wrong as im still getting the error. I removed the pselect command as its not the one i want to run.
(defun c:go ()
(setq i -1)
(while (setq ename (ssname ss (setq i (1+ i))))
(c:thego) ; (see previous post for command)
)
(princ))
I select the object then use this command but get the same error :? Am i missing something?
CAB2k
2008-02-27, 12:49 AM
Look at this:
(defun changeStylename (myobj newstylename)
(if (vlax-property-available-p myobj "stylename" t)
(progn ;you can set the stylename on this object
(print (vlax-get-property myobj "stylename"))
(vlax-put-property myobj "stylename" newstylename)
)
(progn ;your Can Not set the stylename on this object)))
(princ)
)
)
)
(defun c:go ()
(vl-load-com)
(setq ss (ssget))
(setq i -1)
(while (setq ename (ssname ss (setq i (1+ i))))
(changestylename (vlax-ename->vla-object ename) "Ext paving style 1")
)
(princ)
)
Mr Cory
2008-02-27, 01:32 AM
Im still getting the same ol error. Im guessing that has to do with the orginial code?
CAB2k
2008-02-27, 02:02 AM
Copy the code again.
There was a misspelled var name.
(setq ss1 (ssget))
should have been
(setq ss (ssget))
Mr Cory
2008-02-27, 02:20 AM
Brillant, that fixed!!
Thank you so much for your help! You have just simplified alot of my lisps haha thanks again! :mrgreen:
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.