Explode Dynamic Block and create new static block
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I need some help in this conde!? i can't read com autocad
This routine must perform the following steps:
- Iterates through all INSERT entities in the drawing.
- Checks if each entity represents a dynamic block.
- If a dynamic block is found, it explodes the block while preserving attribute values.
- Creates a new static block using the exploded entities and attribute values.
- Skips entities that are not dynamic blocks.
- Outputs a message indicating the completion of the process.
(defun C:ExplodeAndCreateBlocks (/ ss)
(vl-load-com)
;; Function to explode a dynamic block and preserve attribute values
(defun explode_dynamic_block (dyn_blk)
(setq att_values '())
(vlax-for obj (vla-get-attributes dyn_blk)
(setq att_value (vla-get-textstring obj))
(setq att_values (cons att_value att_values))
)
(vla-explode dyn_blk)
att_values
)
;; Function to create a new block with attribute values
(defun create_block_with_attributes (blk_name base_pt att_values)
(setq new_blk_name (strcat blk_name "_Static"))
(setq new_blk (vla-copy base_blk))
(vla-delete new_blk)
(vla-put-name new_blk new_blk_name)
(vla-insert new_blk base_pt)
(vlax-for obj (vla-get-attributes new_blk)
(vla-delete obj)
)
(vlax-for att new_blk
(vla-set-textstring att (car att_values))
(setq att_values (cdr att_values))
)
)
;; Get selection set of all dynamic block inserts
(setq ss (ssget "_X" '((0 . "INSERT"))))
(if ss
(progn
(setq total_blocks (sslength ss))
(setq count 0)
(repeat total_blocks
(setq count (1+ count))
(setq obj (ssname ss count))
(setq blk_name (cdr (assoc 2 (entget obj))))
(setq base_blk (vlax-ename->vla-object obj))
(setq base_pt (vlax-curve-getstartpoint base_blk))
(setq is_dynamic (vl-catch-all-error-p
(vl-catch-all-apply
'(lambda ()
(vla-get-isdynamicblock base_blk)
)
)
)
)
(if (not is_dynamic)
(prompt (strcat "\nSkipping block " (itoa count) " of " (itoa total_blocks) " - " blk_name " (not a dynamic block)"))
(progn
(prompt (strcat "\nProcessing block " (itoa count) " of " (itoa total_blocks) " - " blk_name))
(setq att_values (explode_dynamic_block base_blk))
(create_block_with_attributes blk_name base_pt att_values)
)
)
)
(princ "\nAll dynamic blocks exploded and converted to static blocks.")
)
(princ "\nNo dynamic blocks found in the drawing.")
)
(princ)
)