convert dynamic block visibility to static
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I have some issue with a lips created by dlanorh, it seem not to work when your are dynamic block without attribute. I ask some improved to dlanorh, but it seem to disaperar since 2021.
https://forums.autodesk.com/t5/dynamic-blocks-forum/dynamic-block-visibility-into-individual-block/t...
I want to use your undynamic script but something is wrong on version 2023 in autocad, it says "Nothing Found" but you can see there a visibility state and I need to be explose in block name visibility
(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)))
)
);end_defun
(defun LM:getvisibilitystate ( blk / vis ) (if (setq vis (LM:getvisibilityparametername blk)) (LM:getdynpropvalue blk vis)))
(defun LM:setdynpropvalue ( blk prp val )
(setq prp (strcase prp))
(vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-put x 'value val))) (vlax-invoke blk 'getdynamicblockproperties)
)
);end_defun
(defun LM:getdynpropvalue ( blk prp )
(setq prp (strcase prp))
(vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value))) (vlax-invoke blk 'getdynamicblockproperties))
);end_defun
(defun rh:has_tag (o tg) (vl-some '(lambda (x) (= tg (strcase (vla-get-tagstring x)))) (vlax-invoke o 'getattributes)))
(defun rh:dbe ( blk doc lyr )
(vlax-for obj (vla-item (vlax-get-property doc 'blocks) blk)
(cond ( (and (/= (vla-get-layer obj) lyr)
(not (wcmatch (strcase (vlax-get-property obj 'objectname)) "*ENTITY*"))
)
(vla-delete obj)
)
)
)
);end_defun
(vl-load-com)
;Dynamic to Static Block By visibility state
(defun c:d2sbv ( / *error* c_doc c_spc sv_lst sv_vals tag flg obj o d vn en prp val f ss cnt obj bn ang vn ipt n_obj nbn)
(defun *error* ( msg )
(mapcar 'setvar sv_lst sv_vals)
(if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred.")))
(princ)
);end_local_*error*_defun
(setq c_doc (vlax-get-property (vlax-get-acad-object) 'activedocument)
c_spc (vlax-get-property c_doc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
sv_lst (list 'cmdecho 'osmode)
sv_vals (mapcar 'getvar sv_lst)
);end_setq
(mapcar 'setvar sv_lst '(0 0))
;user settings
(setq tag "STATION-NO")
(while (not flg)
(setq obj (vlax-ename->vla-object (car (entsel "\nSelect One of the Dynamic Blocks to Convert : "))))
(cond ( (and (= (setq o (vlax-get obj 'objectname)) "AcDbBlockReference")
(= :vlax-true (setq d (vlax-get-property obj 'isdynamicblock)))
(setq vn (LM:getvisibilitystate obj))
);end_and
(setq en (vlax-get obj 'effectivename) flg T prp (LM:getvisibilityparametername obj))
(cond ( (or (= :vlax-false (vlax-property-available-p obj 'hasattributes)) (not tag) (not (rh:has_tag obj tag))) (setq val 0)))
)
(t
(cond ( (/= o "AcDbBlockReference") (setq msg "NOT a Block"))
( (= d :vlax-false) (setq msg "NOT a Dynamic Block"))
( (not vn) (setq msg "Block has NO Visibility Parameter"))
);end_cond
(alert msg)
)
);end_cond
);end_while
(setq ss (ssget "_A" '((0 . "INSERT") (66 . 1) (410 . "Model"))))
(cond (ss
(repeat (setq cnt (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt))))
bn (vlax-get obj 'effectivename)
);end_setq
(cond ( (= bn en)
(setq ang (lm:getdynpropvalue obj "angle1")
vn (LM:getvisibilitystate obj)
ipt (vlax-get obj 'insertionpoint)
n_obj (vlax-invoke c_spc 'insertblock ipt en 1 1 1 0)
);end_setq
(LM:setdynpropvalue n_obj prp vn)
(if (numberp val)
(setq val (1+ val) nbn (strcat vn "_" (itoa val)))
(setq val (vl-some '(lambda (x) (if (= tag (strcase (vla-get-tagstring x))) (vla-get-textstring x))) (vlax-invoke obj 'getattributes))
nbn (strcat vn "_" val)
);end_setq
);end_if
(vla-converttostaticblock n_obj nbn)
(rh:dbe nbn c_doc "0")
(vla-delete n_obj)
(setq n_obj (vlax-invoke c_spc 'insertblock ipt nbn 1 1 1 ang))
(mapcar '(lambda (x) (vlax-put-property n_obj x (vlax-get-property obj x))) (list 'layer 'truecolor 'xscalefactor 'yscalefactor 'zscalefactor))
(vla-delete obj)
)
);end_cond
);end_repeat
)
(t (alert "Nothing Found"))
);end_cond
(vla-purgeall c_doc)
(vla-regen c_doc acallviewports)
(mapcar 'setvar sv_lst sv_vals)
(princ)
);end_defun
If I understand his code, I need some modification here : (setq ss (ssget "_A" '((0 . "INSERT") (66 . 1) (410 . "Model")))), but dbe function not work after. Please can you look something? In attchment you can see lips and example file with block.
Thanks in advance,
Sincerly