exploding certain entities in all block reference lisp

exploding certain entities in all block reference lisp

Brian.TsaiF883G
Participant Participant
1,032 Views
6 Replies
Message 1 of 7

exploding certain entities in all block reference lisp

Brian.TsaiF883G
Participant
Participant

working from 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/any-lisp-to-delete-all-dimensions-fr...

i modified the codes to 

sorry, i still don't understand

basically i modified the codes to

(defun c:blitz2  (/ aDoc)
      (vl-load-com)
      (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
      (vlax-for blk (vla-get-blocks aDoc)
      (if
            (and
                  (eq :vlax-false (vla-get-isXref blk))
                  ;(eq :vlax-false (vla-get-isLayout blk))
                  (not (wcmatch (vla-get-name blk) "`*D*"))
                  )
                 (vlax-for dim blk
                       (if (wcmatch
                                 (vla-get-ObjectName dim)
                                 "AcDb*Dimension")
                             (vla-explode dim))
                       )
                 )
            )
      (vla-regen aDoc acAllViewports)
      (princ)
      )


however, it doesn't work for dimensions entity

after some experimenting, it works for polylines when i change

"AcDb*Dimension")

to 

"AcDb*Polyline")

can anyone help?

0 Likes
Accepted solutions (1)
1,033 Views
6 Replies
Replies (6)
Message 2 of 7

Moshe-A
Mentor
Mentor

@Brian.TsaiF883G  hi,

 

Apparently (vla-explode) function does not work on dimensions. so to solved your request you need to copy the dimension by means of (vla-copyObjects) to model space and call (command "explode") collect all extracted objects and (vla-copyObjects) back to the block.

 

??

 

Moshe

 

 

0 Likes
Message 3 of 7

Moshe-A
Mentor
Mentor
Accepted solution

@Brian.TsaiF883G ,

 

check this

 

enjoy

Moshe

 

(vl-load-com); load activex support

