PDA

View Full Version : Unknown system exception on simple delete script


em3
07-07-2011, 10:41 PM
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.

denisT
07-07-2011, 11:29 PM
for o in (objects as array) where classOf o == SplineShape do ( delete o )

has to work

thatoneguy
07-07-2011, 11:40 PM
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. :|

Gravey
07-08-2011, 02:51 AM
i would do it this way:delete ( for o in shapes where classof o == SplineShape collect o)

em3
07-08-2011, 05:03 AM
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!

denisT
07-08-2011, 06:02 AM
DenisT's solution works...


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?

em3
07-09-2011, 05:53 AM
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. :)

CGTalk Moderation
07-09-2011, 05:53 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.