Jump to content

Burst in VBA


EGoldberg

Recommended Posts

All,

 

I've looked through the forums without much luck on my problem. I guess a lot of you prefer Lisp and I'm not quite ready to run down that path yet, I give you all credit though!

 

My question is how can I run or duplicate the effect of burst on a block's attributes using VBA? I have my block set as an object PBLK so

 

PBLK.explode

 

would explode the object but unfortunately it doesn't look like the burst command ever made it into the libraries. My "longcut" would be to explode the object, find the new text fields and copy the old attributes over but that sounds like horrible coding practice. Any help would be greatly appreciated.

Link to comment
Share on other sites

My version of the 'long cut', written a while back, with the addition that invisible attributes are not created.

 

;; Performs in the same way as Burst.lsp,
;; but is much faster and doesn't display invisible attributes.

(defun c:Burst2 ( / *error* doc blocks undo ss )
 (vl-load-com)
 ;; © Lee Mac  ~  20.05.10

 (defun *error* ( msg ) (and Undo (vla-EndUndoMark doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )    

 (setq doc    (vla-get-ActiveDocument (vlax-get-acad-object))
       blocks (vla-get-Blocks doc))    

 (if (ssget "_:L" '((0 . "INSERT")))
   (progn
     (setq Undo (not (vla-StartUndoMark doc)))
     
     (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))

       (if (eq :vlax-true (vla-get-Explodable (Itemp blocks (BlockName obj))))
         (progn
           
           (if (eq :vlax-true (vla-get-HasAttributes obj))
             
             (foreach att (vlax-invoke obj 'GetAttributes)
               
               (if (eq :vlax-false (vla-get-Invisible att))

                 (
                   (if (and (vlax-property-available-p att 'MTextAttribute)
                            (eq :vlax-true (vla-get-MTextAttribute att)))

                     MAtt2MText Att2Text
                   )
                   (entget (vlax-vla-object->ename att))
                 )
               )
             )
           )              
                   
           (foreach eobj (vlax-invoke obj 'Explode)
             (if (eq "AcDbAttributeDefinition" (vla-get-ObjectName eobj))
               (vla-delete eobj)
             )
           )
           (vla-delete obj)
         )
       )
     )
     (vla-Delete ss)

     (setq Undo (vla-EndUndomark doc))
   )
 )
 (princ)            
)

(defun BlockName ( obj )
 (vlax-get-property obj
   (if (vlax-property-available-p obj 'EffectiveName)
     'EffectiveName 'Name
   )
 )
)
                                                
(defun Itemp ( coll item )
 (if
   (not
     (vl-catch-all-error-p
       (setq item
         (vl-catch-all-apply
           (function vla-item) (list coll item)
         )
       )
     )
   )
   item
 )
)

(defun RemovePairs ( pairs lst )
 ;; © Lee Mac  ~  22.05.10
 (vl-remove-if
   (function
     (lambda ( pair )
       (vl-position (car pair) pairs)
     )
   )
   lst
 )
)

(defun RemoveFirstPairs ( pairs lst )
 ;; © Lee Mac  ~  22.05.10
 (defun foo ( pair lst )
   (if lst
     (if (eq pair (caar lst))
       (cdr lst)
       (cons (car lst) (foo pair (cdr lst)))
     )
   )
 )

 (foreach pair pairs
   (setq lst (foo pair lst))
 )
 lst
)
 
(defun Att2Text ( eLst / dx74 )
 ;; © Lee Mac  ~  22.05.10
 (setq dx74 (cdr (assoc 74 eLst)))
   
 (entmake
   (append '( (0 . "TEXT") )
     (RemovePairs '(0 100 2 74 70 280)
       (subst
         (cons 73 dx74) (assoc 74 eLst) eLst
       )
     )
   )
 )
)

(defun MAtt2MText ( eLst )
 ;; © Lee Mac  ~  22.05.10
 (entmake
   (append '( (0 . "MTEXT") (100 . "AcDbEntity") (100 . "AcDbMText") )
     (RemoveFirstPairs '(40 1 50 41 7 71 72 71 72 73 10 11 11 210)
       (RemovePairs '(-1 102 330 360 5 0 100 101 2 42 43 51 74 70 280) eLst)
     )
   )
 )
)

 

In LISP I'm afraid... VBA is dead.

Link to comment
Share on other sites

Thanks for your help. I wish I had the time to sit down and learn LISP and I'm sure I will be in the future but for now I need to use VBA. VBA nicely integrates with Windows to allow me to accomplish a full featured program that runs inside and out of AutoCAD to accomplish my task.

 

I do believe I managed to successfully duplicate the feature of burst in VBA. For those who may come after me and need an idea, please see the following. Anyone who understands VBA, I'd appreciate any comments on anything I might of missed.

 

bk = the block reference that needs to be burst. Call the burst in a program using Call myburst(your block here).

 

Sub myburst(bk)
               OAtts = bk.GetAttributes

               expobj = bk.Erase
               ThisDrawing.ActiveLayer = ThisDrawing.Layers("0")
               For Q = 0 To 7
               Set txtobj = ThisDrawing.PaperSpace.AddText(OAtts(Q).TextString, OAtts(Q).InsertionPoint, OAtts(Q).Height)
               With txtobj
                   .StyleName = OAtts(Q).StyleName
                   .ScaleFactor = OAtts(Q).ScaleFactor
                   '.Alignment = acAlignmentMiddleCenter
                   .color = OAtts(Q).color

               End With
               ActiveDocument.Regen acActiveViewport
               Set txtobj = Nothing
               Next
End Sub

Link to comment
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
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...