(defun c:blitz2  (/ aDoc AcDbBlkTblRec AcDbEntity ename obj^ ctr lst)
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")
  
 (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object)))

 (setq ctr 0)
 (vlax-for AcDbBlkTblRec (vla-get-blocks aDoc)
  (if (and
        (eq :vlax-false (vla-get-isXref AcDbBlkTblRec))
        (not (wcmatch (vla-get-name AcDbBlkTblRec) "`*Model_Space,`*Paper_Space[#],`*D*"))
      )
   (progn
    (setq ctr 0)
    (vlax-for AcDbEntity AcDbBlkTblRec
     (if (wcmatch (vla-get-ObjectName AcDbEntity) "AcDb*Dimension")
      (progn
       (setq ename (entlast) obj^ nil)
       (vlax-invoke aDoc 'CopyObjects (list AcDbEntity) (vla-get-ModelSpace aDoc)) ; copy to model space
       (command ".explode" (entlast))
       (while (setq ename (entnext ename))
	(setq obj^ (cons (vlax-ename->vla-object ename) obj^))
       )
       (vlax-invoke aDoc 'CopyObjects obj^ AcDbBlkTblRec) ; copy/back to block

       (foreach o obj^
	(vla-delete o)
        (vlax-release-object o)
       ); foreach

       (vla-delete AcDbEntity) ; delete dimension
       (setq ctr (1+ ctr))
      ); progn
     ); if

     (vlax-release-object AcDbEntity)
    ); vlax-for
   ); progn
  ); if

  (if (> ctr 0)
   (setq lst (cons (cons (vla-get-name AcDbBlkTblRec) ctr) lst) ctr 0)
  )
  (vlax-release-object AcDbBlkTblRec)
 ); vlax-for
  
 (vla-regen aDoc acAllViewports)
 (vlax-release-object aDoc)

 (command "._undo" "_end")
 (setvar "cmdecho" 1)

 (if (not lst)
  (princ "\nNo nested dimensions found to explode.")
  (foreach item lst
   (princ (strcat "\nBlock \"" (car item) "\", " (itoa (cdr item)) " dimension(s) exploded."))
  )
 ); if
  
 (princ)
); c:blitz2
0 Likes
Message 4 of 7

Brian.TsaiF883G
Participant
Participant

Why are you so awesome? ~~~~

Thank you very much 🙂

0 Likes
Message 5 of 7

Brian.TsaiF883G
Participant
Participant

Now, I am trying to remove all "KS_BOLT" (non-autocad entity)  by replacing 

  (if (wcmatch (vla-get-ObjectName AcDbEntity) "AcDb*Dimension")


to

(if (wcmatch (vla-get-ObjectName AcDbEntity) "Ks_Bolt")

KS_BOLT have the following info I extracted from 'VDumpit' from https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/exploding-certain-entities-in-all-bl...

I am able to select the correct quantity of KS_BOLT but i cannot execute explode or erase command on those non-AutoCAD entities. Does it need some special codes for non_AutoCAD entities?


;;;;;
Select Entity to Dump; IKs_ComBolt: IKs_ComBolt Interface
; Property values:
; Application (RO) = #<VLA-OBJECT IAcadApplication 00007ff726181e30>
; AreaClassName (RO) = ""
; BoltCoatingType = 2
; BoltDisplay = -1
; BoltMountingSpaceFootLength (RO) = 0.0
; BoltMountingSpaceFootWidth (RO) = 0.0
; BoltMountingSpaceHeadLength (RO) = 0.0
; BoltMountingSpaceHeadWidth (RO) = 0.0
; BoltPartlist = -1
; BoltStyleName = "8.8S-GALV"
; Count = 1
; CounterSunk = 0
; DetailStyleName (RO) = ""
; Diameter = 16.0
; DiskInnerDiameter = 18.0
; DiskOuterDiameter = 32.4
; DiskThick = 3.1
; DisplayClassName (RO) = ""
; Document (RO) = #<VLA-OBJECT IAcadDocument 000002811f8aea08>
; EntityTransparency = "ByLayer"
; FamilyClassName (RO) = ""
; FootThick = 16.0
; FreeDescriptionName (RO) = "NONE"
; GripMax (RO) = 174.0
; GripMin (RO) = 164.0
; Handle (RO) = "3F922"
; HasExtensionDictionary (RO) = 0
; HeadThick = 11.0
; Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 0000028185511b98>
; Inbus = 0
; InsertPoint (RO) = (-451.0 2677.0 -5.65455e-13)
; ItemNumber = "025"
; KeySize = 27.0
; KlemmLength = 153.188
; Layer = "PS_BOLT"
; Length = 180.0
; LengthAddition = 0.0
; Linetype = "ByLayer"
; LinetypeScale = 1.0
; Lineweight = -1
; Material = "ByLayer"
; MaterialIndex = 3002
; MountingBolt = 0
; Name = "M16 x 180 8.8/S GALV"
; Note1 = ""
; Note2 = ""
; NutDisplay = -1
; NutPartlist = 0
; ObjectID (RO) = 150
; ObjectName (RO) = "Ks_Bolt"
; OwnerID (RO) = 71
; PalNutDisplay = 0
; PalNutPartlist = 0
; PartOrigin (RO) = 0
; PlotStyleName = "Color_4"
; PosNumber = ""
; SafetyNutKeySize = 0.0
; SafetyNutThick = 0.0
; ShipNumber = ""
; Tension = 0.0
; ThreadedRod = 0
; TotalCount (RO) = 0
; TrueColor = #<VLA-OBJECT IAcadAcCmColor 0000028185511c50>
; Visible = -1
; Washer2Display = 0
; Washer2Partlist = -1
; WasherDisplay = -1
; WasherPartlist = -1
; WedgeWasher2Display = 0
; WedgeWasher2Partlist = 0
; WedgeWasherDisplay = 0
; WedgeWasherPartlist = 0
; Weight (RO) = 0.381242
; Xaxis (RO) = (-0.0522163 0.998636 2.03474e-16)
; Yaxis (RO) = (-6.87954e-16 -2.39723e-16 1.0)
; Methods supported:
; ArrayPolar (3)
; ArrayRectangular (6)
; BuildName ()
; CalculateWeight (1)
; Copy ()
; Delete ()
; GetBoundingBox (2)
; GetExtensionDictionary ()
; GetInsertUcs (1)
; GetMidLineUcs (1)
; GetObjectDisplayMode ()
; GetXData (3)
; Highlight (1)
; IntersectWith (2)
; Mirror (2)
; Mirror3D (3)
; Move (2)
; RecomputeBoltLength ()
; RetrieveGeometry (1)
; Rotate (2)
; Rotate3D (3)
; ScaleEntity (2)
; SetObjectD
Select Entity to Dump
isplayMode (1)
; SetPartOrigin (1)
; SetXData (2)
; TransformBy (1)
; Turn ()
; Update ()

0 Likes
Message 6 of 7

Moshe-A
Mentor
Mentor

@Brian.TsaiF883G hi,

 

"Does it need some special codes for non_AutoCAD entities?"

 

before you rush to change the code with other objects first check it manually (try exploding them)

Custom AutoCAD objects need to support any functionality it needed and that's include the explode function.

if you can not explode KS_BOLT object then the programmer did not implement it 😀

 

Moshe

 

0 Likes
Message 7 of 7

Brian.TsaiF883G
Participant
Participant

Yes it can be exploded.

i tried replacing line 22

  (command ".explode" (entlast))


 to

(command ".erase" (entlast))

 

but it doesn't erase it at all

0 Likes