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: 

Weird behavior in circular patterns

2 REPLIES 2
Reply
Message 1 of 3
dirktheeng
583 Views, 2 Replies

Weird behavior in circular patterns

I'm trying to create a circular pattern using the following code.  It creates the pattern but not the same way the GUI does and it creates a something in the component tree which will cause a hard crash of Fusion 360.

 

Here's my code:

 

class fusionAPI:
    def __init__(self):
        try:
            self.app = adsk.core.Application.get()
            self.core = adsk.core
            self.ui = self.app.userInterface
            self.product = self.app.activeProduct
            self.design = adsk.fusion.Design.cast(self.product)
            self.rootComp = self.design.rootComponent
            self.sketches = self.rootComp.sketches
            self.pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062
            self.globalOrigin = adsk.core.Point3D.create(0,0,0)
            self.extrudes = self.rootComp.features.extrudeFeatures
            self.getUserParameterNames()
            self.orientAligned = adsk.fusion.DimensionOrientations.AlignedDimensionOrientation
            self.orientHorizontal = adsk.fusion.DimensionOrientations.HorizontalDimensionOrientation
            self.orientVertical = adsk.fusion.DimensionOrientations.VerticalDimensionOrientation
        except:
            if self.ui:
                self.ui.messageBox('Problem in __init__:\n{}'.format(traceback.format_exc()))

    def circularPatternFeature(self,feature, axis = None, n = 6, totalAngle = 360, AngleUnits = 'deg'):
        
        if axis == None:
            axis = self.rootComp.yConstructionAxis
            
        if not isinstance(n,str):
            n = str(n)
        if not isinstance(totalAngle,str):
            totalAngle = str(totalAngle)
        
        totalAngle += ' ' + AngleUnits
        
        #Create a new component to stick the pattern in
        newOcc = self.rootComp.occurrences.addNewComponent(adsk.core.Matrix3D.create())
        
        # grab the body from the feature anc create an Assembly Context in the new component
        body = feature.faces.item(0).body
        body = body.createForAssemblyContext(newOcc)
        
        # create an assembly contect for the axis as well in the new component
        axis = self.rootComp.yConstructionAxis.createForAssemblyContext(newOcc)
        
        # create an object collection and add the body to it   
        entities = adsk.core.ObjectCollection.create()
        entities.add(body)
        
        # create a circular pattern
        circularPatterns = self.rootComp.features.circularPatternFeatures
        patternInput = circularPatterns.createInput(entities,axis)
        numInstances = adsk.core.ValueInput.createByString(n)
        totalAngle = adsk.core.ValueInput.createByString(totalAngle)
        patternInput.quantity = numInstances
        patternInput.totalAngle = totalAngle
        circularPatterns.add(patternInput)
        return newOcc

 create in insance of fusionAPI and then pass a feature into circularPatternFeature

 

This is what I get:

 

2014-12-29_19-59-26.png

 

The original component was the Single_Segment:1.  I turned off the visibility to highlight the new component (Component2:1).  Now look at the C-Pattern1 Group(8).  It does indeed have 8 bodies, but notice that it has 2 bodies labled Body1.  If I click on the first Body 1 or even mouse over it, it will cause a crash.

 

Am I doing something wrong or is this a bug?

21st Century Woodworking

-Blending 21st Century Woodworking with Old World Skill
Tags (1)
2 REPLIES 2
Message 2 of 3
dirktheeng
in reply to: dirktheeng

I'm beginning to think this is a bug and that it is not doing some cleanup like it should.  If you return the created component to a variable called pComp and do print(pComp.component.bRepBodies.count) you only get 7 bodies, not 8 like the component tree shows.  If I go and create a new pattern in the gui after creating the one from the script, the mistery component disappears.

21st Century Woodworking

-Blending 21st Century Woodworking with Old World Skill
Message 3 of 3
neil.liu
in reply to: dirktheeng

Thank you for posting the issue.

 

We verifed the workflow with your scipts, they worked as expected on the next release build, while we can reproduce the issue with the previous release, so I assume the issue should have been fixed in the new release (coming soon). 

 

From your scripts it looks there is a bug: if a body is not inside of a component, the assembly context with the component for this body should be invalid. We will figure out the solution soon.   

# grab the body from the feature anc create an Assembly Context in the new component
        body = feature.faces.item(0).body
        body = body.createForAssemblyContext(newOcc)

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