- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all,
I'm trying to create a program where the user can select a body or number of bodies using the command input window and then project the result onto a sketch, so I have tried copying and editing the 'ApplyMaterialToSelection' example code. Below are the changes I made to the code, creating the sketch3, passing it through the function, then using the project function to project the selected bodies onto the sketch. When the code runs the new component and sketch within is created but nothing appears on it.
def notify(self, args):
try:
command = args.firingEvent.sender
inputs = command.commandInputs
for input in inputs:
if input.id == commandId + '_selection':
selectionInput = input
elif input.id == commandId + '_materialList':
materialListInput = input
design = adsk.fusion.Design.cast(app.activeProduct)
transform = adsk.core.Matrix3D.create()
rootComp = design.rootComponent
allOccs = rootComp.occurrences
projectOcc = allOccs.addNewComponent(transform)
projectComp = projectOcc.component
sketches3 = projectComp.sketches
sketch3 = sketches3.add(rootComp.xYConstructionPlane)
entities = getSelectedEntities(selectionInput,sketch3)
def getSelectedEntities(selectionInput,sketch3):
entities = []
for x in range(0, selectionInput.selectionCount):
mySelection = selectionInput.selection(x)
selectedObj = mySelection.entity
if type(selectedObj) is adsk.fusion.BRepBody or type(selectedObj) is adsk.fusion.Component:
projectedEntities = sketch3.project(entities)
entities.append(selectedObj)
elif type(selectedObj) is adsk.fusion.Occurrence:
entities.append(selectedObj.component)
return entities
Another example code I have looked at is the 'Project to Surface API' example, but again this uses bodies and componenets created by the code itself rather than selected by the user. I am new to this so any explanation would be appreciated.
Solved! Go to Solution.