Jump to content

Select within Polyline Lisp - Macintosh


DavidF

Recommended Posts

Morning All,

 

I realise this has been covered in various forms before - but I think the fact I am working on a Mac does change it a bit as it seems I can't support any Visual Lisp files.

 

Basically I am trying to select all the objects (in this case Polylines representing chairs) within a larger polyline. The end game after all these items are selected would be to move them to a different later, change their colour etc.

 

I found this Lisp file which I can load and works perfectly...up the point where i need to end the command - which I am trying to do by pressing enter.

 

http://www.cadforum.cz/cadforum_en/qaID.asp?tip=5697

 

I know pretty much nothing about LISP except how to load it...and that my options in Mac CAD are limited. Anyone got any ideas what I am doing wrong??

 

Cheers,

David

Link to comment
Share on other sites

Hi David,

 

Please try the following code:

(defun c:test ( / cmd lst ply sel )
   (while
       (progn (setvar 'errno 0) (setq ply (car (entsel "\nSelect bounding polyline: ")))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ply) nil)
               (   (not (wcmatch (cdr (assoc 0 (entget ply))) "*POLYLINE"))
                   (princ "\nSelected object is not a polyline.")
               )
               (   (setq lst (polyvertices ply)
                         cmd (getvar 'cmdecho)
                   )
                   (setvar 'cmdecho 0)
                   (command "_.zoom" "_w"
                       "_non" (apply 'mapcar (cons 'min lst))
                       "_non" (apply 'mapcar (cons 'max lst))
                   )
                   (if (setq sel (ssget "_CP" lst '((0 . "*POLYLINE"))))
                       (ssdel ply sel)
                   )
                   (command "_.zoom" "_p")
                   (setvar 'cmdecho cmd)
                   (sssetfirst nil sel)
                   nil
               )
           )
       )
   )
   (princ)
)

(defun polyvertices ( ent / _lwvertices _polyvertices )

   (defun _lwvertices ( enx / itm )
       (if (setq itm (assoc 10 enx))
           (cons (cdr itm) (_lwvertices (cdr (member itm enx))))
       )
   )
   (defun _polyvertices ( ent )
       (if (= "VERTEX" (cdr (assoc 0 (entget ent))))
           (cons (cdr (assoc 10 (entget ent))) (_polyvertices (entnext ent)))
       )
   )
   (if (= "POLYLINE" (cdr (assoc 0 (entget ent))))
       (_polyvertices ent)
       (_lwvertices (entget ent))
   )
)

(princ)

 

The internal selection could be further refined to select polylines on a specific layer, colour, or other property.

 

I hope this helps.

 

Lee

Link to comment
Share on other sites

Hi Lee,

 

Yep - done the trick perfectly! Thank you so much for the help - was wondering when I posted my problem if you would be the one to help :) It can be a little tricky finding LISP routines that don't use Visual. I love my Mac...but it sure can be a pain with CAD word.

 

Cheers,

David

Link to comment
Share on other sites

You're very welcome David, I'm happy to be of assistance.

 

Restricting the ActiveX (COM) component of Visual LISP certainly removes a lot of power from potential LISP programs, and severely limits the number of published programs that you are able to run... I hope the allure of a Mac is worth it! :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...