Trouble Creating Copy of Correct Face In Subassembly Using TemporaryBRepManager

Trouble Creating Copy of Correct Face In Subassembly Using TemporaryBRepManager

alden_360
Contributor Contributor
275 Views
2 Replies
Message 1 of 3

Trouble Creating Copy of Correct Face In Subassembly Using TemporaryBRepManager

alden_360
Contributor
Contributor

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

 

alden_360_0-1739548490994.png

 

0 Likes
Accepted solutions (1)
276 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor
Accepted solution

I'm not sure I fully understand what you're trying to accomplish. I did try running your code, though, and I made a small change that gives consistent results, but I'm not sure it's the results you're looking for. Try adding the two lines below to the beginning of the function and see if that solves the problem.

def create_outline_sketch(input_face: adsk.fusion.BRepFace):
    if input_face.nativeObject:
        input_face = input_face.nativeObject

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3

alden_360
Contributor
Contributor

Hi @BrianEkins, thanks for the tip, I think that accomplished exactly what I was trying to do!

 

In looking at the documentation am I correct in understanding that BRepFace.nativeObject returns the face in the context of its parent component as opposed to the context of the full assembly (if it isn't root)? Aka, my code was working properly when the face was part of the root object because it was already working within the correct context, but did not work within subassemblies with different coordinate systems because the face was still being referenced in the context of the root component?

 

Best,

Alden

0 Likes