Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

FUSION API: SPECIFYING OCCURENCE SURFACE AFTER INSERT FOR EXTRUDE TO ENTITY

Anonymous
410 Views
1 Reply
Message 1 of 2

FUSION API: SPECIFYING OCCURENCE SURFACE AFTER INSERT FOR EXTRUDE TO ENTITY

Anonymous
Not applicable

Hi,

 

I am having difficulties with trying to acquire features of an occurrence after inserting the occurrence to a current design. I am currently working on a wind turbine design where I would like to automate:

 

1. Inserting the blade file into the hub file (a cylinder - the centre piece that joins all blades together)

2. Move the blade to the correct position

3. Extrude to entity from the blade root to the hub

4. Pattern both the extrude entity and blades around the hub

 

The code below assumes that I already have the hub and blade CADs ready with both saved. The blade CAD is simply a blend of aerofoil sketches. Currently what I have are points (1) and (2) achieved and I have difficulties with (3) - specifically how can I specify that I want the first sketch plane of the blade to extrude to entity onto the circular hub surface?

 

I have also attached my blade and hub CADs below. Thanks in advance.

 

 


import adsk.core, adsk.fusion, adsk.cam, traceback import math def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface product = app.activeProduct design = adsk.fusion.Design.cast(product) root = design.rootComponent; # locate blade file BladeFile = None for file in project.rootFolder.dataFiles: if file.name == 'blade': BladeFile = file break # add blade in with transformation transform = adsk.core.Matrix3D.create() vector = adsk.core.Vector3D.create(0.1*100,0.0,0.187*100) transform.translation = vector blade = root.occurrences.addByInsert(BladeFile,transform,True) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

0 Likes
411 Views
1 Reply
Reply (1)
Message 2 of 2

marshaltu
Autodesk
Autodesk

Hello,

 

I add some codes to do what you needed. I am not sure if it meets your requirements. The line marked as red may need to be changed to run the codes in your side.

 

Thanks,

Marshal

 

import adsk.core, adsk.fusion, adsk.cam, traceback
import math

def run(context):
    
    ui = None
    
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        root = design.rootComponent;
        
        # locate blade file
        BladeFile = None
        for file in app.data.activeProject.rootFolder.dataFiles:
            if file.name == 'blade':
                BladeFile = file
                break

        # add blade in with transformation
        transform = adsk.core.Matrix3D.create()
        vector = adsk.core.Vector3D.create(0.1*100,0.0,0.187*100)
        transform.translation = vector
        blade = root.occurrences.addByInsert(BladeFile,transform,True)
        
        # Find the closest face from blade to hub
        cylinder = root.bRepBodies.itemByName('Body1')
        cylinderface = None
        cylinderfaceorigin = None
        for face in cylinder.faces:
            surface = face.geometry
            cylindersurface = adsk.core.Cylinder.cast(surface)
            if cylindersurface:
                cylinderface = face
                cylinderfaceorigin = cylindersurface.origin
                break

        body1inblade = blade.bRepBodies.itemByName('Body1')
        distance = 100000
        closestface = None
        for face in body1inblade.faces:
            tempdistance = face.centroid.distanceTo(cylinderfaceorigin)
            if tempdistance < distance:
                distance = tempdistance
                closestface = face

        # Extrude the closet face to cylinder face in the hub
        extrudeinput = root.features.extrudeFeatures.createInput(closestface, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        extrudeinput.setOneSideToExtent(cylinderface, True)
        extrudefeature = root.features.extrudeFeatures.add(extrudeinput)
        
        # Pattern blade
        inputentities = adsk.core.ObjectCollection.create()
        inputentities.add(blade)
        patterninput1 = root.features.circularPatternFeatures.createInput(inputentities, cylinderface)
        patterninput1.quantity = adsk.core.ValueInput.createByReal(3)
        root.features.circularPatternFeatures.add(patterninput1)
        
        # Pattern extrude
        inputentities.clear()
        for body in extrudefeature.bodies:
            inputentities.add(body)
        patterninput2 = root.features.circularPatternFeatures.createInput(inputentities, cylinderface)
        patterninput2.quantity = adsk.core.ValueInput.createByReal(3)
        root.features.circularPatternFeatures.add(patterninput2)
        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


Marshal Tu
Fusion Developer
>
0 Likes