<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to create a three point construction plane in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-create-a-three-point-construction-plane/m-p/5837977#M20753</link>
    <description>&lt;P&gt;Can you please provide code snippet (or point to some sample) of how to create custom construction plane?&lt;/P&gt;&lt;P&gt;As you mentioned, if Point3D is not the right input, I may convert them to ConstructionPoints first and then supply them for constructing plane.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just need sample code to see how any custom construction entity is created.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2015 03:10:06 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2015-09-30T03:10:06Z</dc:date>
    <item>
      <title>How to create a three point construction plane</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-create-a-three-point-construction-plane/m-p/5836958#M20751</link>
      <description>&lt;P&gt;I could not find any sample/example for creating a custom constrction plane, say, by three point method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is trying to create a Sweep feature.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://forums.autodesk.com/t5/image/serverpage/image-id/191370iFDF24697FC979447/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="NeedThreePointConstructionPlane.png" title="NeedThreePointConstructionPlane.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the code is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    def getThicknessFaceEdge(self,edge):
        face1 = edge.faces[0]        
        face2 = edge.faces[1]
        thicknessFace = None
        thicknessEdge = None
        if face1.evaluator.area &amp;gt; 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&lt;/PRE&gt;&lt;P&gt;Please have a look at this code and suggest improvements as well.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2015 14:11:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-create-a-three-point-construction-plane/m-p/5836958#M20751</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-09-29T14:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a three point construction plane</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-create-a-three-point-construction-plane/m-p/5837803#M20752</link>
      <description>&lt;P&gt;If you've tried creating&amp;nbsp;a construction plane using the three points that you reference in the comment, it won't work.&amp;nbsp; Construction plane creation is parametric so it needs real geometry as input so it can track that geometry and update if it changes.&amp;nbsp;In the case of a three point construction plane, valid input is&amp;nbsp;another ConstructionPoint, a SketchPoint or a BRepVertex.&amp;nbsp; You're trying to use a Point3D object which is just a coordinate in space and not a point based entity.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2015 22:12:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-create-a-three-point-construction-plane/m-p/5837803#M20752</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2015-09-29T22:12:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a three point construction plane</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-create-a-three-point-construction-plane/m-p/5837977#M20753</link>
      <description>&lt;P&gt;Can you please provide code snippet (or point to some sample) of how to create custom construction plane?&lt;/P&gt;&lt;P&gt;As you mentioned, if Point3D is not the right input, I may convert them to ConstructionPoints first and then supply them for constructing plane.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just need sample code to see how any custom construction entity is created.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 03:10:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-create-a-three-point-construction-plane/m-p/5837977#M20753</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-09-30T03:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a three point construction plane</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-create-a-three-point-construction-plane/m-p/5841324#M20754</link>
      <description>&lt;P&gt;Here's some code that I believe is close to what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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 &amp;lt; 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()))
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2015 21:04:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-create-a-three-point-construction-plane/m-p/5841324#M20754</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2015-10-01T21:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a three point construction plane</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-create-a-three-point-construction-plane/m-p/5841353#M20755</link>
      <description>&lt;P&gt;A note about the previous program.&amp;nbsp; The construction plane it's creating is between the two points defined by the side edge and the new point that was calculated.&amp;nbsp; The new point is created at a point in space and is not parametric.&amp;nbsp; 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.&amp;nbsp; I did figure out a way after i wrote that code of a way of creating the point in a parametric way.&amp;nbsp; The steps are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Create a construction line that is perpendicular to the side face and through either the start or end point of the side edge.&lt;/LI&gt;
&lt;LI&gt;Create a construction plane through two lines using the side edge and the construction line.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Now you should be able to make changes to the model and the construction plane will recompute correctly.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2015 21:25:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-create-a-three-point-construction-plane/m-p/5841353#M20755</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2015-10-01T21:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a three point construction plane</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-create-a-three-point-construction-plane/m-p/5843651#M20756</link>
      <description>&lt;P&gt;Thanks a lot Brian. I implemented based on your code suggestions and it worked fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is how it looks:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://forums.autodesk.com/t5/image/serverpage/image-id/192257i9606DCBB4CA5FD1D/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="FlangeCreated.png" title="FlangeCreated.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your latest post had suggestion on creating constructionLine first, which I tried but had some problems. Will look at that later.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the latest code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    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)&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Oct 2015 14:40:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-create-a-three-point-construction-plane/m-p/5843651#M20756</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-10-03T14:40:49Z</dc:date>
    </item>
  </channel>
</rss>

