Results 1 to 5 of 5

Thread: Pass a selection set to a program

  1. #1
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Pass a selection set to a program

    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.

    Code:
     
    (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.

  2. #2
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Lightbulb Re: Pass a selection set to a program

    Quote Originally Posted by ccowgill
    ... I cant figure out how to pass the selection set to the program.
    You can't.

    You will have to do something like this:

    Code:
    (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.
    R.K. McSwain | CAD Panacea |

  3. #3
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Pass a selection set to a program

    Quote Originally Posted by rkmcswain
    You can't.

    You will have to do something like this:

    Code:
     
    (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:

    Code:
      
    (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?

  4. #4
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Exclamation Re: Pass a selection set to a program

    Yes. If the function is expecting an argument, you have to pass it something, but that something could be nil.

    Code:
    (defun subfunction (arg1)
     (if arg1
        (do this if arg1 exists)
        (do this if arg1 = nil)
     )
    )
    
    ;;; calling that function
    (subfunction sset)
    ;; -or-
    (subfunction nil)
    R.K. McSwain | CAD Panacea |

  5. #5
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Pass a selection set to a program

    I got it to work, thanks for your help

Similar Threads

  1. Pass vba selection set to lisp or command line?
    By KevinBarnett in forum VBA/COM Interop
    Replies: 11
    Last Post: 2019-02-15, 04:23 PM
  2. File Selection Program or Database for Non-CAD Use
    By chillme1 in forum Facilities Management In Practice
    Replies: 14
    Last Post: 2013-01-21, 08:40 PM
  3. How do I pass a selection on to LISP?
    By dfuehrer in forum AutoLISP
    Replies: 3
    Last Post: 2007-09-18, 04:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •