I have exported a tree with a bunch of leaf cutouts from ThePlantFactory (which is free now!), and I want to reduce the bones to the lowest possible number. So I've deleted all the cutouts except for 1, which I now want to clone and rotate many times around the tree.
MaxScript seems the best way to do this, but the documentation is poorly written. It's clearly made by someone that already knows MaxScript, for people who already know MaxScript. What with the strange parameter names, single letter variable names, and examples that don't clearly explain each part of the command and arguments without jargon.
Here's what I've got so far, the clone command being the most confusing one that I can't figure out.
iVerticalLoops = 6
iCountMin = 8
iCountMax = 14
iAngleMin = 20
iAngleMax = 35
fScaleMultMin = 0.85
fScaleMultMax = 1.00
fHeightOffsetMultMin = 0.8
fHeightOffsetMultMax = 1.2
iHeightMin = 122.0
iHeightMax = 378.0
iHeightRange = iHeightMax - iHeightMin
iHeightIncrement = iHeightRange / iVerticalLoops
objSource = $Silverpine01_CutoutOrig
select objSource
--We'll create this many "rings" of cutouts around the tree
for iLoopCounter = 1 to iVerticalLoops do
(
--Number of cutouts to clone for this ring
iNumClones = (random iCountMin iCountMax)
--Clone the cutout, adjusting position and rotation for each one
for iCloneCounter = 1 to iNumClones do
(
fOffsetMult = (random fHeightOffsetMultMin fHeightOffsetMultMax)
iOffsetAngle = (random iAngleMin iAngleMax)
-- todo: Clone the cutout
-- todo: Add iHeightIncrement to Z pos
-- todo: Multiply new Z pos by fOffsetMult
-- Add iOffsetAngle to Z rot
--maxOps.CloneNodes objSource
)
)
I have basic experience with Lua, C#, and Pascal. Pascal in particular has good documentation most of the time, so I'm most familiar with it. But MaxScript's docs are scattered and not great in comparison.
Thanks for any insight!
Solved! Go to Solution.
Solved by domo.spaji. Go to Solution.
I'd get familiar with:
https://help.autodesk.com/view/MAXDEV/2025/ENU/?guid=GUID-C17D0E4B-C408-426B-B300-7E23A0D98515
https://help.autodesk.com/view/MAXDEV/2025/ENU/?guid=GUID-3B001F21-8FE9-4663-A972-E648682A0ACD
and I am not commenting your loop iterator variable..
Yeah a lot of pro coders hate my variables but it helps me keep track of things. I also needed to vent a little when I made the OP, that's my bad.
Here's the code I came up with. And I think I know what the issue is: The skinned leaf cutout has its pivot in a weird place, and the node.position & node.rotation values use a different scale from the xyz gizmo in the viewport. So not sure how to solve that.
iVerticalLoops = 3
iCountMin = 8
iCountMax = 14
iAngleMin = 30
iAngleMax = 55
fScaleMultMin = 0.85
fScaleMultMax = 1.00
fHeightOffsetMultMin = 0.98
fHeightOffsetMultMax = 1.02
iHeightMin = 122.0
iHeightMax = 378.0
iHeightRange = iHeightMax - iHeightMin
iHeightIncrement = iHeightRange / iVerticalLoops
objSource = $Silverpine01_CutoutOrig
select objSource
--We'll create this many "rings" of cutouts around the tree
for iLoopCounter = 1 to iVerticalLoops do
(
--Number of cutouts to clone for this ring
iNumClones = (random iCountMin iCountMax)
iOffsetAngle = 0
--Clone the cutout, adjusting position and rotation for each one
for iCloneCounter = 1 to iNumClones do
(
fOffsetMult = (random fHeightOffsetMultMin fHeightOffsetMultMax)
iOffsetAngle = (iOffsetAngle + (random iAngleMin iAngleMax))
-- todo: Clone the cutout
-- todo: Add iHeightIncrement to Z pos
-- todo: Multiply new Z pos by fOffsetMult
-- Add iOffsetAngle to Z rot
maxOps.CloneNodes objSource cloneType:#instance newNodes:&nodeCreated
fPosZ = ( (iHeightIncrement * iLoopCounter) * fOffsetMult)
nodeCreated.position = [0.0,(0.2 * iLoopCounter),fPosZ]
nodeCreated.rotation = (eulerAngles 0 0 (mod iOffsetAngle 360))
)
)
Why don't you post a demo scene? I have no idea, why simple cloning gets complicated. I would use ".transform" instead of ".position" and ".rotation" and I'm sure an "inverse()" somewhere might be useful..
Sorry for the late reply, been very busy!
I provided the example project above, but that is an older version to be fair. I've now updated the project a bit and taken two screenshots. Also attached the script.
I think something is off with moving skinned objects. They all shift way up when I go to the next keyframe, and when I slide it back, they don't go back down. Very weird!
Here are the project files in 2024 format. And yes, there is animation. I did mention bones, but forgot to explicitly say: ThePlantFactory exports rigged tree models with a seamless wind animation. If you're curious, you can download it here: https://www.bentley.com/software/e-on-software-free-downloads/
@FiftyTifty wrote:
I think something is off with moving skinned objects. They all shift way up when I go to the next keyframe, and when I slide it back, they don't go back down. Very weird!
That is how it should be.
You could transform skined obj. on subobject level (Xform mod. after skin mod. for pos. rot, scale)
or
create Mesher compound obj. with your skinned mesh as a "target" and multiply/scatter it.
or
use some built in complete solution
like Scatter compound obj. or array mod. in newer Max versions
Those are awesome ideas! I tried using array, but it gets disabled when exporting the model as fbx since the array modifier is above the skin:
There's also the issue of merging these skinned objects back into 1. I'll make a new topic for this though, as we've moved away from the scripting side. Thanks for all the help!
Edit: Aha, I figured it out!
1. Right-click on the skin modifier -> Copy
2. Add an array modifier, set to radial and adjust the angles as you like
3. Right-click on the modifier list -> Collapse all
4. Right-click on the Editable Mesh entry (only one left in the modifier list) -> paste
Done!
Can't find what you're looking for? Ask the community or share your knowledge.