Making an as-built joint from components created using fscad

Making an as-built joint from components created using fscad

john.demello
Explorer Explorer
1,028 Views
8 Replies
Message 1 of 9

Making an as-built joint from components created using fscad

john.demello
Explorer
Explorer

Hi, I've been using Ben Gruver's excellent fscad wrapper for the Fusion 360 API, which simplifies the task of defining components. Unfortunately, the wrapper doesn't include any functionality for creating as-built joints so this must be done using the standard API. I tried to adapt the code samples in the Fusion 360 API documentation without success, and would appreciate some help. I have included below a simple code for generating two components via fscad. Please could you advise what extra code would be needed to define an as-built joint between the two components?  (Note, the occurrence returned by fscad's .create_occurrence() method is a normal fusion 360 Occurrence object).  Thanks in advance, John

0 Likes
Accepted solutions (1)
1,029 Views
8 Replies
  • API
Replies (8)
Message 2 of 9

john.demello
Explorer
Explorer
#Author-
#Description-

import adsk.core, adsk.fusion, adsk.cam, traceback
from fscad import *

def my_design():
    
    # define a box (extruded square)
    box = Box(3,3,5)
    box.place(~box == 0,~box == 0,-box == 0)
    # define a cyliinder
    cylinder = Cylinder(5,1)
    cylinder.place(~cylinder == 0,~cylinder == 0,-cylinder == 0)
    # define box with cylindrical hole
    tube = Difference(box,cylinder)

    # create occurrences of cylinder and box with cylindrical hole
    tube.create_occurrence(create_children=True)
    cylinder.create_occurrence()

    # define as-built joint between tube and cylinder

def run(context):
    # This is an fscad helper function to set up a new document that will be populated by this script. It will call
    # the specified function (my_design) after creating and setting up a fresh document.
    run_design(my_design, message_box_on_error=False, document_name=__name__)
0 Likes
Message 3 of 9

kandennti
Mentor
Mentor
Accepted solution

Hi @john.demello .

 

I have never used fscad before, but I was able to create a slider joint by doing the following.

# Fusion360API Python script
import adsk.core, adsk.fusion, adsk.cam, traceback
from .fscad import *

def my_design():
    
    # define a box (extruded square)
    box = Box(3,3,5)
    box.place(~box == 0,~box == 0,-box == 0)
    # define a cyliinder
    cylinder = Cylinder(5,1)
    cylinder.place(~cylinder == 0,~cylinder == 0,-cylinder == 0)
    # define box with cylindrical hole
    tube = Difference(box,cylinder)

    # # create occurrences of cylinder and box with cylindrical hole
    occBox = tube.create_occurrence(create_children=False)
    occCyl = cylinder.create_occurrence()

    # define as-built joint between tube and cylinder
    geoBox = createJointGeo(occBox.bRepBodies[0])
    geoCyl = createJointGeo(occCyl.bRepBodies[0])

    app :adsk.core.Application = adsk.core.Application.get()
    des :adsk.fusion.Design = app.activeProduct
    root :adsk.fusion.Component = des.rootComponent

    joints = root.joints
    jointInput = joints.createInput(geoBox, geoCyl)
    jointInput.setAsSliderJointMotion(
        adsk.fusion.JointDirections.ZAxisJointDirection)
    joints.add(jointInput)

def createJointGeo(body):
    def getCylinderFace(faces):
        for face in faces:
            if face.geometry.objectType == 'adsk::core::Cylinder':
                return face
        return None

    face = getCylinderFace(body.faces)
    if not face:
        return

    return adsk.fusion.JointGeometry.createByNonPlanarFace(
            face,
            adsk.fusion.JointKeyPointTypes.StartKeyPoint)


def run(context):
    # This is an fscad helper function to set up a new document that will be populated by this script. It will call
    # the specified function (my_design) after creating and setting up a fresh document.
    run_design(my_design, message_box_on_error=False, document_name=__name__)

 

Given that the wrapper doesn't include the joint, isn't it assumed that the assembly is not used?

0 Likes
Message 4 of 9

JeromeBriot
Mentor
Mentor
Message 5 of 9

JesusFreke
Advocate
Advocate

Yeah, fscad doesn't really do anything with joints. But once fscad runs, you should have some normal components, occurrences and bodies that you can use as per normal with all of the normal fusion APIs. I don't have any experience with the joint APIs, so I can't offer much in the way of help there.

Message 6 of 9

john.demello
Explorer
Explorer

This works perfectly - thank you! I'll need to do a bit of reading now to work out how to extend it to other joint types, but this gives me a really good starting point. Thanks again!

0 Likes
Message 7 of 9

john.demello
Explorer
Explorer
Thank you, I should have done this!
0 Likes
Message 8 of 9

john.demello
Explorer
Explorer

The things fscad can do, it does very well - I've found it to. be ideal for rapidly designing components.

0 Likes
Message 9 of 9

kandennti
Mentor
Mentor

@JesusFreke .

 

Your fscad efforts have made me aware of the importance of TemporaryBRepManager.
I appreciate it.