Reply
Highlighted
Participant
14 Posts
Accepted Solution

revolute joint defined by two circles

39 Views, 5 Replies
Tuesday

 

Hi once again,

I'm trying to mimic the joint creation that works in the UI: define a rotaty joint by selecting one circle in each component:

 

 

# find 2 part that go together and joint them wiht the circle in sketch 'Skizze7'
for i in range(0,parts.count): print('current part: ' +parts.item(i).name) if(parts.item(i).name.startswith('pt1')): prox = parts.item(i); print(' found part: ' + str(prox.name)) comp = prox.component sketches0 = comp.sketches joint0 = sketches0.itemByName('Skizze7') circle0 = joint0.sketchCurves.sketchCircles.item(0) print(' circle: ' + str(circle0)) geo0 = adsk.fusion.JointGeometry.createByCurve(circle0, adsk.fusion.JointKeyPointTypes.CenterKeyPoint) elif(parts.item(i).name.startswith('pt2')): dist = parts.item(i); print('found part: ' + str(dist.name)) comp = dist.component sketches1 = comp.sketches joint1 = sketches1.itemByName('Skizze7') circle1 = joint1.sketchCurves.sketchCircles.item(0) print(' circle: ' + str(circle1)) geo1 = adsk.fusion.JointGeometry.createByCurve(circle1, adsk.fusion.JointKeyPointTypes.CenterKeyPoint) joints = root.joints jointInput = joints.createInput(geo0, geo1) jointInput.setAsRevoluteJointMotion(adsk.fusion.JointDirections.ZAxisJointDirection) # # # Create the joint joint = joints.add(jointInput)

I receive the following error:

 

 

Traceback (most recent call last):
  File "C:/sample.py", line 378, in run joint = joints.add(jointInput)
  File "C:/Users/knorr_s1/AppData/Local/Autodesk/webdeploy/production/2937474db5cdf8bca194aa6f1765e510127e0d47/Api/Python/packages\adsk\fusion.py", line 15181, in add
    return _fusion.Joints_add(self, *args)
RuntimeError: 2 : InternalValidationError : request->setJointOrigins(jo1Def0, jo1Def1)

inspecting both JointGeometry objects I find nothing suspicious ( geometrytype: 4 , keyPointType: 3 like in the manually joined assembly).

 

What do I miss here?

 

Thanks for any suggestions!

Stefan

 

 

This has to do with the sketch circle you're using.  It needs to be  a proxy that's in the context of the top-level assembly.  You can read more about proxies here:

 

Here's some sample code based on your original code that demonstrates this: http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A

 

