Announcements
Visit Fusion 360 Feedback Hub, the great way to connect to our Product, UX, and Research teams. See you there!
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

(API) Copy brep attributes to brep proxy in occurrence

(API) Copy brep attributes to brep proxy in occurrence

When you add an attribute to a BRepBody or body sub-entity, it would be useful to make that attribute available on all occurrences of that body, so that you can use Design.findAttribute and find all occurrences of a specific face, for example.

 

e.g.

 

 

import adsk.fusion
import adsk.core
import traceback

app = adsk.core.Application.get()
root = app.activeProduct.rootComponent

def box(x, y, z):
brep = adsk.fusion.TemporaryBRepManager.get()
box_body = brep.createBox(adsk.core.OrientedBoundingBox3D.create(
adsk.core.Point3D.create(x/2, y/2, z/2),
adsk.core.Vector3D.create(1, 0, 0),
adsk.core.Vector3D.create(0, 1, 0),
x, y, z))
occurrence = root.occurrences.addNewComponent(adsk.core.Matrix3D.create())
base_feature = occurrence.component.features.baseFeatures.add()
base_feature.startEdit()
occurrence.component.bRepBodies.add(box_body, base_feature)
base_feature.finishEdit()
box_body = occurrence.component.bRepBodies.item(0)
box_body.faces.item(0).attributes.add("myattributes", "mybox_face0", "mybox_face0")
box_body.attributes.add("myattributes", "mybox", "mybox")
return occurrence

def run(context):
try:
mybox = box(3, 3, 3)
transform = adsk.core.Matrix3D.create()
transform.translation = adsk.core.Vector3D.create(4, 0, 0)
mybox_duplicate = root.occurrences.addExistingComponent(mybox.component, transform)

attributes = app.activeProduct.findAttributes("myattributes", "mybox_face0")
print(len(attributes)) # result=1
print(attributes[0].otherParents) #result = None

# The attribute is available when referencing the component
print(mybox.component.bRepBodies.item(0).faces.item(0).attributes.count) # result = 1
# But it's not available when referencing an occurrence.
# It would be useful if the attributes in the following 2 cases contained the attributes from the base body
print(mybox.bRepBodies.item(0).faces.item(0).attributes.count) # result = 0
print(mybox_duplicate.bRepBodies.item(0).faces.item(0).attributes.count) # result = 0
except:
traceback.print_exc()

 

Can't find what you're looking for? Ask the community or share your knowledge.

Submit Idea  

Autodesk Design & Make Report