[Closed] Unknown system exception on simple delete script
Hi!
I am looping through scene objects and deleting Splines. It evaluates OK if it’s outside my rollout but does not work when inside the rollout.
macroScript PolyFormCADOptimizer category:"PolyFormTools"
(
--if ThePolyOptimizer.isdisplayed then (DestroyDialog ThePolyOptimizer)
Rollout ThePolyOptimizer "CAD Optimizer"
(
checkbox chk_DeleteSpline "Delete Spline"
button BTN_Optimize "Go"
button BTN_Reset "Reset"
on BTN_Optimize pressed do
(
if (chk_DeleteSpline.state) then
(
for o in objects where classOf o == SplineShape do ( delete o )
)
)
)
)
This throws the exception
This evaluates OK
for o in objects where classOf o == SplineShape do ( delete o )
Is this a bug?
Thanks!
edit: It deletes the first instance but then throws an error.
for o in (objects as array) where classOf o == SplineShape do ( delete o )
has to work
There is a bug in 2012 related to variables created in loops. I haven’t seen this one before.
Try defining “o” outside of the loop first to initialize it.
Also maybe it’s crashing since it is breaking the index on delete. What if you took out the “as array”?
EDIT: that being said… if I just run that line of code on some splineshapes I get no error.
i would do it this way:
delete ( for o in shapes where classof o == SplineShape collect o)
Thanks all. DenisT’s solution works.
@thatoneguy, the single line evaluates for me as well, just doesn’t work inside the rollout.
@denisT, what did adding th as array do that my original code did not?
Thanks!
catch the point… objects is kind of a live structure. when you use it in loop and change it at the same time by deleting its members what do you expect to get?
I get that and it makes sense. I just don’t get why it would work as a stand alone and not work when executed from a form.