i prefer this snippet
delete objects
max modify mode
b = box isselected:on
fn foo obj =
(
addModifier obj (Subdivide())
obj.Subdivide.size = 42
)
foo b
print b.Subdivide.size
but it’s not a point. you can’t do massive modifier attaching with modifier panel open.
the snippet above works just because modpanel forces the modifier update. it’s easy to see when we change the order of lines:
delete objects
max modify mode
b = box isselected:on
fn foo obj =
(
modi = Subdivide()
modi.size = 42
addModifier obj modi
)
foo b
print b.Subdivide.size
also you have to understand that when you apply the modifier with default size value the system subdivides the node first time, and when you change the size the system subdivides the node second time. That’s why it’s preferable to set all modifier’s setting before applying the modifier.
what about this ? probably answers the “random” size values the OP’s subdivide generates
fn scaleObj obj scle = scale obj [scle,scle,scle];
fn maxdim obj =
(
bounds = obj.max - obj.min;
mdim = bounds.x;
if bounds.y > mdim then mdim = bounds.y;
if bounds.z > mdim then mdim = bounds.z;
mdim;
)
fn foo obj val =
(
mdim = maxdim obj;
scle = val/mdim * 10.0;
scaleObj obj scle;
modi = Subdivide();
addModifier obj modi;
scle;
)
delete objects;
max create mode;
b = box();
scle = foo b 13;
scaleObj b (1/scle);
max modify mode;
print b.Subdivide.size
fn foo2 obj val =
(
bxsize = val * 10;
tempbox = box length:bxsize width:bxsize height:bxsize;
modi = Subdivide();
addModifier tempbox modi;
addModifier obj modi;
delete tempbox
)
delete objects;
max create mode;
b = box();
foo2 b 13;
max modify mode;
print b.Subdivide.size
is it random? on my machine the default size is always 2.5.
that’s the default size of a box the subdivide seems to calculate it’s initial setting based on 1/10th the max dimension of the obj.
good catch! if so it might be better to use getModContextBBoxMin and getModContextBBoxMax
delete objects
b = box()
fn foo obj =
(
addModifier obj (Subdivide());
[B] numPoints obj[/B]
obj.Subdivide.size = 42;
)
foo b
Cool. Did you try all possibly working functions before find the right one?
But…
my solution works 7 times faster:
fn foo obj =
(
addModifier obj (copy (Subdivide size:42))
)
can you guess why?
Acutally, no
I was looking for something that will trigger an invalidation of the object cache.
Probably because cloning a ParamBlock is cheaper than invalidating an object cache? :shrug: