woodman78 Posted May 18, 2015 Posted May 18, 2015 I am looking to split a dynamic block with visibility states into a series of blocks with a block for each visibility state. Can anyone help with this? Quote
samifox Posted May 18, 2015 Posted May 18, 2015 you can use Lee's lisp to rename viability state as a new block quickly, some clean up should be done later on Quote
pBe Posted May 18, 2015 Posted May 18, 2015 Its quite easy. This would be fun to code Grab all Visibility names via GetDynamicBlockProperties Create one block for each via ConvertToStaticBlock Did i not say its easy and fun to code? Quote
BlackBox Posted May 18, 2015 Posted May 18, 2015 ... Did i not say its easy and fun to code? No, I don't think you did. Quote
samifox Posted May 18, 2015 Posted May 18, 2015 No, I don't think you did. im afraid we didnt got the joke:cry: Quote
woodman78 Posted May 19, 2015 Author Posted May 19, 2015 Thanks guys I already use Lee's RB command but does anyone have a way to make a block static on a certain visibility state? Quote
Dadgad Posted May 19, 2015 Posted May 19, 2015 Thanks guys I already use Lee's RB command but does anyone have a way to make a block static on a certain visibility state? Have you tried the CB option in Lee's lisp, from the description, it sounds like it may be able to do it? Quote
woodman78 Posted May 19, 2015 Author Posted May 19, 2015 Thanks for your help guys that Lee's lisp doesn't make the static block. Any other ideas? Quote
woodman78 Posted May 19, 2015 Author Posted May 19, 2015 Thanks guys. I found this link from a LeeMac reply: http://www.theswamp.org/index.php?topic=32681.msg382548#msg382548 Quote
Lee Mac Posted May 19, 2015 Posted May 19, 2015 Many thanks for all the recommendations guys It was indeed quite fun to code - here's a quick draft: ;; Split Dynamic Block by Visibility State - Lee Mac (defun c:dynsplit ( / *error* blk dis llp obj prp tmp urp ) (defun *error* ( msg ) (LM:endundo (LM:acdoc)) (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")) (princ (strcat "\nError: " msg)) ) (princ) ) (while (progn (setvar 'errno 0) (setq obj (car (entsel "\nSelect dynamic block to split: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (null obj) nil) ( (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 (entget obj)))))))) (princ "\nSelected object is on a locked layer.") ) ( (/= "AcDbBlockReference" (vla-get-objectname (setq obj (vlax-ename->vla-object obj)))) (princ "\nSelected object is not a block.") ) ( (= :vlax-false (vla-get-isdynamicblock obj)) (princ "\nSelected block is not dynamic.") ) ( (null (setq prp (LM:getvisibilityparametername obj))) (princ "\nSelected dynamic block does not have a visibility parameter.") ) ) ) ) (if obj (progn (LM:startundo (LM:acdoc)) (setq blk (vla-get-effectivename obj) dis 0.0 prp (vl-some '(lambda ( x ) (if (= (strcase prp) (strcase (vla-get-propertyname x))) x) ) (vlax-invoke obj 'getdynamicblockproperties) ) ) (foreach x (vlax-get prp 'allowedvalues) (vla-put-value prp (vlax-make-variant x vlax-vbstring)) (vla-move (setq tmp (vla-copy obj)) (vlax-3D-point 0 0) (vlax-3D-point dis 0) ) (vla-converttostaticblock tmp (uniqueblockname (strcat blk "_" x))) (vla-getboundingbox tmp 'llp 'urp) (setq dis (+ dis (* 1.1 (apply '- (mapcar '(lambda ( x ) (car (vlax-safearray->list x))) (list urp llp)))))) ) (vla-delete obj) (LM:endundo (LM:acdoc)) ) ) (princ) ) (defun uniqueblockname ( key / cnt rtn ) (if (tblsearch "block" key) (progn (setq cnt 1) (while (tblsearch "block" (setq rtn (strcat key "(" (itoa (setq cnt (1+ cnt))) ")")) ) ) rtn ) key ) ) ;; Get Visibility Parameter Name - Lee Mac ;; Returns the name of the Visibility Parameter of a Dynamic Block (if present) ;; blk - [vla] VLA Dynamic Block Reference object ;; Returns: [str] Name of Visibility Parameter, else nil (defun LM:getvisibilityparametername ( blk / vis ) (if (and (vlax-property-available-p blk 'effectivename) (setq blk (vla-item (vla-get-blocks (vla-get-document blk)) (vla-get-effectivename blk) ) ) (= :vlax-true (vla-get-isdynamicblock blk)) (= :vlax-true (vla-get-hasextensiondictionary blk)) (setq vis (vl-some '(lambda ( pair ) (if (and (= 360 (car pair)) (= "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr pair))))) ) (cdr pair) ) ) (dictsearch (vlax-vla-object->ename (vla-getextensiondictionary blk)) "ACAD_ENHANCEDBLOCK" ) ) ) ) (cdr (assoc 301 (entget vis))) ) ) ;; Start Undo - Lee Mac ;; Opens an Undo Group. (defun LM:startundo ( doc ) (LM:endundo doc) (vla-startundomark doc) ) ;; End Undo - Lee Mac ;; Closes an Undo Group. (defun LM:endundo ( doc ) (while (= 8 (logand 8 (getvar 'undoctl))) (vla-endundomark doc) ) ) ;; Active Document - Lee Mac ;; Returns the VLA Active Document Object (defun LM:acdoc nil (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object)))) (LM:acdoc) ) (vl-load-com) (princ) Quote
woodman78 Posted May 19, 2015 Author Posted May 19, 2015 Brilliant as usual LeeMac. Stunning stuff. It is exactly what I was after even down to the naming of the blocks. Thanks. Quote
Lee Mac Posted May 19, 2015 Posted May 19, 2015 Thank you woodman, it was an interesting one to write - I'm glad you are pleased with the result Quote
chico1201 Posted June 16, 2015 Posted June 16, 2015 Thanks for your help the lisp doesn't displayed in an AutoCAD Table. Any other ideas? Quote
hagra Posted October 2, 2023 Posted October 2, 2023 The lisp stops at 8 visibility states and stops running. What have I missed? there are about 20 states in the block Quote
gozzix85 Posted February 26 Posted February 26 Anyone has a way to keep each block's dynamic properties? Should be an easy fix to the code above. Thanks Quote
Lee Mac Posted February 26 Posted February 26 1 hour ago, gozzix85 said: Anyone has a way to keep each block's dynamic properties? Should be an easy fix to the code above. Thanks Comment this line - (vla-converttostaticblock tmp (uniqueblockname (strcat blk "_" x))) 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.