- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am essentially trying to cut out a gear from another gear I already formed. For that I can use a combine (cut) operation followed by a step in the revolute joint. I can then do another combine-command (before which I have to select: Capture Position) and thereby cut out an approximate shape of a gear. I did this manually a few times and it worked, but took ages so I tried to use the API. Here is what I came up with:
import adsk.core, adsk.fusion, adsk.cam, traceback
import math, time
combineFeatures = None
def cut(targetBody: adsk.fusion.MeshBody, toolBodies: adsk.core.ObjectCollection) -> adsk.fusion.MeshBody:
# Create New Combine Feature
combineFeatureInput = combineFeatures.createInput(targetBody, toolBodies)
# Set Up
combineFeatureInput.operation = 1 # Cut
combineFeatureInput.isKeepToolBodies = True
combineFeatureInput.isNewComponent = False
# Add To CombineFeatures
return combineFeatures.add(combineFeatureInput)
def run(context):
ui = None
try:
# Get Base
app = adsk.core.Application.get()
ui = app.userInterface
des = adsk.fusion.Design.cast(app.activeProduct)
# Get Revolute Joint (Gear2)
root = des.rootComponent
joint = root.asBuiltJoints.itemByName('Rev1')
rev = adsk.fusion.RevoluteJointMotion.cast(joint.jointMotion)
# Get The Components (Gear1 & Gear2)
occs = root.occurrences
comp1 = occs.item(0).component
comp2 = occs.item(1).component
# Get The Gear-Mesh-Bodies
gear1 = comp1.bRepBodies[0]
gear2 = comp2.bRepBodies[0]
# Pack gear1 In Collection (As Combine-Cut Requires toolBodies As A Collection)
cutters = adsk.core.ObjectCollection.create()
cutters.add(gear1)
# Get List Of All Combine Features/Commands & Set Globally
features = comp2.features
global combineFeatures
combineFeatures = features.combineFeatures
# Set Up To Group All Cut-Commands For Easy Deletion
cutFeature = None
firstCutIndex = None
# Cutting
for i in range(10):
# Revolve
rev.rotationValue = i * (math.pi/180) # increment revolve by 1deg
adsk.doEvents() # force revolution update
# Cut
cutFeature = cut(gear2, cutters)
if firstCutIndex == None:
firstCutIndex = cutFeature.timelineObject.index # set start index for grouping
time.sleep(1) # timeout to see each cut
# Group All Commands
lastCutIndex = cutFeature.timelineObject.index
timelineGroups = des.timeline.timelineGroups
timelineGroup = timelineGroups.add(firstCutIndex, lastCutIndex)
timelineGroup.name = 'Revolve-Cuts'
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
I could swear, that it already worked in between. Earlier I was able to see the correct cuts, but when the script terminated, all cuts became invisible but the first one. Now it rotates, but does not show any cutting. I kind of suspect that I need to capture the position somehow or update my gear2 any other way for the program to mind the rotation. Any help appreciated!
Solved! Go to Solution.