PDA

View Full Version : include file issues...


ElectricBones
01-27-2009, 06:00 PM
Hi guys I'm fairly new to this maxscript lark but i understand it fairly well now...
I am currently creating a rig element creator. Click a button it makes a leg etc...

Well for my spine system, because it is so large, I have it all in a seperate file. The script itself works fine when I evaluate it, everything is perfect. But when it is called through the other script, the control helpers for one of my IK splines are all sitting on the [0,0,0] point.
It is ahrd to explain and I'd like to post the code up so you can see test it out and see what i mena but it is quite a large script now.. I think there must be a more efficient way of doing it but right now this is my main concern.

I haven't had this problem before and it doesn't cough up any errors. I have also tried it in another small script purely containing a button that sates [on pressed do include "myfile"]

has anyone come across this problem before? and can I give you any more specific information to help you help me?

ElectricBones
01-28-2009, 01:31 PM
Here is the script:

-------------------------------------------------------------------------------------------------------
--START Bone Creation Section with parenting
-------------------------------------------------------------------------------------------------------

hipBone = BoneSys.createBone [0,125,160] [0,62.5,160] [-90,0,0]
hipBone.name = "Hips"
hipBone.width = 4.0
hipBone.height = 4.0
hipBone.taper = 45
hipBone.sidefins = false
hipBone.frontfin = true

hipBoneNub = BoneSys.createBone [0,62.5,160] [0,58.5,160] [-90,0,0]
hipBoneNub.name = "Hips_Nub"
hipBoneNub.width = 4.0
hipBoneNub.height = 4.0
hipBoneNub.taper = 45
hipBoneNub.sidefins = false
hipBoneNub.frontfin = false

spineBone1 = BoneSys.createBone [0,62.5,160] [0,0,160] [-90,0,0]
spineBone1.name = "Spine01"
spineBone1.width = 4.0
spineBone1.height = 4.0
spineBone1.taper = 45
spineBone1.sidefins = false
spineBone1.frontfin = true

spineBone1Nub = BoneSys.createBone [0,0,160] [0,-4,160] [-90,0,0]
spineBone1Nub.name = "Spine01_Nub"
spineBone1Nub.width = 4.0
spineBone1Nub.height = 4.0
spineBone1Nub.taper = 45
spineBone1Nub.sidefins = false
spineBone1Nub.frontfin = false

spineBone2 = BoneSys.createBone [0,0,160] [0,-62.5,160] [-90,0,0]
spineBone2.name = "Spine02"
spineBone2.width = 4.0
spineBone2.height = 4.0
spineBone2.taper = 45
spineBone2.sidefins = false
spineBone2.frontfin = true

spineBone2Nub = BoneSys.createBone [0,-62.5,160] [0,-66.5,160] [-90,0,0]
spineBone2Nub.name = "Spine02_Nub"
spineBone2Nub.width = 4.0
spineBone2Nub.height = 4.0
spineBone2Nub.taper = 45
spineBone2Nub.sidefins = false
spineBone2Nub.frontfin = false

spineBone3 = BoneSys.createBone [0,-62.5,160] [0,-125,160] [-90,0,0]
spineBone3.name = "Spine03"
spineBone3.width = 4.0
spineBone3.height = 4.0
spineBone3.taper = 45
spineBone3.sidefins = false
spineBone3.frontfin = true

spineBone3Nub = BoneSys.createBone [0,-125,160] [0,-129,160] [-90,0,0]
spineBone3Nub.name = "Spine03_Nub"
spineBone3Nub.width = 4.0
spineBone3Nub.height = 4.0
spineBone3Nub.taper = 45
spineBone3Nub.sidefins = false
spineBone3Nub.frontfin = false

hipBoneNub.parent = hipBone
spineBone1Nub.parent = spineBone1
spineBone2Nub.parent = spineBone2
spineBone3Nub.parent = spineBone3

-------------------------------------------------------------------------------------------------------
--END Bone Creation Section with parenting
-------------------------------------------------------------------------------------------------------
--START Spline drawing and Helper creation Functions and Point Helper naming.
-------------------------------------------------------------------------------------------------------

function drawLine pointA pointB pointC pointD =

