[Closed] Setup body objects parameters while retaining the modifier stack
Hello everybody,
I am having a bit of an issue here. I have a bunch of body objects which have been edited by someone else. Some objects have additional modifiers on top of the modifier stack, e.g. a UVW map. What I need is to set for all of the body object their viewport display setting from whatever they are now to “fine”. After digging in the maxscript ref a bit i came up with the following code:
for sel in selection do
(
/*switch to the modify panel (apparently needed, as stated in the maxscript reference
"The Modify panel must be open, otherwise the function does nothing. " */
max modify mode
/*disable show end result - if an object has a modifier on top ob the body object it is then
interpereted as a mesh, so the body object parameters stated below wouldn't work */
enableShowEndRes off
modPanel.setCurrentObject $.baseObject
/* set the body object viewport setting to "fine" */
sel.LowQualityVDS = off
sel.MediumQualityVDS = off
sel.HighQualityVDS = on
sel.IsoAngleDS = 3
sel.IsoChordHeightVDS = 0
sel.FaceApproxAngleVDS = 10
sel.EdgeApproxAngleVDS = 0
sel.FaceChordHeightVDS = 0.02
sel.EdgeChordHeightVDS = 0
sel.MaxEdgeLengthPctVDS = 0
sel.LowQualityVDS = off
sel.MediumQualityVDS = off
sel.HighQualityVDS = on
sel.IsoAngleDS = 3
sel.IsoChordHeightVDS = 0
sel.FaceApproxAngleVDS = 10
sel.EdgeApproxAngleVDS = 0
sel.FaceChordHeightVDS = 0.02
sel.EdgeChordHeightVDS = 0
sel.MaxEdgeLengthPctVDS = 0
sel.HighQualityVDS = off
sel.LowQualityVDS = off
sel.MediumQualityVDS = off
sel.HighQualityVDS = on
sel.IsoAngleDS = 3
sel.IsoChordHeightVDS = 0
sel.FaceApproxAngleVDS = 10
sel.EdgeApproxAngleVDS = 0
sel.FaceChordHeightVDS = 0.02
sel.EdgeChordHeightVDS = 0
sel.MaxEdgeLengthPctVDS = 0
/*re-enable the stack on top ob body object*/
enableShowEndRes on
)
If I run the code on one single object it works fine, but after selecting all of them i get the error message:
-- Error occurred in sel loop; filename: ; position: 461; line: 10
-- Unknown property: "baseObject" in $selection
While debugging I found that it has something to do with data type conversion and this line:
modPanel.setCurrentObject $.baseObject
As I am still new to maxscript I would be thankful for any help .-) !
Cheers!
Gabriel
Change
modPanel.setCurrentObject $.baseObject
to
modPanel.setCurrentObject sel.baseObject
If you have more than one object selected, $ sort of works like selection as a set of objects. As selection.baseObject makes no sense, you get the error. Since you’re already stepping through the selection one object at a time (and that object is stored in the variable sel), it would make sense to use it the same way as you did in the code below, where you set the properties.
Hi Zhalktis and thanks a lot for the quick reply!
Yes now I see the error, bad me – absolutely clear to reuse the variable, and I wasn’t aware of the “$”-selection thing. The code doesn’t produce any errors now, unfortunately it still doesn’t work the way I want Since I can’t share the real CAD-Data, I’ve quickly setup some Body Objects in a CAD soft and imported them into Max, the basic idea / error is the same:
after running the code on multiple objects the for-loop stops at one of them (the first stored in the selection array) and doesn’t go any further The modifier stack is setup the same way as for the real CAD-data. I’ve attached the zip-file link with the scene below. Here is the corrected code:
for sel in selection do
(
/*switch to the modify panel (apparently needed, as stated in the maxscript reference
"The Modify panel must be open, otherwise the function does nothing. " */
max modify mode
/*disable show end result - if an object has a modifier on top ob the body object it is then
interpereted as a mesh, so the body object parameters stated below wouldn't work */
enableShowEndRes off
modPanel.setCurrentObject sel.baseObject
/* set the body object viewport setting to "fine" */
sel.LowQualityVDS = off
sel.MediumQualityVDS = off
sel.HighQualityVDS = on
sel.IsoAngleDS = 3
sel.IsoChordHeightVDS = 0
sel.FaceApproxAngleVDS = 10
sel.EdgeApproxAngleVDS = 0
sel.FaceChordHeightVDS = 0.02
sel.EdgeChordHeightVDS = 0
sel.MaxEdgeLengthPctVDS = 0
sel.LowQualityVDS = off
sel.MediumQualityVDS = off
sel.HighQualityVDS = on
sel.IsoAngleDS = 3
sel.IsoChordHeightVDS = 0
sel.FaceApproxAngleVDS = 10
sel.EdgeApproxAngleVDS = 0
sel.FaceChordHeightVDS = 0.02
sel.EdgeChordHeightVDS = 0
sel.MaxEdgeLengthPctVDS = 0
sel.HighQualityVDS = off
sel.LowQualityVDS = off
sel.MediumQualityVDS = off
sel.HighQualityVDS = on
sel.IsoAngleDS = 3
sel.IsoChordHeightVDS = 0
sel.FaceApproxAngleVDS = 10
sel.EdgeApproxAngleVDS = 0
sel.FaceChordHeightVDS = 0.02
sel.EdgeChordHeightVDS = 0
sel.MaxEdgeLengthPctVDS = 0
/*re-enable the stack on top ob body object*/
enableShowEndRes on
)
Thanks again for help!
Cheers,
Gabriel
i don’t have max around so let’s play blind:
try to select only one ‘body_object’ and check for example a LowQualityVDS property
$.LowQualityVDS
if it returns a value everything is very simple:
bodies = getclassinstances body_object
bodies.HighQualityVDS = on
bodies.IsoAngleDS = 3
bodies.IsoChordHeightVDS = 0
-- ... and so on
if the system says something “this is no property LowQualityVDS …” we can go another way…
bodies = for node in geometry where iskindof node.baseobject body_object collect node.baseobject
-- next is the same
bodies.HighQualityVDS = on
bodies.IsoAngleDS = 3
bodies.IsoChordHeightVDS = 0
-- ... and so on
that means we don’t need select then, and do setup in modifier panel. which is much faster, cleaner, no-flicker, and finally == pro
Hi denisT,
thanks for your suggestion, will try it tomorrow morning asap in the office
EDIT: denisT it’s ingenious, thanks again a lot, the last part did the trick Here is the final code working like a charm:
bodies = for node in geometry where iskindof node.baseobject body_object collect node.baseobject
bodies.HighQualityVDS = on
bodies.IsoAngleDS = 3
bodies.IsoChordHeightVDS = 0
bodies.LowQualityVDS = off
bodies.MediumQualityVDS = off
bodies.HighQualityVDS = on
bodies.IsoAngleDS = 3
bodies.IsoChordHeightVDS = 0
bodies.FaceApproxAngleVDS = 10
bodies.EdgeApproxAngleVDS = 0
bodies.FaceChordHeightVDS = 0.02
bodies.EdgeChordHeightVDS = 0
bodies.MaxEdgeLengthPctVDS = 0
bodies.LowQualityVDS = off
bodies.MediumQualityVDS = off
bodies.HighQualityVDS = on
bodies.IsoAngleDS = 3
bodies.IsoChordHeightVDS = 0
bodies.FaceApproxAngleVDS = 10
bodies.EdgeApproxAngleVDS = 0
bodies.FaceChordHeightVDS = 0.02
bodies.EdgeChordHeightVDS = 0
bodies.MaxEdgeLengthPctVDS = 0
bodies.HighQualityVDS = off
bodies.LowQualityVDS = off
bodies.MediumQualityVDS = off
bodies.HighQualityVDS = on
bodies.IsoAngleDS = 3
bodies.IsoChordHeightVDS = 0
bodies.FaceApproxAngleVDS = 10
bodies.EdgeApproxAngleVDS = 0
bodies.FaceChordHeightVDS = 0.02
bodies.EdgeChordHeightVDS = 0
bodies.MaxEdgeLengthPctVDS = 0
Probably due to a lot of checking or value editing it runs a bit slow, but i just checked with my primitives scene, and it’s exactly what I need. I have setup my office pc remotely a minute ago to run down the script for the whole CAD data set (around 6000 individual body parts), tomorrow morning I’ll see hopefully the result (fingers crossed)
If i have time I will pack it up in a little GUI and post it at scriptspot for all the people out there, all credits go to you
Thanks a lot again!
Regards,
Gabriel
bodies.HighQualityVDS = on
bodies.IsoAngleDS = 3
bodies.IsoChordHeightVDS = 0
bodies.LowQualityVDS = off
...
let’s go a pro way:
bodyDefData =
#(
#(#HighQualityVDS, on),
#(#IsoAngleDS , 3),
#(#IsoChordHeightVDS, 0)
-- add next prop-to-value
)
for prop in bodyDefData do setproperty bodies prop[1] prop[2]
the code was written blind… sorry if i couldn’t make it works right. just get an idea
it’s funny but i’ve never checked that ‘setproperty’ is mapped.
if it’s not the code has to be modified:
for body in bodies do for prop in ... do setproperty body prop[1] prop[2]
denisT thanks a lot for the latest suggestions, the first code did the job over night, everything worked as it should! Still i will try out your suggestion and see what i will come up with. Thanks a lot again for help :)!