Add and delete modifier

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:-)

AttachmentSize
maxscriptproblem.jpg234.81 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

...

First of all on this forum you can find many tool that can use as reference.
I wrote one of this http://www.scriptspot.com/3ds-max/scripts/delete-modifiers

But if you looking more efficient methods see this thread:

http://forums.cgsociety.org/showthread.php?f=98&t=1138877&highlight=dele...

barigazy

Raffx's picture

Thanks a lot barigazy! I

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

AttachmentSize
maxscriptproblem2.jpg 200.2 KB
miauu's picture
barigazy's picture

...

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

barigazy

Raffx's picture

Thanks again! The script is

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

AttachmentSize
fxoptimizer_geometry.ms 1.66 KB
miauu's picture

.

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

barigazy's picture

...

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

barigazy

barigazy's picture

...

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)

barigazy

Raffx's picture

Thank's, all work!! I'm

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!!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.