(

ss = SplineShape pos:pointA

addNewSpline ss

addKnot ss 1 #smooth #curve PointA
addKnot ss 1 #smooth #curve PointB
addknot ss 1 #smooth #curve PointC
addknot ss 1 #smooth #curve PointD

updateShape ss

ss

)

ikSpline = drawLine [0,125,160] [0,40,160] [0,-40,160] [0,-125,160]
ikSpline.name = "IK_Spline"
addmodifier ikSpline (Spline_IK_Control())
ikSpline.Spline_IK_Control.createhelper 4
ikSpline.Spline_IK_Control.linkTypes = 2
arrayIKSpline = ikSpline.Spline_IK_Control.helper_list

ikNodeSpline = drawLine [0,125,200] [0,40,200] [0,-40,200] [0,-125,200]
ikNodeSpline.name = "Upnode_Spline"
addmodifier ikNodeSpline (Spline_IK_Control())
ikNodeSpline.Spline_IK_Control.createhelper 4
ikNodeSpline.Spline_IK_Control.linkTypes = 2
arrayIKNodeSpline = ikNodeSpline.Spline_IK_Control.helper_list

function createHelpers position =

(
ch1 = circle radius: 15 pos: position
ch2 = circle radius: 15 pos: position
ch2.rotation.x_rotation = 90
ch3 = circle radius: 15 pos: position
ch3.rotation.x_rotation = 90
ch3.rotation.z_rotation = 90

convertToSplineShape ch1
convertToSplineShape ch2
convertToSplineShape ch3

addAndweld ch1 ch2 0.0
addAndweld ch1 ch3 0.0

updateshape ch1

ch1
)

ctrlSpine1 = createHelpers [0,125,240]
ctrlSpine1.name = "Ctrl_Spine1"
ctrlSpine2 = createHelpers [0,40,240]
ctrlSpine2.name = "Ctrl_Spine2"
ctrlSpine3 = createHelpers [0,-40,240]
ctrlSpine3.name = "Ctrl_Spine3"
ctrlSpine4 = createHelpers [0,-125,240]
ctrlSpine4.name = "Ctrl_Spine4"

BonePos1 = point name: "node_Bone_Pos1" size: 10
Bonepos2 = point name: "node_Bone_Pos2" size: 10
BonePos3 = point name: "node_Bone_Pos3" size: 10
BonePos4 = point name: "node_Bone_Pos4" size: 10
BonePos5 = point name: "node_Bone_Pos5" size: 10

arrayIKSpline[1].name = "IK_Spline_Vertex1"
arrayIKSpline[2].name = "IK_Spline_Vertex2"
arrayIKSpline[3].name = "IK_Spline_Vertex3"
arrayIKSpline[4].name = "IK_Spline_Vertex4"
arrayIKNodeSpline[1].name = "Upnode_Spline_Vertex1"
arrayIKNodeSpline[1].parent = arrayIKSpline[1]
arrayIKNodeSpline[2].name = "Upnode_Spline_Vertex2"
arrayIKNodeSpline[2].parent = arrayIKSpline[2]
arrayIKNodeSpline[3].name = "Upnode_Spline_Vertex3"
arrayIKNodeSpline[3].parent = arrayIKSpline[3]
arrayIKNodeSpline[4].name = "Upnode_Spline_Vertex4"
arrayIKNodeSpline[4].parent = arrayIKSpline[4]

-------------------------------------------------------------------------------------------------------
--END Spline drawing and Helper creation Functions
-------------------------------------------------------------------------------------------------------
--START Position and Orientation Constraints for Spline Knots
-------------------------------------------------------------------------------------------------------

pc = Position_Constraint()
arrayIKSpline[1].pos.controller = pc
positionConstraintInterface = pc.constraints
positionConstraintInterface.appendtarget ctrlSpine1 100
arrayIKSpline[1].pos.controller.relative = true
oc = Orientation_Constraint()
arrayIKSpline[1].rotation.controller = oc
rotationConstraintInterface = oc.constraints
rotationConstraintInterface.appendtarget ctrlSpine1 100

pc = Position_Constraint()
arrayIKSpline[2].pos.controller = pc
positionConstraintInterface = pc.constraints
positionConstraintInterface.appendtarget ctrlSpine2 100
arrayIKSpline[2].pos.controller.relative = true
oc = Orientation_Constraint()
arrayIKSpline[2].rotation.controller = oc
rotationConstraintInterface = oc.constraints
rotationConstraintInterface.appendtarget ctrlSpine2 100

