Jump to content
woodman78

Split a dynamic block into a single block for each state

Recommended Posts

woodman78

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?

Share this post


Link to post
Share on other sites
samifox

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

some clean up should be done later on

Share this post


Link to post
Share on other sites
pBe

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?

Share this post


Link to post
Share on other sites
BlackBox

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

 

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

Share this post


Link to post
Share on other sites
woodman78

Anyone care to give it a shot?

Share this post


Link to post
Share on other sites
samifox
No, I don't think you did. :P

 

im afraid we didnt got the joke:cry:

Share this post


Link to post
Share on other sites
woodman78

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?

Share this post


Link to post
Share on other sites
Dadgad
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

Share this post


Link to post
Share on other sites
woodman78

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

Share this post


Link to post
Share on other sites
Dadgad

When in doubt, check Lee Mac out. :)

Share this post


Link to post
Share on other sites
Lee Mac

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)

Share this post


Link to post
Share on other sites
woodman78

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

Share this post


Link to post
Share on other sites
Lee Mac

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

Share this post


Link to post
Share on other sites
pBe

 

It was indeed quite fun to code

 

Yup. indeed its. :)

Share this post


Link to post
Share on other sites
chico1201

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

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...