Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Member
stoews1
Posts: 9
Registered: ‎01-28-2009
Message 1 of 30 (899 Views)

Repeat (c:burst) command in lisp routine

899 Views, 29 Replies
04-14-2009 04:17 PM
I am creating a lisp routine to clean up xrefs from architectural drawings for use in our draiwngs. As part of my routine, I want to burst the drawing several times to get rid of all of the blocks within blocks until the whole drawing is single entities. I've tried using the repeat command with (c:burst) and it works until there is "0 found" objects. At which point the lisp routine ends without carrying on. If I say for it to repeat for example 3 times, and it takes exactly 3 times to burst everything into single entities, the routine continues on. It only causes an error if it finds "0 found" before it has repeated the specified number of times. is there a way to make it do a "burst" as many times as needed until there is "0 found" and then continue on with the routine.

this is the part of the lisp routine in question:

(repeat 5
(sssetfirst nil (ssget "X" (list )))
(c:burst)
)
*Joe Burke
Message 2 of 30 (898 Views)

Re: Repeat (c:burst) command in lisp routine

04-15-2009 05:05 AM in reply to: stoews1
You could run burst within a while loop which checks the number of objects before and
after burst.

(while (/= oldcnt newcnt)
< loop >
)

You might use the sslength function to get the count.

Joe Burke
*Expert Elite*
Kent1Cooper
Posts: 5,616
Registered: ‎09-13-2004
Message 3 of 30 (898 Views)

Re: Repeat (c:burst) command in lisp routine

04-15-2009 05:37 AM in reply to: stoews1
You could also just check whether there are still any Blocks or Xrefs left in the drawing:

(while (ssget "X" '((0 . "INSERT")))
(sssetfirst nil (ssget "X" (list )))
(c:burst)
); end while

--
Kent Cooper


stoews1 wrote...
....is there a way to make it do a "burst" as many times as needed until there is "0 found" and then continue on with the routine.
Kent Cooper
*Joe Burke
Message 4 of 30 (899 Views)

Re: Repeat (c:burst) command in lisp routine

04-15-2009 06:11 AM in reply to: stoews1
Hi Kent,

I think that would be an endless loop is there are either xrefs, or non-explodable
blocks, or blocks which ACAD cannot explode due to non-uniform scaling issues
involved.

Joe
*Expert Elite*
Kent1Cooper
Posts: 5,616
Registered: ‎09-13-2004
Message 5 of 30 (899 Views)

Re: Repeat (c:burst) command in lisp routine

04-15-2009 08:35 AM in reply to: stoews1
I assume your suggestion also would not take apart Xrefs or non-explodable Blocks. I don't have a new enough version to have non-explodable blocks, so I wouldn't know about them. Is there a way to check for those?

Both Explode and Burst [unlike, for instance, Refedit] *can* handle non-uniformly-scaled Blocks [at least in ACAD2004], so that shouldn't be a problem.

As for Xref's, I hadn't ever had reason to Explode or Burst one, but sure enough, they won't do it. So yes, it would probably be necessary to precede it all with something like:

(command "_.xref" "_bind" "*")

to change them all into Blocks first.

--
Kent Cooper


Joe Burke wrote...
I think that would be an endless loop is there are either xrefs, or non-explodable blocks, or blocks which ACAD cannot explode due to non-uniform scaling issues involved.
Kent Cooper
Active Member
stoews1
Posts: 9
Registered: ‎01-28-2009
Message 6 of 30 (899 Views)

Re: Repeat (c:burst) command in lisp routine

04-15-2009 08:55 AM in reply to: stoews1
Thanks for the replies guys.

Kent your

(while (ssget "X" '((0 . "INSERT")))
(sssetfirst nil (ssget "X" (list )))
(c:burst)
); end while

did the job perfectly. Thanks.
*Expert Elite*
Kent1Cooper
Posts: 5,616
Registered: ‎09-13-2004
Message 7 of 30 (899 Views)

Re: Repeat (c:burst) command in lisp routine

04-15-2009 09:38 AM in reply to: stoews1
You're welcome. I take it that either you don't have any Xrefs to deal with, or Burst in some later version than I have can now take those apart.

--
Kent Cooper
Kent Cooper
Active Member
jj26
Posts: 7
Registered: ‎02-05-2013
Message 8 of 30 (592 Views)

Re: Repeat (c:burst) command in lisp routine

02-05-2013 03:20 PM in reply to: stoews1

Hi guys,

Not sure if I should bump a 4 year old thread or make a new one. Anyways, I'm trying to do a similar thing as the OP, but XREF's are giving me some problems. I don't want to bind the XREF's, but want to create a routine which will clean up drawings automatically. Is there an easy way to,

 

1) Unattach all of the XREF's in a current drawing

2) Run Kent's burst loop

