1 Lisp to: insert block, explode it and group it

1 Lisp to: insert block, explode it and group it

Anonymous
Not applicable
1,040 Views
7 Replies
Message 1 of 8

1 Lisp to: insert block, explode it and group it

Anonymous
Not applicable

Hi all, and thanks in advance for your time

 

I'm looking for a lisp to insert a block (insert point and rotation).
It should then explode that block and group the remainders (which are 3 blocks).

 

Anybody know where to start? I'm especially having difficulty with the grouping.

0 Likes
1,041 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant

As for the start...

 

(defun c:BInsertGroup ( / el ss)

  (setq el (entlast)
        ss (ssadd))
  (command-s "_.INSERT")
  (command "_.EXPLODE" "_Last")

  (while (setq el (entnext el))
    (ssadd el ss))
  (initcommandversion)
  (command "_.GROUP" ss "")
  (princ)
  )
Message 3 of 8

Kent1Cooper
Consultant
Consultant

Since after an EXPLODE, the resulting pieces are the Previous selection, you can try this:

(defun c:BIEG (); = Block Insert, Explode & Group
  (command-s "_.INSERT")
  (command "_.explode" "_Last")
  (sssetfirst nil (ssget "_P"))
  (command "_.group")
)

which [in minimal testing ] leaves you in the Group command do use whatever options you need there.

Kent Cooper, AIA
Message 4 of 8

Anonymous
Not applicable

Thanks so much for the help

 

How would I go about inserting a block by fixed name?

 

The method I'm familiar with doesn't seem to work:

(defun c:BIEG (); = Block Insert, Explode & Group
  (command-s "_.INSERT" Blockname pause 1 1 pause)
  (command "_.explode" "_Last")
  (sssetfirst nil (ssget "_P"))
  (command "_.group")
)

 

0 Likes
Message 5 of 8

ВeekeeCZ
Consultant
Consultant

LISP version and Autocad version of some commands are sometimes different. Fortunately, using (initcommandversion) you can force the next command to use current autocad version. See the help HERE for more.

 


@Anonymous wrote:

...

(defun c:BIEG (); = Block Insert, Explode & Group
  (command "_.INSERT" Blockname pause 1 1 pause)
  (command "_.explode" "_Last")
  (sssetfirst nil (ssget "_P"))
(initcommandversion) (command "_.group") )

 


 

0 Likes
Message 6 of 8

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

How would I go about inserting a block by fixed name?

The method I'm familiar with doesn't seem to work:

....
  (command-s "_.INSERT" Blockname pause 1 1 pause)
....

 


 

That's because (command-s) can't accept the 'pause' token for User input [read about it in the AutoLisp Reference].  Do it without the -s, as in @ВeekeeCZ's modification [whether or not you need to include the (initcommandversion)].

Kent Cooper, AIA
0 Likes
Message 7 of 8

ВeekeeCZ
Consultant
Consultant

@Kent1Cooper wrote:

@Anonymous wrote:

....

How would I go about inserting a block by fixed name?

The method I'm familiar with doesn't seem to work:

....
  (command-s "_.INSERT" Blockname pause 1 1 pause)
....

 


 

That's because (command-s) can't accept the 'pause' token for User input [read about it in the AutoLisp Reference].  Do it without the -s, as in @ВeekeeCZ's modification [whether or not you need to include the (initcommandversion)].


 

Are you sure about it? Because it works for me either way. I removed '-s' just because I saw no benefit of it any more. Also why I didn't left any comment on that minor mod.

0 Likes
Message 8 of 8

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:

@Kent1Cooper wrote:

.... (command-s) can't accept the 'pause' token for User input [read about it in the AutoLisp Reference].  ....


Are you sure about it? Because it works for me either way. ....


 

All I'm sure about is that the AutoLisp Reference entry for (command-s), under "Known Considerations," says:

 

NoPause.PNG

 

But if that's not true, it wouldn't be the first disagreement I've seen between Help's descriptions and the way things actually work.

Kent Cooper, AIA
0 Likes