LISP to bring blocks to Front with draworder

LISP to bring blocks to Front with draworder

jarredmonday
Collaborator Collaborator
4,164 Views
6 Replies
Message 1 of 7

LISP to bring blocks to Front with draworder

jarredmonday
Collaborator
Collaborator

Hello,

 

I'm looking to bring certain dynamic blocks in my drawing, that are sometime on multiple layers, to the front using draw order.

 

I am currently using the Select Similar do what I need but it's becoming tiresome. My goal is to apply a lisp to a toolbar for a one mouse click. I'm okay at using macros and getting what I need but I cannot find a starting point to select blocks by their names and bringing them to the front.

 

Block name examples:

90-13

CE-13

1161B

...to be continued

 

Thank you for any advice.

 

Please mark Accept as Solution if your question is answered. Kudos gladly accepted. ⇘
0 Likes
Accepted solutions (2)
4,165 Views
6 Replies
Replies (6)
Message 2 of 7

jarredmonday
Collaborator
Collaborator

With a bit more research I was able to find this and it works. May someone modify it so the selected object to be brought to Front?

(defun c:QQ (/ a blkname found lst obj objs ss i blk name)
(vl-load-com)
(if (and (setq blkname '("90-13" "CE-13" "1161B"));;
(foreach x blkname
(if (member x
(while (setq a (tblnext "BLOCK" (null a)))
(setq lst (cons (strcase (cdr (assoc 2 a))) lst))
lst
)
)
(setq found (cons x found))
)
found
)
(setq objs (ssadd)
ss (ssget "_x" '((0 . "INSERT")))
)
)
(progn
(repeat
(setq i (sslength ss))
(setq blk (ssname ss (setq i (1- i))))
(setq obj (vlax-ename->vla-object blk))
(setq name
(if (vlax-property-available-p obj 'effectivename)
(vla-get-effectivename obj)
(vla-get-name obj)
)
)
(if (member (strcase name) blkname)
(ssadd blk objs)
)
)
(if objs
(sssetfirst nil objs)
)
)
(cond ((not blkname)
(princ "\n Missed name of block ***")
)
((not found)
(princ "\n Blocks not found in drawing !!!")
)
(t
(princ "\n couldn't find any block !!! ")
)
)
)
(princ)
)
Please mark Accept as Solution if your question is answered. Kudos gladly accepted. ⇘
0 Likes
Message 3 of 7

hmsilva
Mentor
Mentor
Accepted solution

If the the blocks are not dynamic, something like this will do the trick

 

(defun c:demo (/ ss)
   (if (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 "90-13,CE-13,1161B")))) ; Block names
      (command "_.draworder" ss "" "_front")
   )
   (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 4 of 7

hmsilva
Mentor
Mentor
Accepted solution

@jarredmonday wrote:

With a bit more research I was able to find this and it works. May someone modify it so the selected object to be brought to Front?


II recall that code

Change

(sssetfirst nil objs)

to

 

(command "_.draworder" objs "" "_front")

Hope this helps,
Henrique

 

EESignature

0 Likes
Message 5 of 7

jarredmonday
Collaborator
Collaborator

Thank you very much they both are working very well. I did read on that thread that this will only work for dynamic blocks. Thanks for the reminder. Luckily I only have one or two regular blocks.

Please mark Accept as Solution if your question is answered. Kudos gladly accepted. ⇘
0 Likes
Message 6 of 7

hmsilva
Mentor
Mentor

@jarredmonday wrote:

Thank you very much they both are working very well. I did read on that thread that this will only work for dynamic blocks. Thanks for the reminder. Luckily I only have one or two regular blocks.


You're welcome, jarredmonday!


No, the code will work for dynamic and regular blocks...

Henrique

EESignature

0 Likes
Message 7 of 7

88kedzior88
Explorer
Explorer

(defun c:fr(/ a)
    (setq a (ssget "_I"))
    (sssetfirst a a)
    (command "_.draworder" "_front")
)

 

1) select objects

2) fr

0 Likes