Notifications
Clear all

[Closed] Help with Script: GoToEdit/ablePoly

-Hi, I made this script to make 3ds max to go to the “edit poly modifier,” or “editable poly” if it doesn’t find an “edit poly modifier” on the stack.
-I get error “Unable to convert: undefined to type: max object” when there is no “edit poly modifier” on the stack. The line “modPanel.setCurrentObject $.modifiers[#Edit_Poly]” seems to be the culprit.
-If nothing can be done, is there a way to stop/press okay automatically the “MAXScript MAcroScript Error Exception” dialog when there’s an error?
Thank you!

Here’s the script:

macroScript GoToEditPoly_2
category:“My_Scripts”
internalCategory:“My_Scripts”
Tooltip:“GoToEditPoly_2”
ButtonText:“GoToEditPoly_2”

(
(
if (modPanel.getCurrentObject()) != undefined
then (modPanel.setCurrentObject $.baseObject))
(
if classof (modPanel.getCurrentObject()) == Editable_poly or (modPanel.getCurrentObject()) != undefined
then modPanel.setCurrentObject $.modifiers[#Edit_Poly] else modPanel.getCurrentObject())
)

14 Replies

I’m not sure the only problem is what you think it is but, to solve the missing of the edit_poly modifier you can just write:

if $.modifiers[#Edit_Poly] != undefined do modPanel.setCurrentObject $.modifiers[#Edit_Poly]

What would happen if a Edit_Poly modifier is applied but named differently?

i explained many times on this forum why writing a universal tool you have to avoid accessing to a modifier by name.

so node.modifiers[#edit_poly] and node.edit_poly are not a safe searching option

Thanks for the replies. I tried Andres’s code but nothing seems to happen. I am new to MaxScripting so I apologize Denis. I tried searching for a solution to what you mentioned (avoid accessing to a modifier by name) but I can’t find anything on how to solve that.
Cheers

I can’t clearly understand an idea of your macro. Let me guess…
Do you want to apply an Edit_Poly modifier to the current modifier panel object if the object is not an Editable Poly and doesn’t have an Edit Poly modifier in its stack?

how to check that a node has or not has an Edit Poly modifier in its stack?

fn doesNodeHaveModifier node class: = 
(
	local has = off
	if iskindof class Modifier do
	(
		for modi in node.modifiers while not has do has = iskindof modi class
	)
	has
)
/*
doesNodeHaveModifier <node> class:Edit_Poly
*/
 
2 Replies
(@swordslayer)
Joined: 11 months ago

Posts: 0

Since I know you like oneliners, 2013+:

fn doesNodeHaveModifier node class: = 
	node.modifiers[class] != undefined
 
(@denist)
Joined: 11 months ago

Posts: 0

this access method uses a name of modifier which can be different than class

It’s more likely ts wants to auto-select edit_poly mod if it’s in stack
modifier-auto-select

here is a modified version of finding modifier with Select option and stack order option:

fn findNodeModifier node class: first:off select:off = 
(
	local modi = undefined
	
	if first then 
		for k = node.modifiers.count to 1 by -1 while modi == undefined where iskindof (m = node.modifiers[k]) class do modi = m
	else
		for k = 1 to node.modifiers.count while modi == undefined where iskindof (m = node.modifiers[k]) class do modi = m

	if modi != undefined and select do 
	(
		if (getCommandPanelTaskMode() != #modify) do setCommandPanelTaskMode mode:#modify
		modpanel.setcurrentobject modi
	)
	modi
)


Thanks again guys, I really appreciate all the help. Sergey, that’s what I want, except that it doesn’t auto-select something else if I don’t have the modifier I tell it to choose in the first place.
In other words, if I have that script to auto-select edit poly modifier, but I don’t have an edit poly modifier, I wish it could auto-select the base object instead. The reason I want a script to do this is because many scripts don’t work with edit poly modifier, so I might create objects in the scene with either edit poly modifier, editable poly, or both. Being able to auto-select editable poly when there’s no edit poly, but select edit poly when there is edit poly will speed up the modeling process enormously. Denis, thanks for creating those scripts, I will archive it for when the time comes. Cheers

Nope, it uses class (note that I didn’t cast it to string or anything), it was added in max 2013 specifically to address the issues of different name vs class. Try it.

Page 1 / 2