Set all Blocks to "Allow Exploding" macro

Set all Blocks to "Allow Exploding" macro

jagostinho74
Collaborator Collaborator
4,941 Views
11 Replies
Message 1 of 12

Set all Blocks to "Allow Exploding" macro

jagostinho74
Collaborator
Collaborator

Hello,

 

I have a DWG w/ several Blocks, some that can be exploded and some that cannot.

Can anyone point to a macro that can set them all to be explodable?

 

Thank you

J

Assistant BIM/CAD Manager

Manchester, UK


0 Likes
Accepted solutions (1)
4,942 Views
11 Replies
Replies (11)
Message 3 of 12

jagostinho74
Collaborator
Collaborator

Thank you for the link @ВeekeeCZ but I am not managing to get it to work.

I was keen on adding this to a new toolbar button but I am guessing that it may not work if the code is defining a function?

Assistant BIM/CAD Manager

Manchester, UK


0 Likes
Message 4 of 12

ВeekeeCZ
Consultant
Consultant
Accepted solution

You should learn how to deal with lisp. Look HERE . Then your 'macro' in your toolbar would be just a command name.

 

The second option is to put the entire lisp into the macro field. It will work, but it's dirty and totally unreadable:

 

((lambda () (vl-load-com) (vlax-for b (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (or (wcmatch (vla-get-Name b) "`**_Space*") (vla-put-explodable b :vlax-true)))(princ)))

Message 5 of 12

jagostinho74
Collaborator
Collaborator

thank you @ВeekeeCZ 

Assistant BIM/CAD Manager

Manchester, UK


0 Likes
Message 6 of 12

Cladboy
Participant
Participant

Hi @jagostinho74,

 

Appreciate this was a while ago, but, I had a similar issue and ended up at your post above. 

Using Co-pilot i came up with to the lisp below - if it doesn't work blame Microsoft, not me 😂.

 

(defun c:SetExplodable ()
  (setq ss (ssget "X" '((0 . "INSERT")))) ; Select all blocks
  (if ss
    (progn
      (setq i 0)
      (repeat (sslength ss)
        (setq blk (vlax-ename->vla-object (ssname ss i)))
        (if (vlax-property-available-p blk 'Explodable)
          (vla-put-Explodable blk :vlax-true)
        )
        (setq i (1+ i))
      )
    )
    (princ "\nNo blocks found.")
  )
  (princ)
)

 

 

Hope this helps, albeit a little late to the show.

 

Message 7 of 12

Sea-Haven
Mentor
Mentor

@Cladboy "if it doesn't work blame Microsoft, not me" I have used Copilot and its success rate is not great, but did you test the code ? 

 

A bit of googling would reveal. "Explodable property is part of AcDbBlockTableRecord object which is block definition." have a look at BeekeeCZ post.

 

 

 

0 Likes
Message 8 of 12

Cladboy
Participant
Participant

@Sea-Haven Yes i did test it and it worked for me.

 

0 Likes
Message 9 of 12

cadffm
Consultant
Consultant

like Alan

No, that's impossible. You remembered wrong or posted the wrong code.

 

If you use chatgpt, co-pilot or others, then do it, but spare others. If you have any questions, ask chatgpt, co-pilot ..

Sebastian

0 Likes
Message 10 of 12

Cladboy
Participant
Participant

Right then, a couple of things.

 

1. My mistake for not thoroughly testing the lisp. It looked as though i was getting the result I and @jagostinho74 wanted to achieve, but long story short it didn't. My bad, hands up, but here's another AI generated lisp that does work - as far as i can see.

 

(defun c:MakeBlocksExplodable ()
(vl-load-com)
(setq *acad* (vlax-get-acad-object))
(setq *doc* (vla-get-ActiveDocument *acad*))
(setq *blocks* (vla-get-Blocks *doc*))
(vlax-for block *blocks*
(if (eq (vla-get-IsXRef block) :vlax-false)
(vla-put-Explodable block :vlax-true)
)
)
(princ "\nAll blocks are now explodable.")
(princ)
)

 

 

 

2. This is a genuine question without looking for an argument. What's the problem with someone using AI to try and find a solution? "If you use chatgpt, co-pilot or others, then do it, but spare others. If you have any questions, ask chatgpt, co-pilot .."

Message 11 of 12

Sea-Haven
Mentor
Mentor

There is nothing wrong with using AI, Copilot or ChatGP, only issue is they have a high failure rate, a lot of code is posted here with "This is not working can someone fix."

 

It very much depends on the task once you get into deeper code requirement like this task, AI struggles. Plenty of failure code has been posted here.

 

As I said I have tried Copilot some results good others just ignore.

Message 12 of 12

thinkbdw
Observer
Observer

Make this last one as a lsp file and it works a treat!!! Nice one @Cladboy 😘