View Full Version : CSolver Simple Problem
HCompston 06-19-2007, 07:48 PM Hello
This is realy simple but I can no longer see the wood for the trees.
I am putting together a quick script that adds a bunch of point constraints to a selection of object. I can do this bit fine. However I want to add the point constraints to the Constraint Solver. The syntax in the manual says <boolean>AddConstraint <node>newConstraint No matter what I try and do I cannot get this to work. Can someone give me a quick sample of how to add a constraint to a solver using this code?
Thanks
Harry
|
|
Is this SDK or Max script?
Or are you looking at the Reactor Dynamics max script access help. That is the only place that I can find the line that you are describing in the help.
If it is and you are looking for position constraint instead then need to look up just that.
HCompston
06-19-2007, 09:05 PM
Hi Paul
I am trying to add a Reactor Point_Point() constraint to a CSolver() Constraint solver. This is part of a script to help facilatate the automation of setting up a reactor based animation.
It is all maxscript and not SDK.
Thanks
Harry
HCompston
06-20-2007, 08:44 AM
Ok Still stuck but got a little further. It seems that the addconstraint method is similar to the addmodifier method. However I do not understand the <boolean> argument it is asking for. Has anyone ever used this method or is there a better way to add the reactor objects to the solver?
Thanks
Harry
HCompston
06-20-2007, 08:31 PM
Ok Been trying all day now and the syntax is alluding me.
Where's Bobo hiding ;)
Harry
MoonDoggie
06-20-2007, 08:37 PM
I believe that means the method returns a boolean if it was successful. Could be wrong.
HCompston
06-20-2007, 09:06 PM
Hi MoonDoggie
I thought that however the method specifies <boolean>AddConstraint <node>newConstraint so I presumed that it was similar to the addmodifier method. However when you try and use like an addmodifier it returns a "Wanted 4 got 2" error. Now I assume that this the number of arguments that the method requires. However in the manual it only seems to specify 2. So I am a little stuck.
Thanks
Harry
davestewart
06-20-2007, 11:48 PM
Hi Harry,
I've never used Reactor, but I thought I'd have a fiddle. This worked for me; am I missing your point?
c = CSolver()
p = Point_Point()
c.addConstraint p
HCompston
06-21-2007, 12:43 PM
Hi Dave
This is exactly what I was trying. Here is the script in its early dev stage. You can see the very same code at the bottom . I have commented it for ease. This returns the error
-- Argument count error: AddConstraint wanted 4, got 2
Any Ideas?
(
MyRBCol = RBCollection()
MyRBCol.name = "MyRigidBody_Solver"
MyCSolver = CSolver ()
MyCSolver.name = "MyConstraint_Solver"
MySelection = Selection as array
Local MyParent = $lamp
For i = 1 to Myselection.count do
(
MyObj = Myselection[i]
MyObj.parent = MyParent
MyPCont = Point_Point()
MyPCont.name = (MyObj.name + "_PointConst")
MyPcont.Childbody = MyObj
MyPcont.hasparent = true
MyPcont.parentbody = MyParent
MyCSolver.rbCollection = MyRBCol
Addconstraint MyPcont MyCSolver -- addconstraint line
)
)
Thanks
Harry
davestewart
06-21-2007, 01:03 PM
Ahh... simple mistake!
You're asking max to execute the global function "addConstraint" (see "Controller Functions for use with Constraint Assignments" in the help") which expects 4 arguments...
...as opposed to the cSolvers's method (function) "addConstraint" which expects 1 argument. If you change the last line of your script to...
MyCSolver.Addconstraint MyPcont
...it should all work fine.
Basically, any object that has an "Interface" or "Interfaces" takes it's object name first, followed by the method (function) name, then it's arguments:
objectNameOrType.methodName argument1 argument2 argumentN
It's not that clear to people first starting out in max script (Understanding the structure of a function or method in the help file isn't that clear unless you have programming experience, or have read "How do I understand the function definitions in this document?" in the help), but that's the key thing.
You can see all the accessible properties and functions of an object (if it has any) with the following command:
showInterfaces $
Interface: rctConstraintSolverInterface
Properties:
.constraints : node by value array : Read|Write
.rbCollection : node : Read|Write
.isDisabled : boolean : Read|Write
.deactivationThreshold : float : Read|Write
Methods:
<boolean>addConstraint newConstraint
<boolean>removeConstraintIndex index
<boolean>removeConstraint deletedConstraint
<integer>getNumConstraints()
<boolean>isValid()
Actions:
Does that make it clear!?
Cheers,
Dave
HCompston
06-21-2007, 06:30 PM
Hi Dave
One day I must read the whole manual, im sure it will make sense then :)
Believe it or not that was what I was looking for in the manual but couldnt find it. I ususaly use ShowProperties when looking for that information but forgot to even try it in this case..
Thanks a lot.
Harry
CGTalk Moderation
06-21-2007, 06:30 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.