Author Topic: Using FOREACH with C:BURST  (Read 2940 times)

0 Members and 1 Guest are viewing this topic.

stusic

  • Guest
Using FOREACH with C:BURST
« on: June 20, 2013, 01:36:12 PM »
Good afternoon everyone :)

I've run into a bit of a problem and haven't been able to find a solution yet. I have a routine that inserts a bunch of blocks and explodes them, then uses a FOREACH statement to iterate through each of the exploded block components and changes an attributed tag that was nested in the original block. Works well. However, now I've run into a situation where I need to utilize the express tool's BURST to retain the properties of the layer it was inserted on.

Originally, there was this. It works well because it retained the selection of each block, therefore allowing me to modify the nested block attributes in each inserted instance:
Code: [Select]
(foreach obj (vlax-invoke tmp 'explode) ;; Explode the block
                    (cond
                        ;;bunch of COND statements here, including the modification of the nested attributed blocks
                    ) ;; end cond
                ) ;; end foreach

However, I was unable to get the BURST command to work within the FOREACH function. This is what works for BURSTing, but doesn't iterate through each of the exploded blocks (basically losing the selection):
Code: [Select]
(sssetfirst nil (ssadd (vlax-vla-object->ename tmp)))
(c:burst)

Does anyone know of a way to use the BURST and still iterate through each of the exploded blocks?

Thanks for any guidance, it's much appreciated.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Using FOREACH with C:BURST
« Reply #1 on: June 20, 2013, 01:44:18 PM »
I would recommend storing the layer of the block reference before exploding, and then applying this layer to the relevant exploded block components within the foreach loop iterating over the list returned by the explode method.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Using FOREACH with C:BURST
« Reply #2 on: June 20, 2013, 02:45:20 PM »
Before you burst, you could collect the last entity created (entlast). Then, after burst, entnext from the stored entlast variable and you have the newly created objects from burst. That would give you a selection of objects to edit.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

BlackBox

  • King Gator
  • Posts: 3770
Re: Using FOREACH with C:BURST
« Reply #3 on: June 20, 2013, 02:52:14 PM »
I would recommend storing the layer of the block reference before exploding, and then applying this layer to the relevant exploded block components within the foreach loop iterating over the list returned by the explode method.

FWIW - For some background, see this thread.
"How we think determines what we do, and what we do determines what we get."

stusic

  • Guest
Re: Using FOREACH with C:BURST
« Reply #4 on: June 20, 2013, 03:20:56 PM »
FWIW - For some background, see this thread.

Yeah, the solution you guys gave me there worked well. I was thinking I could just copy that code to the next section I'm working on, but this next section requires alteration of the nested attributed block, so it won't quite work. The explode method works well if I want to change nested attributed blocks, the burst method works well to maintain the original layer, but neither works well if I want to do both.  :|

I was trying to write something along the lines of what Lee suggested, but I error out (Error: bad argument type: consp "M-PIPING-INS-3-4"). Seems it's not quite as simple as I thought...

Code: [Select]
(foreach obj
(setq clay (vla-get-layer tmp)) ;; get layer of "tmp" block
(vlax-invoke tmp 'explode) ;; Explode the block
(setq css (ssget "_X" '((8 . "0")))) ;; Select the objects on layer "0". Not sure if this will just select objects within my
                                                                 ;; selection, or ALL objects in the drawing on this layer...
    (vla-put-layer css clay) ;; Put the ss "css" on layer of original tmp block
(cond
                        ;;bunch of COND statements here, including the modification of the nested attributed blocks
                    )
                )

BlackBox

  • King Gator
  • Posts: 3770
Re: Using FOREACH with C:BURST
« Reply #5 on: June 20, 2013, 03:28:25 PM »
FWIW - For some background, see this thread.

Yeah, the solution you guys gave me there worked well. I was thinking I could just copy that code to the next section I'm working on, but this next section requires alteration of the nested attributed block, so it won't quite work.
No worries; that was added here for context, so others can better understand what got us to this point... Background is helpful to know when offering suggestions, that's all.



The explode method works well if I want to change nested attributed blocks, the burst method works well to maintain the original layer, but neither works well if I want to do both.  :|

You lose me here.



I was trying to write something along the lines of what Lee suggested, but I error out (Error: bad argument type: consp "M-PIPING-INS-3-4").

Not so difficult... Lee suggested:

I would recommend storing the layer of the block reference before exploding, and then applying this layer to the relevant exploded block components within the foreach loop iterating over the list returned by the explode method.

... Consider:
Code - Auto/Visual Lisp: [Select]
  1. (setq layerName (vla-get-layer obj))
  2. (foreach x (vlax-invoke obj 'explode)
  3.   (vla-put-layer x layerName)
  4. )
"How we think determines what we do, and what we do determines what we get."

stusic

  • Guest
Re: Using FOREACH with C:BURST
« Reply #6 on: June 20, 2013, 03:54:31 PM »
... Consider:
Code - Auto/Visual Lisp: [Select]
  1. (setq layerName (vla-get-layer obj))
  2. (foreach x (vlax-invoke obj 'explode)
  3.   (vla-put-layer x layerName)
  4. )

Beautiful. I'm glad that I was *kinda* close in my guess. I am learning more and more each day. I just wish I wasn't under the gun and had time to really learn rather than just rushing to get it to work...

BlackBox

  • King Gator
  • Posts: 3770
Re: Using FOREACH with C:BURST
« Reply #7 on: June 20, 2013, 04:02:26 PM »
... Consider:
Code - Auto/Visual Lisp: [Select]
  1. (setq layerName (vla-get-layer obj))
  2. (foreach x (vlax-invoke obj 'explode)
  3.   (vla-put-layer x layerName)
  4. )

Beautiful. I'm glad that I was *kinda* close in my guess. I am learning more and more each day. I just wish I wasn't under the gun and had time to really learn rather than just rushing to get it to work...

... Learning under pressure is good for the synapses, methinks.  :-)
"How we think determines what we do, and what we do determines what we get."

stusic

  • Guest
Re: Using FOREACH with C:BURST
« Reply #8 on: June 20, 2013, 06:26:32 PM »
... Learning under pressure is good for the synapses, methinks.  :-)

Good for making burnt cookies ;)