Hello,
I am trying to edit an older LISP created in the past where it asks to selct specific block in drawing in order to switch it to a correct layer/color/linetype.
My issue is trying to convert this to slect all block within the drawing. I have played around with ssget _X but it does not seem to yield the desired result.
Solved! Go to Solution.
Solved by ronjonp. Go to Solution.
IMO this is much easier using VLA ... give this a try:
(defun c:foo (/ a d)
;; RJP » 2022-04-13
;; All blocks internals to layer 0, color byblock and linetype byblock
(vlax-for l (vla-get-layers (setq d (vla-get-activedocument (vlax-get-acad-object))))
(cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a))))
)
(vlax-for b (vla-get-blocks d)
(if
(and (= 0 (vlax-get b 'isxref) (vlax-get b 'islayout)) (not (wcmatch (vla-get-name b) "*|*")))
(vlax-for o b
(cond ((vlax-write-enabled-p o)
(vl-catch-all-apply 'vla-put-layer (list o "0"))
(vl-catch-all-apply 'vla-put-linetype (list o "ByBlock"))
(vl-catch-all-apply 'vla-put-color (list o 0))
)
)
)
)
)
(foreach l a (vlax-put l 'lock -1))
(vla-regen d acallviewports)
(princ)
)
Update per sample drawing below.
(defun c:foo2 (/ a d f)
;; RJP » 2022-04-13
(vlax-for l (vla-get-layers (setq d (vla-get-activedocument (vlax-get-acad-object))))
(cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a))))
)
(vlax-for b (vla-get-blocks d)
(setq f (and (= 0 (vlax-get b 'isxref) (vlax-get b 'islayout))))
(vlax-for o b
(cond ((vlax-write-enabled-p o)
;; Only internals of block definitions to layer 0
(and f (vl-catch-all-apply 'vla-put-layer (list o "0")))
;; Everything else
(vl-catch-all-apply 'vla-put-linetype (list o "ByBlock"))
(vl-catch-all-apply 'vla-put-color (list o 0))
)
)
)
)
(foreach l a (vlax-put l 'lock -1))
(vla-regen d acallviewports)
(princ)
)
Thank you for quick reply! Maybe its just my VLA knowledge, however this will not work for blocks inside of viewports no? It only sets my title block (from what I can gather).
Side note: I am putting "learning vla" on my list this is much cleaner!
The code above modifies all the block definitions within the drawing. Post your sample drawing where you say it does not work within viewports.
It seems to work here? Do you want items other than blocks to be on layer 0 and linetype and color to byblock?
Attached are all 437 block definitions within that file and a quick check, the code is doing it's job.
Also, your 'bubble' callouts are MTEXT within a square that is a block?
@patrick.legaultBTQSE wrote:Side note: I am putting "learning vla" on my list this is much cleaner!
Give THIS a look when you start learning 🙂
Ah yes I see it now, must have bugged! Thank you very much ron! I will have a look at the basics documentation as well!
@patrick.legaultBTQSE I posted another version of the code in my original post that does everything in the drawing. You'll need to grab that version (c:foo2 ).
Can't find what you're looking for? Ask the community or share your knowledge.