Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Creating an offset feature into a new component

jonas_tjepkema
Explorer

Creating an offset feature into a new component

jonas_tjepkema
Explorer
Explorer

Hi,

 

I've run a little bit into a wall and cannot figure it out... I am using the Fusion API to basically copy a single face of a design into a new component. To do this I found that an offset of 0 cm was the best approach, but I cannot figure out why my new offset is created into the same component as the original body/face...

 

Is there a way to do the feature directly into a new component like in the GUI, or do I need to go through the process of cutting and pasting the new body into the new component?

 

edit: also, is there an easy way to get the parent body or component of the selected face? I somehow cannot find any straight forward way to do it...

 

def createNewComponent(comp, name):
            allOccs = comp.occurrences
            newOcc = allOccs.addNewComponent(adsk.core.Matrix3D.create())
            newOcc.component.name = name
            return newOcc.component

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        design = adsk.fusion.Design.cast(app.activeProduct)

        rootComp = design.rootComponent
        newComp = createNewComponent(rootComp, "slices_test")

        faceSel = ui.selectEntity("Select a face", "Faces")
        if faceSel.entity.objectType == adsk.fusion.BRepFace.classType():
            faceInput = faceSel.entity
        else:
            ui.messageBox("Error: Please select a valid face.")
            return
        
        inputEntities = adsk.core.ObjectCollection.create()
        inputEntities.add(faceInput)

        distance = adsk.core.ValueInput.createByString('0 cm')

        offsetFeature = newComp.features.offsetFeatures
        offsetInput = offsetFeature.createInput(inputEntities,distance,adsk.fusion.FeatureOperations.NewBodyFeatureOperation,False)
        offsetFeature.add(offsetInput)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

0 Likes
Reply
Accepted solutions (1)
202 Views
1 Reply
Reply (1)

kandennti
Mentor
Mentor
Accepted solution

Hi @jonas_tjepkema -San.


I think your code should be correct.

 

If you want to create an offset within the new occurrence in its current state, it seems you can do it by activating the new occurrence.

0 Likes