Jump to content

Object selection query


Artek

Recommended Posts

Hi guys, Let's say i have a rectangle with small closed polylines inside it. I will then use the bpoly command to create the boundaries inside that rectangle. in plain lisp, how do i select all the new objects created by the bpoly command - the main polyline (rectangle) plus the island/s inside it? I could only think of using "last" but it only returns one object (the enclosing rectangle) and not including the islands. Any thoughts anyone? Thanks!

Link to comment
Share on other sites

Artek, give this a try and let me know if it worked :

 

Note that this won't work if last entity created in DWG before routine executes is block with attributes or old heavy POLYLINE or 3D POLYLINE, as after (setq el (entlast)), (entnext el) will be either Attribute entity or Vertex entity and not desired newly created objects with bpoly command...

 

(defun c:bpsel (/ hpb i ss ent chk s e ch)
 (setq hpb (getvar 'hpbound))
 (setq i -1)
 (setq ss (ssget "_X"))
 (while (setq ent (ssname ss (setq i (1+ i))))
   (if (and
         (not (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (cdr (assoc 8 (entget ent)))))))))
         (= (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
       )
       (setq chk (cons T chk))
       (setq chk (cons nil chk))
   )
 )
 (if (eval (cons 'or chk))
   (progn
     (setq s (ssadd))
     (setq e (entlast))
     (initget 1 "P R")
     (setq ch (getkword "\nCreate [P]olyline(s) or [R]egion(s) for boundary(ies) [P/R] : "))
     (if (eq ch "P") (setvar 'hpbound 1) (setvar 'hpbound 0))
     (prompt "\nPick inside point and ENTER to accept")
     (command "_.bpoly")
     (while (> (getvar 'cmdactive) 0) (command pause))
     (while (setq e (entnext e))
       (ssadd e s)
     )
     (sssetfirst nil s)
   )
   (prompt "\nNo valid LWPOLYLINE set in DWG database for executing routine or layer in witch it resides is locked")
 )
 (setvar 'hpbound hpb)
 (princ)
)

[EDIT] : Try with this, here I've resolved lack stated from above written note...

 

(defun c:bpsel (/ i ss ent chk pt s e ch)
 (setq hpb (getvar 'hpbound))
 (setq i -1)
 (setq ss (ssget "_X"))
 (while (setq ent (ssname ss (setq i (1+ i))))
   (if (and
         (wcmatch (cdr (assoc 0 (entget ent))) "*POLYLINE")
         (< -1 (cdr (assoc 70 (entget ent))) 6)
         (= 1 (logand 1 (cdr (assoc 70 (entget ent)))))
       )
       (setq chk (cons T chk))
       (setq chk (cons nil chk))
   )
 )
 (if (eval (cons 'or chk))
   (progn
     (setq pt (entmakex (list '(0 . "POINT") (cons 10 (getvar 'lastpoint)))))
     (setq s (ssadd))
     (setq e (entlast))
     (initget 1 "P R")
     (setq ch (getkword "\nCreate [P]olyline(s) or [R]egion(s) for boundary(ies) [P/R] : "))
     (if (eq ch "P") (setvar 'hpbound 1) (setvar 'hpbound 0))
     (prompt "\nPick inside point and ENTER to accept")
     (command "_.bpoly")
     (while (> (getvar 'cmdactive) 0) (command pause))
     (while (setq e (entnext e))
       (ssadd e s)
     )
     (sssetfirst nil s)
     (entdel pt)
   )
   (prompt "\nNo valid LWPOLYLINE or old heavy 2D POLYLINE set in DWG database for executing routine")
 )
 (setvar 'hpbound hpb)
 (princ)
)

Edited by marko_ribar
added additional code
Link to comment
Share on other sites

Thank you very much, Marko. Is there a way to save the selection and recall it at a certain point in a command? It's working on 'move' command but not for hatch. For example, after invoking the bpsel command. How can I use that to hatch the same objects created earlier by bpsel without having to reselect them again?

Link to comment
Share on other sites

I forgot to check my second - final bpsel.lsp code... There was mistake in if condition in checking - now OK. - added (wcmatch) as I should but I overlooked it... As for selection sets, you can save them after bpsel in separate variables... bpsel => selected entities => move => (setq s1 (ssget "_P")) - saved selected entities into first variable s1... bpsel => sel. ent. => move => (setq s2 (ssget "_P")) - saved into second variable s2... And so on, on as many selection sets you want to save - I think up to 256 can be hold in memory of CAD...

=> Command: -bhatch => Properties => Solid hatch or some other => Advanced => Associativity => Yes/No - I would put here "No" as I want to remove hatch after it's created if it's undesirable => Select Objects => Select objects: !s1 or !s2 or ... !s256 => ENTER x times to accept -bhatch command and finish...

 

This is how would I do the task you're trying to perform...

 

Hope this helps, M.R.

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...