Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

revolute joint defined by two circles

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
designingberlin
334 Views, 5 Replies

revolute joint defined by two circles

 

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

 

 

5 REPLIES 5
Message 2 of 6
ekinsb
in reply to: designingberlin

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
Message 3 of 6
designingberlin
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

Message 4 of 6

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?

Message 5 of 6
ekinsb
in reply to: designingberlin

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
Message 6 of 6

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report