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: 

"Failed to get owner occurrence transform" - Rectangular Pattern of Occurrences

1 REPLY 1
Reply
Message 1 of 2
Mr.Stephen-K
94 Views, 1 Reply

"Failed to get owner occurrence transform" - Rectangular Pattern of Occurrences

Hello,

 

I am running into an error using the API while trying to perform a Rectangular Pattern on an occurrence of a component. 

 

In general, I am trying to create a new "Parent" component / occurrence in a design that will hold "Child" hardware component occurrences.  The script successfully creates the "Parent" component / occurrence activates the new occurrence creates the "Child" hardware occurrences and pattens them.  However, when I review the Timeline the Rectangular Pattern features show "yellow / sick" and have the following error: 

 

MrStephenK_0-1677088873824.png

 

Double clicking / opening the sick pattern feature and closing resolves the "sick / yellow" warning and the pattern seems to be stable.  

 

Below is the "Generalized" section of code used to perform this operation:

import adsk.core, adsk.fusion, adsk.cam, traceback    
app: adsk.core.Application = adsk.core.Application.get()
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
ui = app.userInterface

root = design.rootComponent

vector = adsk.core.Vector3D.create(0.0, 0.0, 0.0)
transform = adsk.core.Matrix3D.create()
transform.translation = vector

parent_part_occ = root.occurrences.addNewComponent(transform)
parent_part_occ.component.name = "Parent Part"
parent_part_occ.component.description = "Parent Part"

#create parts list to add occurrances 
child_parts_add_list = ['123', '456', '789']
child_parts_add_qty = ['16', '2', '1']
child_parts_add_desc = ["Name 1", "Name 2", "Name 3"]

parent_part_occ.activate = True

for part, qty, desc in zip(child_parts_add_list, child_parts_add_qty, child_parts_add_desc):
       new_occ = parent_part_occ.component.occurrences.addNewComponent(transform)
       new_occ.component.name = desc 
       new_occ.component.description = desc
       new_occ.component.partNumber = part
       
       if int(qty) > 1:
              # Create input entities for rectangular pattern
              inputEntites = adsk.core.ObjectCollection.create()
              inputEntites.add(new_occ)
              
              # Get x and y axes for rectangular pattern
              xAxis = root.xConstructionAxis
              yAxis = root.yConstructionAxis
              
              # Quantity and distance
              quantityOne = adsk.core.ValueInput.createByString(qty)
              distanceOne = adsk.core.ValueInput.createByString('1 in')
              quantityTwo = adsk.core.ValueInput.createByString('1')
              distanceTwo = adsk.core.ValueInput.createByString('0 in')
              
              # Create the input for rectangular pattern
              rectangularPatterns = parent_part_occ.component.features.rectangularPatternFeatures
              rectangularPatternInput = rectangularPatterns.createInput(inputEntites, xAxis, quantityOne, distanceOne, adsk.fusion.PatternDistanceType.SpacingPatternDistanceType)
              
              # Set the data for second direction
              rectangularPatternInput.setDirectionTwo(yAxis, quantityTwo, distanceTwo)
              
              # Create the rectangular pattern
              rectangularFeature = rectangularPatterns.add(rectangularPatternInput)
              rectangularFeature.name = "Pattern " + desc
              inputEntites.clear 
              
parent_part_occ.activate = False

 

I am wondering what this error means and how to avoid the code from causing the Rectangular Pattern to be created with this warning.  It seems suspect that a open / close of the feature resolves the issue.

 

Thank you,

 

1 REPLY 1
Message 2 of 2
kandennti
in reply to: Mr.Stephen-K

Hi @Mr.Stephen-K .

 

I tried a few.

I found some things that were wrong and will tell you about them.

・・・
# parent_part_occ.activate = True
parent_part_occ.activate()
・・・

・・・
# parent_part_occ.activate = False
design.activateRootComponent()
・・・

However, it was not the cause of this phenomenon.

 

I made the following changes to try it out.

・・・
        for part, qty, desc in zip(child_parts_add_list, child_parts_add_qty, child_parts_add_desc):
            # new_occ = parent_part_occ.component.occurrences.addNewComponent(transform)
            new_occ = root.occurrences.addNewComponent(transform)
            new_occ.component.name = desc 
            new_occ.component.description = desc
・・・

In this case it did not result in a warning.
For the root component it is not a problem, only for the occurrence component it is a warning.

 

I think the "rectangularFeature" created by the Add method is a NativeObject because the nativeObject is set to None.

1.png

I felt that this was the cause of the problem, but I could not figure out how to make it a Proxy.

・・・

                # Create the rectangular pattern
                rectangularFeature = rectangularPatterns.add(rectangularPatternInput)
                rectangularFeature = rectangularFeature.createForAssemblyContext(new_occ) #<-error
                rectangularFeature.name = "Pattern " + desc

・・・

I added this one, but still got an error.

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