Jump to content

Split a dynamic block into a single block for each state


Recommended Posts

Posted

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?

Posted

you can use Lee's lisp to rename viability state as a new block quickly,

some clean up should be done later on

Posted

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?

Posted

... Did i not say its easy and fun to code?

 

No, I don't think you did. :P

Posted

Anyone care to give it a shot?

Posted
No, I don't think you did. :P

 

im afraid we didnt got the joke:cry:

Posted

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?

Posted
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?

Lee Mac's CB might do it.jpg

Posted

Thanks for your help guys that Lee's lisp doesn't make the static block. Any other ideas?

Posted

When in doubt, check Lee Mac out. :)

Posted

Many thanks for all the recommendations guys :thumbsup:

 

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)

Posted

Brilliant as usual LeeMac. Stunning stuff. It is exactly what I was after even down to the naming of the blocks. Thanks.

Posted

Thank you woodman, it was an interesting one to write - I'm glad you are pleased with the result :thumbsup:

Posted

 

It was indeed quite fun to code

 

Yup. indeed its. :)

  • 4 weeks later...
Posted

Thanks for your help the lisp doesn't displayed in an AutoCAD Table. Any other ideas?

  • 8 years later...
Posted

The lisp stops at 8 visibility states and stops running. What have I missed? there are about 20 states in the block

  • 1 year later...
Posted

Anyone has a way to keep each block's dynamic properties? Should be an easy fix to the code above. Thanks

Posted
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)))

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...