Forum Groups
  All forums
    Help & Feedback
      Questions
      Work in progress
      Finished Art
      Non-Max related
    Community
      Offtopic
      News
    Hardware
    Photography



Maxunderground news unavailable

Maxscript Question: Create Turbosmooth modifier on selection
show user profile  IxenonI
Hey guys,

I don`t really know anything about maxscripting and was wondering if someone could help me out with writing the following script:

On your selected objects, check if there is a turbosmooth (TS) modifier applied. If so, do nothing on the objects that already have a TS modifier. On the ones with no TS modifier, do the following:

Create 2 TS modifiers on the selection. The first one with two iterations and separate by smoothing groups enabled, the second one with one iteration and separate by smoothing group disabled.

I already found a script that just applies the TS modifiers to your selection that works great. Here it is:

(
theObjects = geometry as array
for obj in theObjects do
(
addmodifier obj (TurboSmooth iterations:2 sepBySmGroups:true)
addmodifier obj (TurboSmooth iterations:1 sepBySmGroups:false)
)
)


The downside of this version is that it does not check if there are already any TS modifiers on the selection. If they already exist on the selection, it can crash max as it will increase the polycount to a very high level per object by adding additional TS modifiers, hence the need to check for TS modifiers before applying new ones on top.

Thank you very much for any help with this!
read 191 times
9/1/2016 4:04:48 AM (last edit: 9/1/2016 4:04:48 AM)
show user profile  ScotlandDave
Basically this:

theObjects = geometry as array
for obj in theObjects do
(
    hasTurbosmooth = false
    for mod in obj.modifiers do
    (
        if ((classOf modi == TurboSmooth) or (classOf modi == MeshSmooth)) then
        (
            hasTurbosmooth = true
        )
    )
    if not hasTurbosmooth then
    (
           addmodifier obj (TurboSmooth iterations:2 sepBySmGroups:true)
           addmodifier obj (TurboSmooth iterations:1 sepBySmGroups:false)
    )
)


Spoon - will we have code tags on the new forum?? Using nbsp's to create tabs, i'm sure there is another way but can't be bothered to search it..


Website | Blog | Contact | Vimeo

read 163 times
9/1/2016 10:41:52 AM (last edit: 9/1/2016 10:42:37 AM)
show user profile  IxenonI
Hey ScotlandDave,

Thank you for your help. I just tried your scripts and it adds turbosmooth modifiers but it does not seem to check if they are already existing on the object. It continues to add TS modifiers on top of the existing ones. On Max 2015 here...


read 151 times
9/1/2016 6:12:47 PM (last edit: 9/1/2016 6:12:47 PM)
show user profile  ScotlandDave
I didn't test sorry - change 'modi' to 'mod' and it should fix it.


Website | Blog | Contact | Vimeo

read 141 times
9/1/2016 7:26:33 PM (last edit: 9/1/2016 7:26:33 PM)
show user profile  Garp
for x in selection where x.modifiers[#turboSmooth] == undefined do . . .

;)




read 133 times
9/2/2016 12:28:44 AM (last edit: 9/2/2016 12:29:00 AM)
show user profile  ScotlandDave
^ more efficient way for sure :)

I just modded your original code.

[edit] Actually a nice method Garp, didn't know about .modifiers[#modifier] - nice one :)



Website | Blog | Contact | Vimeo

read 117 times
9/2/2016 9:53:29 AM (last edit: 9/2/2016 9:54:47 AM)
show user profile  Garp
Thinking twice, your code is better.
Indexing with the name works... until the modifier is renamed :\

I thought the indexing used the type's name. But no, it used the modifer's actual name.




read 110 times
9/2/2016 3:43:33 PM (last edit: 9/2/2016 3:43:33 PM)
show user profile  ScotlandDave
Ah, thought it was too good to be true :/


Website | Blog | Contact | Vimeo

read 108 times
9/2/2016 4:34:37 PM (last edit: 9/2/2016 4:34:37 PM)
show user profile  Garp
The fancy (and unreadable) one-liner version:

for x in objects where (findItem (for m in x.modifiers collect classOf m) turboSmooth) == 0 do...

Ha.




read 98 times
9/3/2016 5:26:46 AM (last edit: 9/3/2016 5:27:19 AM)
show user profile  ScotlandDave
Aha nice. Makes sense, if a bit less readable ( still much better though ) - i wonder how the execution times would stack up if you compared the readable method and the condensed method..


Website | Blog | Contact | Vimeo

read 85 times
9/3/2016 5:53:05 PM (last edit: 9/3/2016 5:53:41 PM)
#Maxforums IRC
Open chat window


Support Maxforums.org