- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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()))
Solved! Go to Solution.