Construction Point and Selection of circular face of extruded body
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone, I am getting a little desperate.
I have a script, which creates an extruded body based on a circular sketch on a selected plane. That works so far. After that, I want to make a construction point in the center at the top face of my extrusion and select this face for later, in order to align it to another circular face.
My problem is, that I always get the following error when trying to construct the point:
...line 110, in createdockingObject
center_point = constructionPoints.add(pointInput)
File "C:\Users/julia/AppData/Local/Autodesk/webdeploy/production/19107935ce2ad08720646cb4a31efe37d8a5f41b/Api/Python/packages\adsk\fusion.py", line 13404, in add
return _fusion.ConstructionPoints_add(self, input)
RuntimeError: 2 : InternalValidationError : data_->execute(&obj, apiName) && obj
It works, when I use the sketch circle. And I tried it with the circular face, using the startFace Property of the extrusion, the circular edge. It doesn't work...
Then I also try to use the ui.activeSelections.add command to select the circular face or the edge to use it. In this case, I get the following error:
...line 118, in createdockingObject
ui.activeSelections.add(circularFace)
File "C:\Users/julia/AppData/Local/Autodesk/webdeploy/production/19107935ce2ad08720646cb4a31efe37d8a5f41b/Api/Python/packages\adsk\core.py", line 14956, in add
return _core.Selections_add(self, entity)
RuntimeError: 3 : invalid argument entity
Here is the main code part. I also upload the whole script.
def createNewComponent():
# Get the active design.
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
rootComp = design.rootComponent
allOccs = rootComp.occurrences
newOcc = allOccs.addNewComponent(adsk.core.Matrix3D.create())
return newOcc.component
def createdockingObject(entities_plane, entities_point):
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
if not design:
ui.messageBox('It is not supported in current workspace, please change to MODEL workspace and try again.')
return
currentDesignType = design.designType
global newComp
newComp = createNewComponent()
if newComp is None:
ui.messageBox('New component failed to create', 'New Component Failed')
return
newComp.name = 'basePlate'
#get selected plane
plane = entities_plane[0].name
plane = entities_plane[0]
# add sketch
sketches = newComp.sketches
sketch = sketches.add(plane)
sketch.name = 'basePlateSketch'
#get selected point
point = entities_point[0]
point_align = point.geometry
#ui.messageBox('Punkt ausgewählt')
# add circle as sketch curves
circles = sketch.sketchCurves.sketchCircles
#circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(point_align.x, -point_align.z, point_align.y), 0.8)
circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), 0.8)
# Get the profile defined by the circle.
prof = sketch.profiles.item(0)
# Define that the extent is a distance extent of 2.5 mm.
distance = adsk.core.ValueInput.createByReal(0.25)
# Create the extrusion.
extrudes = newComp.features.extrudeFeatures
ext = extrudes.addSimple(prof, distance, adsk.fusion.FeatureOperations.NewComponentFeatureOperation)
body = ext.bodies.item(0)
#get circular face or edge for selection and set constructionPoint by center
edges = body.edges.count
circularEdge = body.edges.item(0)
#par = ext.parentComponent
startFacesObj = ext.startFaces
startFaceCenter = startFacesObj.item(0).centroid
ext.name = 'basePlateBody'
#ui.messageBox('bodies Base Plate' + str(ext.bodies.count))
# get circluar face
circularFace = None
for face in body.faces:
geom = face.geometry
face1 = face
if geom.surfaceType == adsk.core.SurfaceTypes.CylinderSurfaceType:
circularFace = face
#ui.messageBox('Circular Face')
break
#foundFaces = newComp.findBRepUsingPoint(point, adsk.fusion.BRepEntityTypes.BRepFaceEntityType)
constructionPoints = newComp.constructionPoints
#creating construction point in the center of the circular face
pointInput = constructionPoints.createInput()
#it works with the sketch circle
#pointInput.setByCenter(circle1)
#it does not work with the circular face or the edge??
#pointInput.setByCenter(circularFace)
#pointInput.setByCenter(circularEdge)
#pointInput.setByPoint(startFaceCenter)
#center_point = constructionPoints.add(pointInput)
#trying to select the face or circular edge: doesn't work
ui.activeSelections.clear()
# tried different things:
#ui.activeSelections.add(circularEdge)
#ui.activeSelections.add(body)
#ui.activeSelections.add(center_point)
ui.activeSelections.add(circularFace)
alignCommand = ui.commandDefinitions.itemById('FusionMoveCommand')
alignCommand.execute()
I hope, anyone can help me. Thank you in advance.