jim78b Posted September 14, 2022 Posted September 14, 2022 I have several drawings with many blocks and every time I start setbyblock.lsp it is very slow, isn't there a way to speed up the listing? a thousand thanks (defun c:setbyblock ( / _byblock e n x a sel c) (defun _byblock ( n l / a e x ) (if (and (setq e (tblobjname "BLOCK" n)) (not (member n l))) (while (setq e (entnext e)) (setq x (entget e)) (if (setq a (assoc 420 x)) (setq x (vl-remove (assoc 420 x) x)) ) (if (setq a (assoc 62 x)) (entmod (subst '(62 . 0) a x)) (entmod (append x '((62 . 0)))) ) (if (= "INSERT" (cdr (assoc 0 x))) (_byblock (cdr (assoc 2 x)) (cons n l)) ) ) ) nil ) (prompt "\nSelect Blocks: ") (setq sel (ssget (list (cons 0 "INSERT")))) (setq c 0) (repeat (sslength sel) (setq n (ssname sel c)) (_byblock (cdr (assoc 2 (entget n))) nil) (setq c (1+ c)) ) (command "_.regen") (princ) ) Quote
tombu Posted September 14, 2022 Posted September 14, 2022 (edited) Try this one by Peter Jamtgaard ; 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) (if(=(getvar 'PStyleMode)0)(vla-put-PlotStyleName objBlock "ByBlock")) ) ) ) (prin1) ) (prin1) Edited September 14, 2022 by tombu Quote
jim78b Posted September 14, 2022 Author Posted September 14, 2022 Wow ...is more quick ?even for nested blocks ? Quote
Steven P Posted September 14, 2022 Posted September 14, 2022 7 minutes ago, jim78b said: I need only color =byblock I reckon you can change it, this line here changes the color. (vla-put-Color objBlock 0) Perhaps if you put a ; at the start of the lines that change for example layer and linetype, that might do what you want? You'd have to work out what to do from there though. The ; stops that line being implemented in the LISP 1 Quote
jim78b Posted September 14, 2022 Author Posted September 14, 2022 I don't know lisp ...only nerd color byblock and other bylayer or can remove lines... Quote
tombu Posted September 14, 2022 Posted September 14, 2022 (edited) 1 hour ago, jim78b said: I don't know lisp ...only nerd color byblock and other bylayer or can remove lines... Try ; 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) ; (if(=(getvar 'PStyleMode)0)(vla-put-PlotStyleName objBlock "ByBlock")) ) ) ) (prin1) ) (prin1) Edited September 14, 2022 by tombu removed errant line 1 Quote
Steven P Posted September 14, 2022 Posted September 14, 2022 34 minutes ago, jim78b said: I don't know lisp ...only nerd color byblock and other bylayer or can remove lines... But you can learn and are more likely to get better help if you show that you want to learn rather than asking for a complete solution every time, 1 1 1 Quote
jim78b Posted September 14, 2022 Author Posted September 14, 2022 40 minutes ago, tombu said: Try ; 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) ; (if(vla-get-Lineweight objBlock -1) ; (if(=(getvar 'PStyleMode)0)(vla-put-PlotStyleName objBlock "ByBlock")) ) ) ) (prin1) ) (prin1) this lisp not go well , because don't select all blocks only one at a time Quote
mhupp Posted September 14, 2022 Posted September 14, 2022 (edited) Should stream line the code. ;;----------------------------------------------------------------------;; ;; SET ALL ENTITYS COLOR TO BYBLOCK (defun C:ALL-BlkByBlock (/ colBlockReference ActDoc dprSelection objSelection strBlockName) (setq Drawing (vla-get-ActiveDocument (vlax-get-Acad-Object))) (vla-StartUndoMark Drawing) (if (setq sel (ssget "_X" '((0 . "INSERT") (410 . "Model")))) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (setq obj (vlax-ename->vla-object ent)) (vlax-for objBlock (vla-item (vla-get-blocks Drawing) (vla-get-name obj)) (vla-put-Color objBlock 0) ) ) ) (vla-Regen Drawing acAllViewports) (vla-EndUndoMark Drawing) (princ) ) Edited September 15, 2022 by mhupp updated code 1 Quote
jim78b Posted September 15, 2022 Author Posted September 15, 2022 ok resolve thanks very much!!! 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.