Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Volume Select Gizmo

Volume Select Gizmo

Anonymous
Not applicable
383 Views
2 Replies
Message 1 of 3

Volume Select Gizmo

Anonymous
Not applicable
Hey...

Im tearing my hair out trying to figure this one out... I'm making a tool for quickly setting up muscles between two points, and the code is this;

macroscript muscleSetup
category:"Toke Scripts"
(
fn muscleBone type =
(
p1 = selection
p2 = selection

muscle = BoneSys.createBone p1.pos p2.pos

muscle.boneFreezeLength = off
muscle.boneScaleType = type

muscle.position.controller = Position_Constraint ()
muscle.position.controller.appendTarget p1 100
muscle.rotation.controller = Lookat_Constraint lookat_vector_length:0
muscle.rotation.controller.appendTarget p2 100

muscleNull = BoneSys.createBone

muscleNull.pos = p2.pos
muscleNull.parent = muscle

muscleNull.position.controller = position_constraint ()
muscleNull.position.controller.appendTarget p2 100
)
fn muscleCylinder type =
(
p1 = selection
p2 = selection

dist = (distance p1.pos p2.pos)

muscle = cylinder height:dist sides:8 heightsegs:5

muscle.pos = p1.pos
muscle.boneEnable = true

addmodifier muscle (xform())
muscle.modifiers.gizmo.rotation += quat 0 0.707107 0 0.707107

addmodifier muscle (volumeselect level:1 useAffectRegion:true falloff:(dist/2))
muscle.modifiers.gizmo.scale =
muscle.modifiers.gizmo.position =

--searching through scene for other muscles and instances modifier
flexMuscles = for i in geometry where i.boneEnable == true and classof (i.modifiers) == flex collect i

if flexMuscles.count > 0 then
(
tempMod = flexMuscles.modifiers
addmodifier muscle tempMod
)else
(
addmodifier muscle (flex flex:0.16 strength:4 sway:15)
)

muscle.boneFreezeLength = off
muscle.boneScaleType = type

muscle.position.controller = Position_Constraint ()
muscle.position.controller.appendTarget p1 100
muscle.rotation.controller = Lookat_Constraint lookat_vector_length:0
muscle.rotation.controller.appendTarget p2 100

muscleNull = BoneSys.createBone

muscleNull.pos = p2.pos
muscleNull.parent = muscle

muscleNull.position.controller = position_constraint ()
muscleNull.position.controller.appendTarget p2 100
)
rollout rollout_muscleSetup "Muscle Setup"
(
group "Step 1"
(
label lb1 "Select two points."
)
group "Step 2"
(
label lb2 "Choose type"
radiobuttons muscleType labels:#("scale","squash")
)
group "Step 3"
(
label lb3 "Choose muscle"
button cylinderBN "Cylinder w. Flex"
button boneBN "Bone"
)
on boneBN pressed do
(
if muscleType.state == 1 then
(
muscleBone #scale
)else
(
muscleBone #squash
)
)
on cylinderBN pressed do
(
if muscleType.state == 1 then
(
muscleCylinder #scale
)else
(
muscleCylinder #squash
)
)
)
createdialog rollout_muscleSetup style:#(#style_titlebar,#Style_toolwindow,#style_sysmenu)
)


The tool stops when trying to access the vol. select modifiers gizmo, and says "Unknown Property". When I copy the exact same code into the listener and execute it, I get the gizmo scaled down and repositioned as I want it.

Has anybody had similar problems or know of a solution?
0 Likes
384 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

addmodifier muscle (volumeselect level:1 useAffectRegion:true falloff:(dist/2))
completeRedraw() -- seems that volume select gizmo can only be accessed after it has been registered properly in the scene, so force a complete redraw
muscle.modifiers.gizmo.scale =
muscle.modifiers.gizmo.position =


It's not that elegant, almost feels like a bug, but it works.

-Johan
0 Likes
Message 3 of 3

Anonymous
Not applicable
Perfect! nevermind about the elegance:-) Here is the finished script:

macroscript muscleSetup
category:"Toke Scripts"
(
fn muscleBone type =
(
p1 = selection
p2 = selection

p1.name = (uniqueName "MuscleStart_")
p2.name = (uniqueName "MuscleEnd_")

muscle = BoneSys.createBone p1.pos p2.pos

muscle.boneFreezeLength = off
muscle.boneScaleType = type
muscle.name = (uniqueName "Muscle_")

muscle.position.controller = Position_Constraint ()
muscle.position.controller.appendTarget p1 100
muscle.rotation.controller = Lookat_Constraint lookat_vector_length:0
muscle.rotation.controller.appendTarget p2 100

muscleNull = BoneSys.createBone

muscleNull.pos = p2.pos
muscleNull.parent = muscle

muscleNull.position.controller = position_constraint ()
muscleNull.position.controller.appendTarget p2 100
)
fn muscleCylinder type =
(
p1 = selection
p2 = selection

p1.name = (uniqueName "MuscleStart_")
p2.name = (uniqueName "MuscleEnd_")

dist = (distance p1.pos p2.pos)

--searching through scene for other muscles and instances modifier
flexMuscles = for i in geometry where i.boneEnable == true and classof (i.modifiers) == flex collect i

muscle = cylinder height:1 sides:8 heightsegs:10 name:(uniqueName "Muscle_")

muscle.pos = p1.pos
muscle.boneEnable = true

muscle.position.controller = Position_Constraint ()
muscle.position.controller.appendTarget p1 100
muscle.rotation.controller = Lookat_Constraint lookat_vector_length:0
muscle.rotation.controller.appendTarget p2 100

addmodifier muscle (xform())
muscle.modifiers.gizmo.rotation += quat 0 0.707107 0 0.707107
muscle.modifiers.gizmo.scale +=

addmodifier muscle (ffdBox ())
setDimensions muscle.modifiers

addmodifier muscle (volumeselect level:1 useAffectRegion:true falloff:(dist/2))
completeRedraw()
muscle.modifiers.gizmo.scale =
muscle.modifiers.gizmo.position =

muscleNull = BoneSys.createBone

muscleNull.pos = p2.pos
muscleNull.parent = muscle

muscleNull.position.controller = position_constraint ()
muscleNull.position.controller.appendTarget p2 100

if flexMuscles.count > 0 then
(
tempMod = flexMuscles.modifiers
addmodifier muscle tempMod
muscle.baseobject = flexMuscles.baseobject
)else
(
addmodifier muscle (flex flex:0.2 strength:4 sway:10)
muscle.boneFreezeLength = off
muscle.boneScaleType = type
)
)
rollout rollout_muscleSetup "Muscle Setup"
(
group "Step 1"
(
label lb1 "Select two points."
)
group "Step 2"
(
label lb2 "Choose type"
radiobuttons muscleType labels:#("scale","squash")
)
group "Step 3"
(
label lb3 "Choose muscle"
button cylinderBN "Cylinder w. Flex"
button boneBN "Bone"
)
on boneBN pressed do
(
if muscleType.state == 1 then
(
muscleBone #scale
)else
(
muscleBone #squash
)
)
on cylinderBN pressed do
(
if muscleType.state == 1 then
(
muscleCylinder #scale
)else
(
muscleCylinder #squash
)
)
)
createdialog rollout_muscleSetup style:#(#style_titlebar,#Style_toolwindow,#style_sysmenu)
)
0 Likes