Solved! Go to Solution.
Solved by MichaelT_123. Go to Solution.
Solved by ekinsb. Go to Solution.
Here's a small sample that takes in a list of lists where each list in the list consists of two items; the name of the parameter and the expression to assign to it. The code then iterates through this list and sets each of the parameters to the specified value.
paramList = [['Length', '1 in'], ['Width', '2 in'], ['Height', '0.5 in'], ['Angle', '10 deg']] def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface des = adsk.fusion.Design.cast(app.activeProduct) for paramInfo in paramList: param = des.allParameters.itemByName(paramInfo[0]) param.expression = paramInfo[1] except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Thank you Brian for the prompt response.
It was great help.
In my the first stumble with F360 script I have tried to animate joints using script.
Perhaps it was to difficult step for a toddler ...
I tripped on couple of issues. Some of the are below.
1.) API lists a JointList object which does not appear on the pulldown menu when writing script.
The code I have used
var jointX = des.rootComponent.JointList.itemByName('Slider_X');
returns error itemByName() method is undefined.
The method is listed in API documentation.
"jointList_var" is a variable referencing a JointList object.
var returnValue = jointList_var.itemByName(name);
2.) I have tried AsBuiltJoints in the similar code
var jointX = des.rootComponent.AsBuiltJoints.itemByName('Slider_X');
There was the same error.
3.) The same journey I had with AsBuiltJointList
var jointX = des.rootComponent.AsBuiltJointList.itemByName('Slider_X');
This is still far from animating the Joints. Perhaps I will use .offset ???
What am I doing wring Brian?
Can you help me to make this first step?
With Regards
MichaelT
It's actually easier than you're making it because of the parametric capabilities in Fusion. When you place a dimension to control the size of sketch geometry and create a feature, there are parameters created that control all of those. For example, when you place a dimension to control the length of a sketch line, there is a parameter automatically created that the dimension is dependent on. If you change the value of the parameter, the dimension will automatically update and anything that uses that sketch line (i.e. a feature) will also automatically update. You access parameters through the "Change Parameters" command in the MODIFY menu.
When you create a joint the same thing happens. A parameter is automatically created that controls the values associated with a joint. For example, if I create a revolute joint Fusion automatically creates four parameters; one to control the revolute angle and three others to control the x, y, and z offset values. If I want to animate the part by changing the angle of the joint I just need to change the value of the parameter. To make it easier to use the parameters you can rename in the Parameters dialog to something that makes sense like "Motor 1" and then reference them by name in your program.
Thank you Brian,
yours replays were very helpful. Particularly the first with the event handler I find interesting.
I did couple exercises with the "parameters" path as you suggested.
The drawback is that the same parameters in the real unpredictable CADord ( CAD world ) can control many things at once or they can be advertently inserted.
Addressing/finding the joint by its name/component could greatly alleviate the issue. .... much more ... attaching the event/process handler directly to the joint (instead lonely parameters ) could open many other interesting possibilities.
Could you find the way to overcome the stumbling piece of code I have mentioned e.g. :
var jointX = desvar jointX = des.rootComponent.XXXXXJointList.itemByName('Slider_X'); ?
With Regards
MichaelT
Here's some code that finds the joint by name and then drives it's value through a series of steps.
def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface des = adsk.fusion.Design.cast(app.activeProduct) root = des.rootComponent slider = root.joints.itemByName('Slider1') sliderMotion = adsk.fusion.SliderJointMotion.cast(slider.jointMotion) for i in range(0, 100): sliderMotion.slideValue = i * .01 adsk.doEvents() except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Thanks Brian.
In this exercise I have learnt quite a few things about fused joints 🙂 and also that I can rely on a support of fusion experts in all 360 directions.
I have learned --- there are two distinctive "JOINTS" component's collection object classes.
--- The joints collection as you would add to it by manually creating joint using the dialog input command.
--- The asBuiltJoints collection as you would add to it by allowing the automatic contextual creation by F360 of AsBuiltJoint
So joint and AsBuiltJoint are distinctive within a given particular F360 component ....use component.joints or component.AsBuiltJoints respectively to find them.
If you however want to find the joint or AsBuiltJoint not only in the particular component but also inside it's subcomponents there are matching allJoints and allAsBuiltJoints component's properties to accomplish this.
???? as I understand it ????
In my first exercises in this area I was really stiffed and paralysed for a couple of days. Now I am sliding on the path to recovery ...
With Regards
MichaelT