pc = Position_Constraint()
arrayIKSpline[3].pos.controller = pc
positionConstraintInterface = pc.constraints
positionConstraintInterface.appendtarget ctrlSpine3 100
arrayIKSpline[3].pos.controller.relative = true
oc = Orientation_Constraint()
arrayIKSpline[3].rotation.controller = oc
rotationConstraintInterface = oc.constraints
rotationConstraintInterface.appendtarget ctrlSpine3 100

pc = Position_Constraint()
arrayIKSpline[4].pos.controller = pc
positionConstraintInterface = pc.constraints
positionConstraintInterface.appendtarget ctrlSpine4 100
arrayIKSpline[4].pos.controller.relative = true
oc = Orientation_Constraint()
arrayIKSpline[4].rotation.controller = oc
rotationConstraintInterface = oc.constraints
rotationConstraintInterface.appendtarget ctrlSpine4 100

-------------------------------------------------------------------------------------------------------
--END Position Constraints for Spline Knots
-------------------------------------------------------------------------------------------------------
--START Path Constraints for Bone position Points
-------------------------------------------------------------------------------------------------------

pathc = Path_Constraint()
BonePos1.pos.controller = pathc
pathc.path = ikSpline
pathc.percent = 0

pathc = Path_Constraint()
BonePos2.pos.controller = pathc
pathc.path = ikSpline
pathc.percent = 25

pathc = Path_Constraint()
BonePos3.pos.controller = pathc
pathc.path = ikSpline
pathc.percent = 50

pathc = Path_Constraint()
BonePos4.pos.controller = pathc
pathc.path = ikSpline
pathc.percent = 75

pathc = Path_Constraint()
BonePos5.pos.controller = pathc
pathc.path = ikSpline
pathc.percent = 100

deletekeys BonePos1
deletekeys BonePos2
deletekeys BonePos3
deletekeys BonePos4
deletekeys BonePos5

-------------------------------------------------------------------------------------------------------
--END Path Constraints for Bone position Points
-------------------------------------------------------------------------------------------------------
--START Bone Position and Look At Constraints.
-------------------------------------------------------------------------------------------------------

pc = Position_Constraint()
hipBone.pos.controller = pc
positionConstraintInterface = pc.constraints
positionConstraintInterface.appendtarget BonePos1 100
lc = LookAT_Constraint()
hipbone.rotation.controller = lc
rotationconstraintInterface = lc.constraints
rotationconstraintInterface.appendtarget BonePos2 100
hipBone.rotation.controller.viewline_length_abs = off
pc = Position_Constraint()
hipBoneNub.pos.controller = pc
positionConstraintInterface = pc.constraints
positionConstraintInterface.appendtarget BonePos2 100

pc = Position_Constraint()
spineBone1.pos.controller = pc
positionConstraintInterface = pc.constraints
positionConstraintInterface.appendtarget BonePos2 100
lc = LookAT_Constraint()
spineBone1.rotation.controller = lc
rotationconstraintInterface = lc.constraints
rotationconstraintInterface.appendtarget BonePos3 100
spineBone1.rotation.controller.viewline_length_abs = off
pc = Position_Constraint()
spineBone1Nub.pos.controller = pc
positionConstraintInterface = pc.constraints
positionConstraintInterface.appendtarget BonePos3 100

pc = Position_Constraint()
spineBone2.pos.controller = pc
positionConstraintInterface = pc.constraints
positionConstraintInterface.appendtarget BonePos3 100
lc = LookAT_Constraint()
spineBone2.rotation.controller = lc
rotationconstraintInterface = lc.constraints
rotationconstraintInterface.appendtarget BonePos4 100
spineBone2.rotation.controller.viewline_length_abs = off
pc = Position_Constraint()
spineBone2Nub.pos.controller = pc
positionConstraintInterface = pc.constraints
positionConstraintInterface.appendtarget BonePos4 100

pc = Position_Constraint()
spineBone3.pos.controller = pc
positionConstraintInterface = pc.constraints
positionConstraintInterface.appendtarget BonePos4 100
lc = LookAT_Constraint()
spineBone3.rotation.controller = lc
rotationconstraintInterface = lc.constraints
rotationconstraintInterface.appendtarget BonePos5 100
spineBone3.rotation.controller.viewline_length_abs = off
pc = Position_Constraint()
spineBone3Nub.pos.controller = pc
positionConstraintInterface = pc.constraints
positionConstraintInterface.appendtarget BonePos5 100

