ScriptSpot

Forum topic · General Scripting

Add and delete modifier

By Raffx · 2014-07-09

Downloads
Description

Hi,

I'm trying to make my first script. The script is very simple, some buttons to do repetitive operations, no complicated things.
I have some problem with addModifier and deleteModifier methods.

This is my code's piece:

on btn5_Delete pressed do
(
deleteModifier btn_pickObj.object ProOptimizer
messagebox "Modifier Deleted" title: "High Poly"
)

when I press my button I receive this error:

Unable to convert:ProOptimizer to type:Modifier

I have read the maxscript help guide where deletemodifier and addmodifier method are explained:

deleteModifier -- mapped

I tried to use index instead of modifier and it works!! but I want specify only my ProOptimizer modifier.

Where is the error? I'm going crazy.
I'm a maxscript's newbie so thank for patience:-)

Comments (9)

Raffx · 2014-07-10

Thanks a lot barigazy! I solved partially the problem, with addModifier there is no problem, all is ok! but with deleteModifier I have still errors!!

Thanks for patience

Attachments

barigazy · 2014-07-10

Post you code here and I will try to solve your problem.

Raffx · 2014-07-11

Thanks again!

The script is very simple:

-pick geometry
-apply and analyze the object with proOptimizer
-and delete the modifier

all buttons are based on pickbutton object so if there isn't any object it return some errors.I'll fixed later this problems.

For now I want solve the delete problem

this is my code

Attachments

.

miauu · 2014-07-11

Branko will solve your problem, but did you read my pverious post?

barigazy · 2014-07-11

Hey friend. :) How are you?
I already post link for the tool. Anyway I will post solution later.

barigazy · 2014-07-11

I don't have time to test this

try(destroydialog :: FxOptimizer) catch()

rollout FxOptimizer "FX Optimizer"
(
--Geometry Optimizations
local po_obj, msg = ""
fn getProOpt node =
(
if not isValidNode node do return undefined
(getClassInstances ProOptimizer target:node)[1]
)
fn filterGeo node = isKindOf node GeometryClass and canConvertTo node Editable_mesh
GroupBox grp2_Geometry "Geometry Optimization:" pos:[5,5] width:185 height:145

button btn1_createMod "Apply Optimizer" pos:[10,25] width:85 height:30
button btn2_AnalyzeMod "Analyze" pos:[100,25] width:85 height:30

button btn3_LowPoly "Low Poly" pos:[10,60] width:85 height:30
button btn4_HiPoly "Hi-Poly" pos:[100,60] width:85 height:30

spinner spn1_Low "" pos:[10,95] width:86 height:16 range:[0,80,25]
spinner spn2_High "" pos:[100,95] width:86 height:16 range:[80,100,100]

pickbutton btn_pickObj "Pick Geometry" pos:[10,115] width:85 height:30 autoDisplay:true filter:filterGeo
button btn5_Delete "Delete" pos:[100,115] width:85 height:30

--Actions

on btn1_createMod pressed do
(
if selection.count == 0 then messagebox "Select Some Object" title:"Modifier" beep:off else
(
deselect (for o in selection where not canConvertTo o Editable_mesh collect o)
modPanel.addModToSelection (ProOptimizer name:"FX Optimizer") ui:on
messagebox "Modifier Applied" title:"Modifier" beep:off
)
)
on btn2_AnalyzeMod pressed do
(
if (mody = getProOpt po_obj) != undefined then (mody.calculate = on ; msg = "analyze complete") else msg = "analyze uncomplete"
messagebox msg title: "analyze" beep:off
)
on btn3_LowPoly pressed do (if (mody = getProOpt po_obj) != undefined do mody.VertexPercent = spn1_Low.value)
on btn4_HiPoly pressed do ((if (mody = getProOpt po_obj) != undefined do mody.VertexPercent = spn2_High.value))
on btn5_Delete pressed do
(
if (mody = getProOpt po_obj) == undefined then msg = "Modifier Not Exists" else
(
number = modPanel.getModifierIndex po_obj mody
deleteModifier btn_pickObj.object number
msg = "Modifier Deleted"
)
messagebox msg title:"High Poly" beep:off
)
on btn_pickObj picked obj do (if isValidNode (po_obj = obj) do select obj)
)
CreateDialog FxOptimizer 195 155 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

Raffx · 2014-07-14

Thank's, all work!! I'm analyzing your script since 3 days and some things are clear and others unclear.

What really I don't understand and what I'm doing wrong with deleteModifier method??

and why your script works with deleteModifier?

Sorry I'm a pain in the ass but this driving me crazy!!