Notifications
Clear all

[Closed] Anyone knows this MAXScript bug?

Hi,

I encountered a highly strange bug in MAXScript. I know that it exists in 2012 and 2013, and I think it’s a very obvious one, so I hope any of you has encountered it and found a way around it …

Let me explain what happens:

  1. Create a box
  2. Open MAXScript listener and define the following simple function:
fn f = (
  	addModifier $ (Subdivide ())
  	$.modifiers[#Subdivide].size = 42)
  1. Select the box and go to Create mode or any mode other than Modify mode
  2. Enter into the MAXScript listener:
f ()
  1. Now your box has a Subdivide modifier, but astonishingly, it’s “size” setting is not 42 but instead some strange value! I’ve seen 0.145, 2.155, 8.3 etc. but never the correct value of 42.

A few funny things I found out so far:

  • When you go to Modify mode and then execute your function, it works!
  • When you execute the contents of the function line by line separately, it works!
  • When doing this as a part of a bigger script, it never works No matter if you switch to Modify mode before, do viewport redraws etc.

I simply can’t make it work!
Bug report is already filed, but who knows how long it’ll take them to fix it.

I hope that you guys found this bug as well, or a similar one, and know a way around it.

Here’s a screenshot:

34 Replies

Been there, done that. Long story short, you need to force an update of the object’s modifier stack for this to work (inserting something along the lines of classOf $ will do). Bobo explained this better before: Code not working inside function, otherwise OK

1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

it’s a good trick shown by Bobo, but the our case is different. And the trick doesn’t work for it.

Oh, wow, thank you!
I gave up hope completely and wrote the subdivision myself.
But for the next time, I know. I wonder: does Autodesk know about this? I think this should be considered a bug, especially when there is no “official” way to update the modifier stack.

fn f obj = 
(
	  addModifier obj  (Subdivide());
	obj.Subdivide.size = 42;
)

this works as expected

1 Reply
(@gazybara)
Joined: 1 year ago

Posts: 0

Why not use


fn f obj s: = (addModifier obj  (Subdivide size:s))
f obj s:42

i conform that the Subdivide modifier doesn’t work right on its creation:
the canonical form of the function is:


 fn applySubdivide obj size: = 
 (
 	modi = subdivide size:size
 	addmodifier obj modi
 	modi
 )
 /*
 applySubdivide $ size:42
 */
 

and… it’s not working. and it’s not working in any command mode.

so we have to do something to force the initialization of the modifier parameters (or paramblock). ideally we need the modifier work before applying it to the node.

after several different attempts i found only one way to do it:


 fn applySubdivide obj size: =
 (
 	modi = copy (subdivide size:size)
 	addmodifier obj modi
 	modi
 )
 

that means the Subdivide modifier CREATE AND ATTACHTONODE events are not working right. It’s a BUG. But the CLONE event works right.

I don’t think that it might be a general solution for any other modifiers. I think it’s just a sample of some specific bug of a specific modifier, and a work around.

it’s not working. the same as:


fn f obj = 
(
	addModifier obj  (Subdivide());
	obj.Subdivide.size = 42;
)

Function is basically similar except that it is necessary to allocate and return a copy of the modifier

1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

except that one works and another doesn’t …

?

works here.

2 Replies
(@denist)
Joined: 1 year ago

Posts: 0

 delete objects
 b = box()
 fn foo obj = 
 (
 	addModifier obj  (Subdivide());
 	obj.Subdivide.size = 42;
 )
 foo b
 

it’s not working for me in max 2010 and 2012

(@denist)
Joined: 1 year ago

Posts: 0

here is more detailed snippet to check:


 delete objects
 max create mode
 b = box isselected:on
 fn foo obj = 
 (
 	addModifier obj (Subdivide())
 	obj.Subdivide.size = 42
 )
 foo b
 max modify mode
 print b.Subdivide.size
 

unfortunately the clone of a modifier doubles the memory use. so it will be nice to find a wiser solution.

I know, but… Anyway, you’re always right. Thanks

Page 1 / 3