How to create a three point construction plane

How to create a three point construction plane

Anonymous
Not applicable
1,122 Views
5 Replies
Message 1 of 6

How to create a three point construction plane

Anonymous
Not applicable

I could not find any sample/example for creating a custom constrction plane, say, by three point method.

 

My code is trying to create a Sweep feature.

 

NeedThreePointConstructionPlane.png

 

And the code is:

 

    def getThicknessFaceEdge(self,edge):
        face1 = edge.faces[0]        
        face2 = edge.faces[1]
        thicknessFace = None
        thicknessEdge = None
        if face1.evaluator.area > face2.evaluator.area:
            thicknessFace = face2;
        else:
            thicknessFace = face1;
            
        thicknessEdge = thicknessFace.edges.item(1) # hardcoded, but need to search for next/smaller edge, TBD
        return (thicknessFace, thicknessEdge);
        
    def getFaceNormal(self,face):
        pt = face.pointOnFace() # Some ERROR here..hmmm
        (returnValue, normal) = face.evaluator.getNormalAtPoint(pt)
        return normal;
        
    def Execute(self, selectedEdge):
 
        if not isinstance(selectedEdge,adsk.fusion.BRepEdge):
            return;

        doc = app.activeDocument
        d = doc.design
        rootComp = d.rootComponent
        
        (thkFc, thkEd) = self.getThicknessFaceEdge(selectedEdge)
        (returnValue, startSelEdPoint, endSelEdPoint) = selectedEdge.evaluator.getEndPoints()
        thckFcNormal = self.getFaceNormal(thkFc)
        thckFcNormal.scaleBy(4) # some hardcoded value for now TBD, Take it from UI later
        
        (returnValue, startThkEdPoint, endThkEdPoint) = thkEd.evaluator.getEndPoints()
        startThkNormalEndPoint = startThkEdPoint.copy
        startThkNormalEndPoint.trabslateBy(thckFcNormal)
        sketches = rootComp.sketches
        profileSketch = sketches.add(thkFc)
        profileSketch.project(thkFc)
        
        # need a construction Plane passing through startThkEdPoint, endThkEdPoint, startThkNormalEndPoint
        # TBD
        
        # create a new pathSketch on the constructionPlane
        # TBD
        
        # Create Sweep using profileSketch and the pathSketch
        # TBD

Please have a look at this code and suggest improvements as well.

0 Likes
1,123 Views
5 Replies
Replies (5)
Message 2 of 6

ekinsb
Alumni
Alumni

If you've tried creating a construction plane using the three points that you reference in the comment, it won't work.  Construction plane creation is parametric so it needs real geometry as input so it can track that geometry and update if it changes. In the case of a three point construction plane, valid input is another ConstructionPoint, a SketchPoint or a BRepVertex.  You're trying to use a Point3D object which is just a coordinate in space and not a point based entity.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 6

Anonymous
Not applicable

Can you please provide code snippet (or point to some sample) of how to create custom construction plane?

As you mentioned, if Point3D is not the right input, I may convert them to ConstructionPoints first and then supply them for constructing plane.

 

I just need sample code to see how any custom construction entity is created.

0 Likes
Message 4 of 6

ekinsb
Alumni
Alumni

Here's some code that I believe is close to what you want.

 

import adsk.core, adsk.fusion, traceback
import math

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        edgeSelect = ui.selectEntity('Select the edge for the flange', 'LinearEdges')
        if not edgeSelect:
            return
                    
        edge = adsk.fusion.BRepEdge.cast(edgeSelect.entity)

        # Get the area of the faces that the edge connects.  Assume
        # that the smallest face is an edge face.
        if edge.faces.item(0).evaluator.area < edge.faces.item(1).evaluator.area:
            edgeFace = edge.faces.item(0)
        else:
            edgeFace = edge.faces.item(1)
            
        # Get one of the small edges on the edge face.
        if edge.coEdges.item(0).loop.face == edgeFace:
            coEdge = edge.coEdges.item(0)
        else:
            coEdge = edge.coEdges.item(1)

        sideEdge = coEdge.next.edge

        # Create a non-parametric construction point in space, along the normal of the face.
        (result, normal) = edgeFace.evaluator.getNormalAtPoint(edgeFace.pointOnFace)
        newPoint = sideEdge.startVertex.geometry
        newPoint.translateBy(normal)

        des = adsk.fusion.Design.cast(app.activeProduct)        
        root = des.rootComponent
        
        constPointInput = root.constructionPoints.createInput()        
        constPointInput.setByPoint(newPoint)
        constPoint = root.constructionPoints.add(constPointInput)
        
        constPlaneInput = root.constructionPlanes.createInput()
        constPlaneInput.setByThreePoints(constPoint, sideEdge.startVertex, sideEdge.endVertex)
        constPlane = root.constructionPlanes.add(constPlaneInput)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 6

