JoeyG_77 Posted April 11, 2019 Share Posted April 11, 2019 Hey everyone ... Im looking for a lisp that would take a block open it and change all the layers & line types to "bylayer" & then change it to a specific layer and close the block after editing it. Thanks Joey G Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted April 11, 2019 Share Posted April 11, 2019 I had this in my library - modified it from ByBlock to ByLayer for your purposes... Untested though... (defun c:BlksByLayer ( / *error* BlkByLayer *adoc* ss i lst ) (vl-load-com) (defun *error* ( m ) (vla-endundomark *adoc*) (if m (prompt m) ) (princ) ) (defun BlkByLayer ( objSelection / blkdef ) (if (= (type objSelection) 'ENAME) (setq objSelection (vlax-ename->vla-object objSelection)) ) (if (wcmatch (strcase (vla-get-objectname objSelection)) "*BLOCK*") (if (and (setq blkdef (vla-item (vla-get-blocks *adoc*) (vla-get-name objSelection))) ;;;(= (vla-get-isdynamicblock blkdef) :vlax-false) ;;; - if you need to process dynamic blocks as well - if you don't remove comments (= (vla-get-isxref blkdef) :vlax-false) (not (vl-position (vla-get-name objSelection) lst)) ) (progn (setq lst (cons (vla-get-name objSelection) lst)) (vlax-for objBlock blkdef (vla-put-color objBlock 256) (vla-put-linetype objBlock "ByLayer") (vla-put-Lineweight objBlock -1) ) ) ) ) ) (setq *adoc* (vla-get-activedocument (vlax-get-acad-object))) (if (= 8 (logand 8 (getvar 'undoctl))) (vla-endundomark *adoc*) ) (vla-startundomark *adoc*) (if (setq ss (ssget "_:L" '((0 . "INSERT")))) (repeat (setq i (sslength ss)) (BlkByLayer (ssname ss (setq i (1- i)))) (entupd (ssname ss i)) ) ) (vla-regen *adoc* acactiveviewport) (*error* nil) ) HTH., M.R. Quote Link to comment Share on other sites More sharing options...
JoeyG_77 Posted April 11, 2019 Author Share Posted April 11, 2019 Marko ... Thanks for the response ! It worked great to change everything to bylayer but I needed it to change it to a specific layer after it changed to bylayer . Thanks for the help Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted April 11, 2019 Share Posted April 11, 2019 Try changing this part : (if (setq ss (ssget "_:L" '((0 . "INSERT")))) (repeat (setq i (sslength ss)) (BlkByLayer (ssname ss (setq i (1- i)))) (entupd (ssname ss i)) ) ) To something like this : (if (setq ss (ssget "_:L" '((0 . "INSERT")))) (repeat (setq i (sslength ss)) (BlkByLayer (ssname ss (setq i (1- i)))) (entupd (cdr (assoc -1 (entmod (subst (cons 8 "LayerName") (assoc 8 (entget (ssname ss i))) (entget (ssname ss i))))))) ) ) Quote Link to comment Share on other sites More sharing options...
Anakozza Posted May 3, 2023 Share Posted May 3, 2023 hi Marko_ribar, I want to do the same trick to change all the nested elements inside a block in layer "0" and color Bylayer , Ltype bylayer etc (all things bylayer). Can You help Me i also have this lisp ; Written By: Peter Jamtgaard 12/20/2006 modified by Anakozza 05/03/2023 ;^P(or C:BBL (load "BBL.lsp"));BBL (defun C:BBL (/ colBlockReference ActDoc dprSelection objSelection strBlockName ) (if (setq dprSelection (entsel "\nSelect Block: ")) (progn (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)) dprSelection (car dprSelection) objSelection (vlax-ename->vla-object dprSelection) ) (vla-StartUndoMark ActDoc) (BlkByLayer objSelection) (entupd dprSelection) (vla-EndUndoMark ActDoc) ) ) (prin1) ) (defun BlkByLayer (objSelection / colBlockReference objBlock strBlockName ) (if (= (type objSelection) 'ENAME) (setq objSelection (vlax-ename->vla-object objSelection))) (if (wcmatch (strcase (vla-get-objectname objSelection)) "*BLOCK*") (progn (vlax-for objBlock (vla-item (vla-get-blocks ActDoc) (vla-get-name objSelection) ) (vla-put-Color objBlock "ByLayer") (vla-put-Layer objBlock "0") (vla-put-linetype objBlock "ByLayer") (vla-put-Lineweight objBlock -1) (vla-put-PlotStyleName objBlock "ByLayer") ) ) ) (prin1) ) (prin1) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.