def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = adsk.fusion.Design.cast(app.activeProduct)
# Get the root component of the active design
rootComp = design.rootComponent
occ = adsk.fusion.Occurrence.cast(None)
occ1 = None
occ2 = None
for occ in rootComp.allOccurrences:
if occ.name.startswith('TestPart1'):
occ1 = occ
elif occ.name.startswith('TestPart2'):
occ2 = occ
if occ1 and occ2:
break
# Find the sketch and circle in occ1.
sk = occ1.component.sketches.itemByName('ForJoint')
circ1 = sk.sketchCurves.sketchCircles.item(0)
# Create a proxy for the circle.
circ1.createForAssemblyContext(occ1)
# Find the sketch and circle in occ2.
sk = occ2.component.sketches.itemByName('ForJoint')
circ2 = sk.sketchCurves.sketchCircles.item(0)
# Create a proxy for the circle.
circ2.createForAssemblyContext(occ2)
# Create the joint.
jointGeom1 = adsk.fusion.JointGeometry.createByCurve(circ1, adsk.fusion.JointKeyPointTypes.CenterKeyPoint)
jointGeom2 = adsk.fusion.JointGeometry.createByCurve(circ2, adsk.fusion.JointKeyPointTypes.CenterKeyPoint)
joints = rootComp.joints
jointInput = joints.createInput(jointGeom1, jointGeom2)
jointInput.setAsRevoluteJointMotion(adsk.fusion.JointDirections.ZAxisJointDirection)
# Create the joint
joint = joints.add(jointInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Autodesk Support
1256 Posts
352 Kudos
368 Solutions

Re: revolute joint defined by two circles

Tuesday in reply to: stefan

This has to do with the sketch circle you're using.  It needs to be  a proxy that's in the context of the top-level assembly.  You can read more about proxies here:

 

Here's some sample code based on your original code that demonstrates this: http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A

 

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        design = adsk.fusion.Design.cast(app.activeProduct)
        
        # Get the root component of the active design
        rootComp = design.rootComponent

        occ = adsk.fusion.Occurrence.cast(None)
        occ1 = None
        occ2 = None
        for occ in rootComp.allOccurrences:
            if occ.name.startswith('TestPart1'):
                occ1 = occ
            elif occ.name.startswith('TestPart2'):
                occ2 = occ
                
            if occ1 and occ2:
                break
            
        # Find the sketch and circle in occ1.
        sk = occ1.component.sketches.itemByName('ForJoint')
        circ1 = sk.sketchCurves.sketchCircles.item(0)
        
        # Create a proxy for the circle.
        circ1.createForAssemblyContext(occ1)
        
        # Find the sketch and circle in occ2.
        sk = occ2.component.sketches.itemByName('ForJoint')
        circ2 = sk.sketchCurves.sketchCircles.item(0)
        
        # Create a proxy for the circle.
        circ2.createForAssemblyContext(occ2)
        
        # Create the joint.        
        jointGeom1 = adsk.fusion.JointGeometry.createByCurve(circ1, adsk.fusion.JointKeyPointTypes.CenterKeyPoint)
        jointGeom2 = adsk.fusion.JointGeometry.createByCurve(circ2, adsk.fusion.JointKeyPointTypes.CenterKeyPoint)
            
        joints = rootComp.joints
        jointInput = joints.createInput(jointGeom1, jointGeom2)
        jointInput.setAsRevoluteJointMotion(adsk.fusion.JointDirections.ZAxisJointDirection)
           
        # Create the joint
        joint = joints.add(jointInput)        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Participant
14 Posts

Re: revolute joint defined by two circles

Tuesday in reply to: ekinsb

Thanks again Brian!

Reading about the proxy concept - it looks a bit like a pointer into the component file to a specific geometry/feature. The proxy itself has no intrinsic properties except to represent something else. 

 

so Fusion does the proxy generation using the UI without the user knowing about it.

 

Thanks again !

Stefan

Participant
14 Posts

Re: revolute joint defined by two circles

Wednesday in reply to: stefan

Hi Brian,

I just set up the assembly and it works. Of course I had to pass the proxy to the JointGeometry and not the geometries themselves like this:

        # Find the sketch and circle in occ1.
        sk = occ1.component.sketches.itemByName('ForJoint')
        circ1 = sk.sketchCurves.sketchCircles.item(0)
        
        # Create a proxy for the circle.
        c1 = circ1.createForAssemblyContext(occ1)
        
        # Find the sketch and circle in occ2.
        sk = occ2.component.sketches.itemByName('ForJoint')
        circ2 = sk.sketchCurves.sketchCircles.item(0)
        
        # Create a proxy for the circle.
        c2 = circ2.createForAssemblyContext(occ2)
        
        # Create the joint.        
        jointGeom1 = adsk.fusion.JointGeometry.createByCurve(c1, adsk.fusion.JointKeyPointTypes.CenterKeyPoint)
        jointGeom2 = adsk.fusion.JointGeometry.createByCurve(c2, adsk.fusion.JointKeyPointTypes.CenterKeyPoint)

Big Thanks again!

 

PS: Are there any plans to include the sculpt environment or to enable motion studies via the API in the future?

Autodesk Support
1256 Posts
352 Kudos
368 Solutions

Re: revolute joint defined by two circles

Wednesday in reply to: stefan

There are plans to expose the sculpting functionality but there isn't a timeline for that.  This is the first time motion studies has been requested and there hasn't been any investigation into that.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Participant
14 Posts

Re: revolute joint defined by two circles

20 hours ago in reply to: stefan

One more detailed question concerning a tree structure of components.

I have serveral components like

- base

 

+ root
+ component1
+ occurence1 (grounded in component1)
+ occurence2 (joint with occurence1)
+ component2
+ occurence3 (grounded in component2)

now I want to create a joint in the root component between occurence1 and occurence3.

I picked the reference geometry in both occurences and create the proxies like this.

 

l1 = lineInOcc1.createForAssemblyContext(occ1)
l3 = lineInOcc3.createForAssemblyContext(occ3)  

The joint creation fails and I assume the trick is the proxy again. Do I have to create proxies to the joint reference in component1 and component2 first? In the UI I can establish the joint, so I assume it will work in the API as well.

 

Thanks,

Stefan