ekinsb
Alumni
Alumni

A note about the previous program.  The construction plane it's creating is between the two points defined by the side edge and the new point that was calculated.  The new point is created at a point in space and is not parametric.  This means that if the model changes in a way where the edge moves, the work plane will no longer be positioned correctly because the point did not recalculate.  I did figure out a way after i wrote that code of a way of creating the point in a parametric way.  The steps are:

 

  1. Create a construction line that is perpendicular to the side face and through either the start or end point of the side edge.
  2. Create a construction plane through two lines using the side edge and the construction line.

Now you should be able to make changes to the model and the construction plane will recompute correctly.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 6 of 6

Anonymous
Not applicable

Thanks a lot Brian. I implemented based on your code suggestions and it worked fine.

 

Here is how it looks:

 

FlangeCreated.png

 

Your latest post had suggestion on creating constructionLine first, which I tried but had some problems. Will look at that later.

 

Here is the latest code:

 

    def Execute(self, selectedEdge):
 
        if not isinstance(selectedEdge,adsk.fusion.BRepEdge):
            return;

        doc = app.activeDocument
        d = doc.design
        rootComp = d.rootComponent
        
        (thkFc, thkEd) = self.getThicknessFaceEdge(selectedEdge)
        
        newPoint1 = thkEd.startVertex.geometry
        print(newPoint1.x, newPoint1.y, newPoint1.z)

        newPoint2 = thkEd.endVertex.geometry
        print(newPoint2.x, newPoint2.y, newPoint2.z)
        
        thkEdVector = adsk.core.Vector3D.create(newPoint1.x - newPoint2.x,newPoint1.y - newPoint2.y,newPoint1.z - newPoint2.z)
        length = thkEdVector.length
        print(length, thkEdVector.x, thkEdVector.y, thkEdVector.z)
  
        normal = self.getFaceNormal(thkFc)
        newPoint1.translateBy(normal)
              
        newPoint3 = adsk.core.Point3D.create(newPoint1.x ,newPoint1.y,newPoint1.z)
        thkEdVector.scaleBy(5)
        newPoint3.translateBy(thkEdVector)
        print(newPoint3.x, newPoint3.y, newPoint3.z)
        
        # create a workpoint for newpoint which is the 3rd point for plane
        constructionPointInput = rootComp.constructionPoints.createInput()
        constructionPointInput.setByPoint(newPoint1)
        constructionPoint1 = rootComp.constructionPoints.add(constructionPointInput)
        
        constructionPointInput.setByPoint(newPoint3)
        constructionPoint3 = rootComp.constructionPoints.add(constructionPointInput)
        
#        constructionLineInput = rootComp.constructionAxes.createInput()
#        constructionLineInput.setByTwoPoints(thkEd.startVertex, newPoint3)
#        constructionLine = rootComp.constructionAxes.add(constructionLineInput)
        
        constructionPlaneInput = rootComp.constructionPlanes.createInput()
        constructionPlaneInput.setByThreePoints(constructionPoint1, thkEd.startVertex, thkEd.endVertex)
        #constructionPlaneInput.setByTwoEdges(thkEd,constructionLine)
        constructionPlane = rootComp.constructionPlanes.add(constructionPlaneInput)
        
        sketches = rootComp.sketches
        profileSketch = sketches.add(thkFc)
        profileSketch.project(thkFc)
        
        pathSketch = sketches.add(constructionPlane)
        projections = pathSketch.project(thkEd.startVertex)
        sketchPoint1 = projections.item(0)
        projections = pathSketch.project(constructionPoint1)
        sketchPoint2 = projections.item(0)
        projections = pathSketch.project(constructionPoint3)
        sketchPoint3 = projections.item(0)        
        
        sketchLine1 = pathSketch.sketchCurves.sketchLines.addByTwoPoints(sketchPoint1, sketchPoint2)
        sketchLine2 = pathSketch.sketchCurves.sketchLines.addByTwoPoints(sketchPoint2, sketchPoint3)
        arc = pathSketch.sketchCurves.sketchArcs.addFillet(sketchLine1, sketchLine1.endSketchPoint.geometry, sketchLine2, sketchLine2.startSketchPoint.geometry, length/2.0)
        
        prof = profileSketch.profiles.item(0)
        path = rootComp.features.createPath(sketchLine1)

        sweeps = rootComp.features.sweepFeatures
        sweepInput = sweeps.createInput(prof, path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)

        sweep = sweeps.add(sweepInput)
0 Likes