-------------------------------------------------------------------------------------------------------
--END Bone Position and Look At Constraints.
-------------------------------------------------------------------------------------------------------
--START Upnode Placement, Path Constraints and Bone Setup
-------------------------------------------------------------------------------------------------------

upnodePos1 = point name: "upnode_Pos1" size: 10
upnodepos2 = point name: "upnode_Pos2" size: 10
upnodePos3 = point name: "upnode_Pos3" size: 10
upnodePos4 = point name: "upnode_Pos4" size: 10

pathc = Path_Constraint()
upnodePos1.pos.controller = pathc
pathc.path = ikNodeSpline
pathc.percent = 10

pathc = Path_Constraint()
upnodePos2.pos.controller = pathc
pathc.path = ikNodeSpline
pathc.percent = 30

pathc = Path_Constraint()
upnodePos3.pos.controller = pathc
pathc.path = ikNodeSpline
pathc.percent = 50

pathc = Path_Constraint()
upnodePos4.pos.controller = pathc
pathc.path = ikNodeSpline
pathc.percent = 70

deletekeys upnodePos1
deletekeys upnodePos2
deletekeys upnodePos3
deletekeys upnodePos4

hipBone.rotation.controller.upnode_world = off
hipBone.rotation.controller.pickUpNode = upnodePos1
hipBone.rotation.controller.upnode_ctrl = 0
hipBone.rotation.controller.StoUP_axis = 1

spineBone1.rotation.controller.upnode_world = off
spineBone1.rotation.controller.pickUpNode = upnodePos2
spineBone1.rotation.controller.upnode_ctrl = 0
spineBone1.rotation.controller.StoUP_axis = 1

spineBone2.rotation.controller.upnode_world = off
spineBone2.rotation.controller.pickUpNode = upnodePos3
spineBone2.rotation.controller.upnode_ctrl = 0
spineBone2.rotation.controller.StoUP_axis = 1

spineBone3.rotation.controller.upnode_world = off
spineBone3.rotation.controller.pickUpNode = upnodePos4
spineBone3.rotation.controller.upnode_ctrl = 0
spineBone3.rotation.controller.StoUP_axis = 1

-------------------------------------------------------------------------------------------------------
--END Upnode Placement, Path Constraints and Bone Setup
-------------------------------------------------------------------------------------------------------


I've isolated where the problem seems to occur. When this part of the script is left out for each knot, they get placed correctly when opened from another script but then they are no longer constrained to my control circles.


pc = Position_Constraint()
arrayIKSpline[1].pos.controller = pc
positionConstraintInterface = pc.constraints
positionConstraintInterface.appendtarget ctrlSpine1 100
arrayIKSpline[1].pos.controller.relative = true

any clues?

Bobo
01-28-2009, 03:01 PM
Include() is a compile-time statement. It is not used while the script is running, but while it is being evaluated. It has the effect of pasting the sources of the scripts together as if they were in a single file. So having an event handler containing an include() does not call the include when the button is pressed, but makes the code of the included file part of the handler's code. Without seeing it all, it is hard to tell where it goes wrong.

Since the MAXScript Editor in Max 2008 and higher supports HUGE files, try putting your code together in a single file (I don't know what a long script is in your case, but if it is less than 500KB of source code, it is pretty normal in my book - my beloved KrakatoaGUI.ms is nearly 500KB right now ;)) and see if it runs without any include calls.

ElectricBones
01-28-2009, 03:36 PM
Thanks for the reply...It looks like the include is nothing to do with it now... I've tried including it all into a single file and the same problem occurs.
I've taken out the above mentioned position_constraint() which stops the helper points being shunted to [0,0,0] but then my position constraint is no longer there and I can't use my rig anymore.

Kramsurfer
01-28-2009, 08:46 PM
500k .ms files ? Sweet..

We're in the process of moving from 9 to 2009, I'll be trying out this "big file" thing. Our Scene Management Script, Scene Pimp, in pieces is 972k.

It'll be interesting having it all in one spot, although it's already divided by logical sections.

CGTalk Moderation
01-28-2009, 08:46 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.