3) Reattach the XREF's

 

Any help is appreciated.

Active Member
jj26
Posts: 7
Registered: ‎02-05-2013
Message 9 of 30 (572 Views)

Re: Repeat (c:burst) command in lisp routine

02-05-2013 05:17 PM in reply to: jj26

I was thinking something like,

 

(command "_.-xref" "_UNLOAD" "*")

(while (ssget "_A" '((0 . "INSERT")))
(sssetfirst nil (ssget "_A" (list)))
(c:burst)
)

(command "_.-xref" "_RELOAD" "*" )

 

But of course an unloaded XREF is still 'in' the drawing, and I don't think there's a way to select all blocks which aren't unloaded XREF's. And then if you detach the XREF you have to start keeping track of the names of the XREF's and their directories, and then that's where I don't know quite how to start.

*Expert Elite*
Kent1Cooper
Posts: 5,616
Registered: ‎09-13-2004
Message 10 of 30 (566 Views)

Re: Repeat (c:burst) command in lisp routine

02-05-2013 06:01 PM in reply to: jj26

jj26 wrote:

Hi guys,

Not sure if I should bump a 4 year old thread or make a new one. Anyways, I'm trying to do a similar thing as the OP, but XREF's are giving me some problems. I don't want to bind the XREF's, but want to create a routine which will clean up drawings automatically. Is there an easy way to,

 

1) Unattach all of the XREF's in a current drawing

2) Run Kent's burst loop

3) Reattach the XREF's

 

Any help is appreciated.


You don't want to "unattach" them [if by that you mean what AutoCAD calls Detaching them], but rather Unload them, so that you can Reload them and they'll come back as they were.  I thought you could just do an Xref Unload *, then run the burst loop, and then Xref Reload *, but (ssget "X" '((0 . "INSERT"))) finds even Unloaded Xrefs, so the loop never stops finding things, even if it can't do anything to them, so it doesn't end.

 

Another possibility I thought of was to Wblock all Xrefs out to a new drawing, burst everything, and then bring that new drawing back in.  But doing so [with one test Xref] converts it from an Xref to a regular Block.  I didn't try Xref-ing that back in, but if you have more than one Xref to deal with, I assume you wouldn't want that.

 

You may need to step through each item and check whether it's an Xref, in which case you don't need to Unload them.  I'm not where I can test this, but give it a try:

 

(defun C:YourCommandName (/ GoAgain blks blk)
  (vl-load-com)
  (setq GoAgain T); to begin with [make at least one pass]
  (while
    (and
      GoAgain
        ; will be nil once it makes a pass without finding any non-Xref blocks
      (setq blks (ssget "_X" '((0 . "INSERT")))); includes Xref's
    ); and
    (setq GoAgain nil); "zero out" initially for this pass
    (repeat (sslength blks)
      (setq blk (ssname blks 0)); first [remaining] item in selection
      (if (not (vlax-property-available-p (vlax-ename->vla-object blk) 'Path))
        ; i.e. it's not an Xref [ordinary Blocks don't have Path property]
        (progn
          (setq GoAgain T); it found one, so run the loop again after this pass
          (sssetfirst nil blk)
          (c:burst)
        ); progn
      ); if
      (ssdel blk blks); remove that entity name from selection, go on to next
    ); repeat
  ); while
); defun

 

Might Explode do just as well as Burst under the circumstances?  If so, and given that it would do them one at a time, you wouldn't need (sssetfirst), but could replace that line and the (c:burst) line with just:

 

(command "_.explode" blk)

Kent Cooper
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.