PDA

View Full Version : Pass a selection set to a program



ccowgill
2007-05-18, 11:46 AM
I am trying to partially automate one of my programs, but I cant figure out how to pass the selection set to the program. when standard AutoCAD commands are called, you can just enter ss in the command but I cant seem to figure it out. This is my code, I havent defined all the local variables yet because I am still in testing phase.



(defun c:aremove (/ ss counter ent entdata)
(setq ss (ssget "_X"
(list '(-4 . "<and")
'(0 . "TEXT")
'(8 . "Offset Notes")
'(62 . 256)
(cons 410 (getvar "ctab"))
'(-4 . "and>")
)
) ;_ end of ssget
counter 0
ss2 (ssadd)
ss3 (ssadd)
) ;_ end of setq
(while (setq ent (ssname ss counter))
(setq entdata (entget ent)
obj (cdr (assoc 1 entdata)))
(cond
((wcmatch (cdr (assoc 1 entdata)) "*#\" @*")
(setq text1 (vl-string-left-trim "1234567890`+\" " obj)
text2 (vl-string-left-trim "ABCDEFGHIJKLMNOPQRSTUVWXYZ " text1)
text3 (vl-string-right-trim "`'" text2)
text4 (atof text3)
) ;_ end of setq
(if (<= text4 26.0)
(setq ss2 (ssadd ent ss2))
) ;_ end of if
)
((wcmatch (cdr (assoc 1 entdata))
"*POWER POLE*,*TELE RISER BOX*,*GUY WIRE*"
) ;_ end of wcmatch
(setq text1 (vl-string-left-trim "1234567890+\" " obj)
text2 (vl-string-left-trim "ABCDEFGHIJKLMNOPQRSTUVWXYZ " text1)
text3 (vl-string-right-trim "`'" text2)
text4 (atof text3)
) ;_ end of setq
(if (<= text4 26.0)
(setq ss3 (ssadd ent ss3))
) ;_ end of if
)
) ;_ end of cond
(setq counter (1+ counter))
) ;_ end of while
(C:REM);use selection set ss2
(C:RBO);use selection set ss3
; (setq ss2 nil)
; (setq ss3 nil)
(gc)
) ;_ end of defun


I can post the lisp that contains C:REM and C:RBO if necessary, but I think that the question is general enough that it wont be required.

rkmcswain
2007-05-18, 12:25 PM
... I cant figure out how to pass the selection set to the program.

You can't.

You will have to do something like this:




(defun subfunction (ss)
(blah blah blah)
(this is where your main code would go)
(to handle the argument)
)

(defun C:aremove ( / ss)
(setq ss (ssget))
(subfunction ss)
)



If you need a variable number of arguments, then generate a list of these arguments and pass the single list to your subfunction and let it deal with parsing out the variables.

ccowgill
2007-05-18, 01:00 PM
You can't.

You will have to do something like this:




(defun subfunction (ss)
(blah blah blah)
(this is where your main code would go)
(to handle the argument)
)

(defun C:aremove ( / ss)
(setq ss (ssget))
(subfunction ss)
)



If you need a variable number of arguments, then generate a list of these arguments and pass the single list to your subfunction and let it deal with parsing out the variables.
so what you are saying is I need to define my subfunctions with no c: and add a line in it like this:



(defun subfunction (ss)
(blah blah blah)
(if (= ss nil)
(do this if T)
(pass ss if F)
)
(this is where your main code would go)
(to handle the argument)
)


or will it give me errors if the function does not receive the argument?

rkmcswain
2007-05-18, 01:24 PM
Yes. If the function is expecting an argument, you have to pass it something, but that something could be nil.



(defun subfunction (arg1)
(if arg1
(do this if arg1 exists)
(do this if arg1 = nil)
)
)

;;; calling that function
(subfunction sset)
;; -or-
(subfunction nil)

ccowgill
2007-05-18, 01:43 PM
I got it to work, thanks for your help