Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am working on an add-in that generates a sketch with a clean projected body outline to a selected face which is then used later in the program. I am seeing an issue where if the selected face/body is in a component that does not have the same origin orientation as root the projected body is created at the wrong projection angle/plane orientation.
Code is below as well as images showing the correct and incorrect behavior I am seeing. I suspect that my issue is coming from the section where I create the plane to project the body to and has something to do with an incorrect/missing assembly context, but am unsure how to correct for it. Anyone have any ideas?
Thanks!
# Function to create clean sketch of outer profile on face
# INPUTS: Selected face entity
# CREATES: Sketch w/ outer profile
# RETURNS: Collection of profile curves making up outer profile
def create_outline_sketch(
input_face: adsk.fusion.BRepFace):
# Create sketch on input surface plane to house outline profile made by projected edges
sk_face_outline: adsk.fusion.Sketch = input_face.body.parentComponent.sketches.addWithoutEdges(input_face)
sk_face_outline.name = 'Face Outline Sketch'
tempbr_manager = adsk.fusion.TemporaryBRepManager.get() # Get temp geometry manager
temp_face = tempbr_manager.copy(input_face).faces[0]
currPointonFace = temp_face.pointOnFace
currGeomNorm = temp_face.geometry.evaluator.getNormalAtPoint(currPointonFace)[1]
currPlane = adsk.core.Plane.create(currPointonFace, currGeomNorm)
temp_outline_body = tempbr_manager.createProjectedBodyOutline(input_face.body, currPlane, 0.000001) # Create temp body from face
if temp_outline_body[1]:
futil.log("Contains approximation")
proj_feat = input_face.body.parentComponent.features.baseFeatures.add()
proj_feat.startEdit()
outline_body = input_face.body.parentComponent.bRepBodies.add(temp_outline_body[0], proj_feat) # Create body from temp face body
proj_feat.finishEdit()
sk_new_face_outline: adsk.fusion.Sketch = input_face.body.parentComponent.sketches.addWithoutEdges(input_face)
sk_new_face_outline.name = 'Temp Brep Outline Sketch'
sketch_trash = adsk.core.ObjectCollection.create()
sk_new_face_outline.project(outline_body.faces[0])
# Sort profiles with outer profile loop
if sk_new_face_outline.profiles.count > 0:
for profy in sk_new_face_outline.profiles:
for luup in profy.profileLoops:
if not luup.isOuter:
for profCurv in luup.profileCurves:
sketch_trash.add(profCurv.sketchEntity)
for item in sketch_trash:
item.deleteMe()
outline_profilecurvs = sk_new_face_outline.profiles.item(0).profileLoops.item(0).profileCurves
clean_curves_coll = adsk.core.ObjectCollection.create()
for profCurv in outline_profilecurvs:
clean_curves_coll.add(profCurv.sketchEntity)
return clean_curves_coll, sk_new_face_outline
Solved! Go to Solution.