Hello I'm beginner in MaxScript and I writed a little script to automatically apply an auto-smooth on only one selected object.
But I would like to make it working on a selection of several objects.
Maybe it's also possible to improve the syntax because I'm not sure is the best way to write this script.
Thanks for your help !
(
bob=selection
sel=bob as array
if sel.count !=1 then
(
messageBox "select only one object"
)
else
(
if classof $.modifiers[1] != Edit_Poly then
(
modPanel.addModToSelection (smooth autosmooth:true threshold: 10) ui:on
)
else
(
numFaces = polyop.getNumfaces $
subobjectLevel = 4
$.modifiers[#Edit_Poly].autoSmoothThreshold = 10
$.modifiers[#Edit_Poly].SetSelection #Face #{1..numFaces}
$.modifiers[#Edit_Poly].ButtonOp #Autosmooth
$.modifiers[#Edit_Poly].SetSelection #Face #{}
subobjectLevel = 0
)
)
)
By
Comments (9)
Comment policy
Thanks
Hello
Thanks for your replies !
Your tips and examples help me a lot to better understand how to script.
I will re-write my script based on your advices.
Cheers!
some tips from me
We cannot supply all the good tips just with few words, but here is and some from me.
modPanel methods required Modify panel to be active!
Using Modify panel is slow, so when you have alternative just use it instead. For adding modifier you can use
function (without need to switch to mod-panel).
There also an useful function
that verify if you can apply concrete modifier class to your object.
And here is how I imagine your task...
Cheers!
Hi Anubis,I always try to
Hi Anubis,
I always try to learn from the best, but is difficult to explain some stuff using Google Translate :) like me.
My solution is not for learning example because is to short.
I try to explaine just some basic rules for optimizatons.
:)
I think that Henrard ask for tips as he say: "also possible to improve the syntax".
Anyway, as I have a bad habit to trust to my memory and post untested code, I presume that I made a syntax typo in my example code. I used:
but the correct might was:
, rigth?
:)
Yep. I post the code 75% never tested, some works and some not.
But it would be pointless if we just post the correct codes.
Then we would not have something to talk about.
:)
indeed :)
Meanwhile, as I copy/paste some line of code from your example, now I see that you use "o" variable, while I use "obj" and need to edit my example code :) but EDIT option here available only for my last post :( so I attach edited code on this post.
Attachments
If you have a time i'm posting new thread about Resize Modifier (XForm+CustAttributes).I need some advice about xform transform and center (modifier) position
one tip for you:
Look in the MaxScript help to find out more about meshOp and polyOp operations.
Theses are interface functions and try to store them in some variable before you put them inside for-loop. It is much fester.
Also try to switch from modify to create panel when use theses types
of operations using this line:
Using "undo off (...)" and "with redraw off (...)" you can speed-up the things a lot.
;)Aniway . . . you deside what you need
try this one
I write a simple function
fn autoSmooth tresh: = if selection.count == 0 then (messageBox "Select Some Objects!" title:"Warning" beep:off) else
(
local poAS = polyop.setFaceSmoothGroup
local moAS = meshop.autosmooth
for o in selection where isKindOf o GeometryClass and not isKindOf o Targetobject do
(
if o.modifiers.count != 0 then addModifier o (smooth autosmooth:true threshold:tresh) else
(
case classof o of (
(Editable_Poly): (poAS o o.faces tresh add:false)
(Editable_Mesh): (moAS o o.faces tresh ; update o)
)
)
)
)
autoSmooth tresh:45