ziele_o2k Posted February 28, 2017 Posted February 28, 2017 Hi, I'm using routine which sets color of all elements in drawing database to ByBlock (abb) or ByLayer (abl) (with my modifications). Can someone modify this so it would work only on selected block. (modify all elements inside selected block including nested blocks). I often use ctrl+shift+c and ctrl+shift+v, and it would be amazing to have routine that will change color of pasted block. ;; AllColorBylayer.lsp [command name: ACB] ;; To change the Color of ALL entities in the drawing, including those nested in ;; Block definitions [but not Xrefs] and Dimension/Leader parts, to ByLayer. ;; Kent Cooper, 27 February 2014, expanding on some elements by p_mcknight ;; modifications by Ziele_o2k ;;source: ;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/a-lisp-to-make-all-entities-color-quot-by-layer-quot/td-p/4840793 (vl-load-com) (defun C:abl ; = All to Color Bylayer (/ cb ent obj blk subent) (defun cb () ; = force Color(s) to Bylayer (setq obj (vlax-ename->vla-object ent)) (vla-put-color obj 256); ByLayer (if (wcmatch (vla-get-ObjectName obj) "*Dimension,*Leader") (foreach prop '(DimensionLineColor ExtensionLineColor TextColor) ;; not all such entity types have all 3 properties, but all have at least one (if (vlax-property-available-p obj prop) (vlax-put obj prop 256); ByLayer ); if ); foreach ); if ); defun -- cb ;; Top-level entities: (setq ent (entnext)) (while ent (cb) (setq ent (entnext ent)) ); while ;; Nested entities in this drawing's Block definitions: (setq blk (tblnext "block" t)) (while blk (if (= (logand 20 (cdr (assoc 70 blk))) 0); not an Xref [4] or Xref-dependent [16] (progn (setq ent (cdr (assoc -2 blk))) (while ent (cb) (setq ent (entnext ent)) ); while ); progn ); if (setq blk (tblnext "block")) ); while (command "_.regenall") (princ) ); defun (vl-load-com) (defun C:abb ; = All to Color Bylayer (/ cb ent obj blk subent) (defun cb () ; = force Color(s) to Bylayer (setq obj (vlax-ename->vla-object ent)) (vla-put-color obj 0); ByBlock (if (wcmatch (vla-get-ObjectName obj) "*Dimension,*Leader") (foreach prop '(DimensionLineColor ExtensionLineColor TextColor) ;; not all such entity types have all 3 properties, but all have at least one (if (vlax-property-available-p obj prop) (vlax-put obj prop 0); ByVlock ); if ); foreach ); if ); defun -- cb ;; Top-level entities: (setq ent (entnext)) (while ent (cb) (setq ent (entnext ent)) ); while ;; Nested entities in this drawing's Block definitions: (setq blk (tblnext "block" t)) (while blk (if (= (logand 20 (cdr (assoc 70 blk))) 0); not an Xref [4] or Xref-dependent [16] (progn (setq ent (cdr (assoc -2 blk))) (while ent (cb) (setq ent (entnext ent)) ); while ); progn ); if (setq blk (tblnext "block")) ); while (command "_.regenall") (princ) ); defun Quote
tombu Posted February 28, 2017 Posted February 28, 2017 Try this one: http://forums.augi.com/showthread.php?151042-Changing-all-entities-to-color-by-layer-within-blocks-as-well&p=1238297&viewfull=1#post1238297 Quote
ziele_o2k Posted February 28, 2017 Author Posted February 28, 2017 Try this one: http://forums.augi.com/showthread.php?151042-Changing-all-entities-to-color-by-layer-within-blocks-as-well&p=1238297&viewfull=1#post1238297 Thank you. I changed lisp from your link, and it works almost good, but I dont know why isn't updating dimensions color to byBlock (after exploding block, dimension color is byBlock...) (defun C:bbb (/ 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) (BlkByBlock objSelection) (entupd dprSelection) (vla-EndUndoMark ActDoc) ) ) (princ) ) (defun BlkByBlock (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 0) (print (vla-get-ObjectName objBlock)) (if (wcmatch (vla-get-ObjectName objBlock) "*Dimension,*Leader") (foreach prop '(DimensionLineColor ExtensionLineColor TextColor) ;; not all such entity types have all 3 properties, but all have at least one (if (vlax-property-available-p objBlock prop) (vlax-put objBlock prop 0); ByVlock ); if ); foreach ); if (if (wcmatch (strcase (vla-get-objectname objBlock)) "*BLOCK*") (BlkByBlock objBlock)) ; set color byblock ; (vla-put-linetype EOBJ "ByBlock") if all you want is color byblock ; (vla-put-Lineweight EOBJ -1) if all you want is color byblock ; (vla-put-PlotStyleName EOBJ "ByBlock") if all you want is color byblock ) ) ) (princ) ) Quote
tombu Posted February 28, 2017 Posted February 28, 2017 Try my latest modified version: ; Written By: Peter Jamtgaard 12/20/2006 ;^P(or C:BlkByBlock (load "BlkByBlock.lsp"));BlkByBlock (defun C:BlkByBlock (/ 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) (BlkByBlock objSelection) (entupd dprSelection) (vla-EndUndoMark ActDoc) ) ) (prin1) ) (defun BlkByBlock (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 0) (vla-put-Layer objBlock "0") (vla-put-linetype objBlock "ByBlock") (vla-put-Lineweight objBlock -1) (vla-put-PlotStyleName objBlock "ByBlock") ) ) ) (prin1) ) It also puts all objects on layer 0 and sets linetype, lineweight, and plot style ByBlock as well. Comment lines 35 through 38 out if you don't want that as well. If you have an AutoCAD vertical like Civil 3D or MEP the SETNESTEDOBJECTSBYBLOCK command is included. Quote
ziele_o2k Posted March 1, 2017 Author Posted March 1, 2017 Thanks tombu, but this is not answer to my problem which is why dimensions color is not changed to byblock. Quote
tombu Posted March 1, 2017 Posted March 1, 2017 Thanks tombu, but this is not answer to my problem which is why dimensions color is not changed to byblock. Edit the dimension style, it probably has the colors, linetypes, and lineweights set in there. You could modify it or create a child dimension style that has everything set to ByBlock, that's how my dimensions are set now. Quote
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.