Results 1 to 8 of 8

Thread: Result of LISP script = selected objects in model space

  1. #1
    Member
    Join Date
    2010-07
    Posts
    2
    Login to Give a bone
    0

    Default Result of LISP script = selected objects in model space

    Can anybody advise me?
    In my LISP script I have a selectionset (created by 'ssadd' function). As a result, I want get objects from the selectionset selected in Autocad model space.

    Is there any way to make it?

    Thanks,
    Michal

  2. #2
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Result of LISP script = selected objects in model space

    Welcome to AUGI... Here is quick one :

    Code:
    (defun c:ss ( / ss s1 )
      (setq ss (ssadd))
      (while (setq s1 (car (entsel "\nPick single object")))
        (vl-catch-all-apply 'ssadd (list s1 ss))
      )
      (sssetfirst nil ss)
    (princ)
    )
    M.R.

    Note : vl-catch-all-apply function catches error of ssadd function if s1 is nil and therefore while loop is ended. sssetfirst function selects and grips objects in model space - possible also in paper space...

  3. #3
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Result of LISP script = selected objects in model space

    Without having a more clear understanding of what it is you're trying to do... I personally would prefer some visual feedback so that I'd know which entities I've already selected:

    Code:
    (defun c:FOO ( / *error*)
    
      (defun *error*  (msg)
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort"))
                ((lambda (i)
                   (while (/= nil (setq e (ssname ss (setq i (1+ i)))))
                     (redraw e 4)))
                  -1))                                                      ; <esc> or (quit)
              ((princ (strcat "\n** Error: " msg " ** "))))                 ; Fatal error, display it
        (princ))
    
      ((lambda (ss / e)
         (while (/= nil (setq e (car (entsel "\nSelect an entity: "))))
           (setq ss (ssadd e ss)) (redraw e 3))
         (sssetfirst nil ss))
        (ssadd))
      (*error* nil))
    ** Note - The error handler simply accounts for highlighted objects, were the user to hit ESC.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  4. #4
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Result of LISP script = selected objects in model space

    What's wrong with the following?

    Code:
    (sssetfirst nil (ssget))

  5. #5
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Result of LISP script = selected objects in model space

    Quote Originally Posted by alanjt View Post
    What's wrong with the following?

    Code:
    (sssetfirst nil (ssget))
    Absolutely nothing IMO - especially given the limited info in OP.

    Hooray simplicity! LoL
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  6. #6
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Result of LISP script = selected objects in model space

    Quote Originally Posted by RenderMan View Post
    Hooray simplicity! LoL
    I code like I live. :P

  7. #7
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Result of LISP script = selected objects in model space

    Returning objects?

    Here are two functions that return object(s) not using ssadd, but allowing for the use of filters. One returns a list of objects that is really easy to use a foreach with and the secont is similar to entsel but allows the use of a filter for a single selection.

    syntax

    (selectobjects nil)
    (selectobjects (list (cons 0 "insert")))

    or

    (selectobject nil)
    (selectobject (list (cons 0 "insert")))

    P-

    Code:
    (defun SelectObjects (lstFilter / intCount lstReturn ssSelections)
     (vl-load-com)
     (if (setq ssSelections (ssget lstFilter))
      (repeat (setq intCount (sslength ssSelections))
       (setq intCount  (1- intCount)
             lstReturn (cons (vlax-ename->vla-object 
                              (ssname ssSelections intCount)) 
                             lstReturn
                       )
       )
      )
     )
     lstReturn
    )
    
    (defun SelectObject (lstFilter / objReturn ssSelections)
     (vl-load-com)
     (if (setq ssSelections (ssget ":S:E" lstFilter))
      (vlax-ename->vla-object 
       (ssname ssSelections 0)  
      )
     )
    )
    AutomateCAD

  8. #8
    Member
    Join Date
    2010-07
    Posts
    2
    Login to Give a bone
    0

    Default Re: Result of LISP script = selected objects in model space

    ´sssetfirst´ have been a function I was looking for.

    Thanks

Similar Threads

  1. Replies: 40
    Last Post: 2022-03-21, 08:19 PM
  2. Replies: 2
    Last Post: 2010-03-23, 07:22 PM
  3. Match Objects from Model Space with Paper Space Objects
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2007-09-18, 01:56 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
  •