<?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 determine a directionPoint to offset an arbitrary sketch loop inwards in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6432753#M19599</link>
    <description>&lt;P&gt;Hi Jack,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried your suggestion and it worked well for a profile where the centroid is inside the profile but fails for profiles where the centroid is outside the profile, see the attached profile. Looks like we still need AreaPoperties methods to get points inside and outside a profile?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rod.&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/254632iAC465744ED5E2E72/image-size/medium?v=v2&amp;amp;px=-1" border="0" alt="Screen Shot 2016-07-12 at 6.06.14 PM.png" title="Screen Shot 2016-07-12 at 6.06.14 PM.png" align="left" /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jul 2016 01:15:29 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-07-13T01:15:29Z</dc:date>
    <item>
      <title>How to determine a directionPoint to offset an arbitrary sketch loop inwards?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6413750#M19593</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Am working on a program to offset outside loops in a sketch outward and offset inside loops inwards. I can imagine being able to get the max/min x &amp;amp; y values for the sketch curves that make up the loop and use this info to pick a directionPoint outside the loop pretty easily.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm confused as to how best find a directionPoint inside an arbitrary loop? Any help much appreciated!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thx,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Rod.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2016 21:05:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6413750#M19593</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-06-30T21:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine a directionPoint to offset an arbitrary sketch loop inwards</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6421736#M19594</link>
      <description>&lt;P&gt;Any takers? I'm still stuck on finding a point inside an arbitrary sketch profile, or loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thx,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rod.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2016 15:44:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6421736#M19594</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-07-06T15:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine a directionPoint to offset an arbitrary sketch loop inwards</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6423660#M19595</link>
      <description>Hi Rod,

There is no simple way to do it now. A workaround might be extruding the profile into a body, then find a point inside the top face of the body by modifying the code in the following posts:

&lt;A href="http://forums.autodesk.com/t5/api-and-scripts/extrude-some-profiles/td-p/6404721" target="_blank"&gt;http://forums.autodesk.com/t5/api-and-scripts/extrude-some-profiles/td-p/6404721&lt;/A&gt;
&lt;A href="http://modthemachine.typepad.com/my_weblog/2016/05/is-point-on-face.html" target="_blank"&gt;http://modthemachine.typepad.com/my_weblog/2016/05/is-point-on-face.html&lt;/A&gt;

The projection of that point onto the sketch plane will be the point you want.

You might also want to request an API to do it in  IdeaStation: &lt;A href="http://forums.autodesk.com/t5/fusion-360-ideastation-request-a/idb-p/125" target="_blank"&gt;http://forums.autodesk.com/t5/fusion-360-ideastation-request-a/idb-p/125&lt;/A&gt;</description>
      <pubDate>Thu, 07 Jul 2016 13:46:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6423660#M19595</guid>
      <dc:creator>ShirleyShi</dc:creator>
      <dc:date>2016-07-07T13:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine a directionPoint to offset an arbitrary sketch loop inwards</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6424822#M19596</link>
      <description>&lt;P&gt;Hi Shirley,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the response, it's helps to know I wasn't missing an easy way to do this. That's is quite the workaround for what should be a simple task, I'll try the workaround and I'll submit an idea station request for sure!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rod.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2016 23:44:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6424822#M19596</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-07-07T23:44:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine a directionPoint to offset an arbitrary sketch loop inwards</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6425999#M19597</link>
      <description>&lt;P&gt;IdeaStation request posted....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://forums.autodesk.com/t5/ideastation-request-a-feature-or/api-an-easy-way-to-offset-a-sketch-loop-inward-vs-outward/idi-p/6424833" target="_blank"&gt;http://forums.autodesk.com/t5/ideastation-request-a-feature-or/api-an-easy-way-to-offset-a-sketch-loop-inward-vs-outward/idi-p/6424833&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2016 16:26:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6425999#M19597</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-07-08T16:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine a directionPoint to offset an arbitrary sketch loop inwards</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6430452#M19598</link>
      <description>&lt;P&gt;You can get the centroid&amp;nbsp;of a profile by querying AreaProperties. The following script demo how to get the centroid&amp;nbsp;of a profile.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)

        # Get the root component of the active design
        rootComp = design.rootComponent
        
        # Get one profile
        sketches = rootComp.sketches
        sketch = sketches[0]
        prof = sketch.profiles[0]
        
        # Get area properties from a profile
        areaProps = prof.areaProperties(adsk.fusion.CalculationAccuracy.MediumCalculationAccuracy)
        
        # Get centroid
        centroid = areaProps.centroid
        
        ui.messageBox('{}, {}, {}'.format(centroid.x, centroid.y, centroid.z))

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Jack&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 02:13:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6430452#M19598</guid>
      <dc:creator>liujac</dc:creator>
      <dc:date>2016-07-12T02:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine a directionPoint to offset an arbitrary sketch loop inwards</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6432753#M19599</link>
      <description>&lt;P&gt;Hi Jack,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried your suggestion and it worked well for a profile where the centroid is inside the profile but fails for profiles where the centroid is outside the profile, see the attached profile. Looks like we still need AreaPoperties methods to get points inside and outside a profile?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rod.&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/254632iAC465744ED5E2E72/image-size/medium?v=v2&amp;amp;px=-1" border="0" alt="Screen Shot 2016-07-12 at 6.06.14 PM.png" title="Screen Shot 2016-07-12 at 6.06.14 PM.png" align="left" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 01:15:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6432753#M19599</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-07-13T01:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine a directionPoint to offset an arbitrary sketch loop inwards</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6432803#M19600</link>
      <description>&lt;P&gt;Right.&amp;nbsp;The geometric centroid of a convex object always lies in the object. A non-convex object might have a centroid that is outside the figure itself. It's easy to find a point outside the profile as your mentioned. We still need to add method to get a point inside a profile.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Jack&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 02:25:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6432803#M19600</guid>
      <dc:creator>liujac</dc:creator>
      <dc:date>2016-07-13T02:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine a directionPoint to offset an arbitrary sketch loop inwards</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6445402#M19601</link>
      <description>&lt;P&gt;This is a little bit elaborate but in my testing so far, it works in all cases.&amp;nbsp; I've attached the script too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        # Get the active sketch.
        sk = adsk.fusion.Sketch.cast(app.activeEditObject)
        
        pnt = None
        if sk:
            # Get all of the curves in the sketch and add them to a collection.
            # This is the same set of curves that will be input to the offset method.
            skCurves = adsk.core.ObjectCollection.create()
            skCurve = adsk.fusion.SketchCurve.cast(None)
            for skCurve in sk.sketchCurves:
                skCurves.add(skCurve)

            # Get a point in the "inside" of the curves.                
            pnt = getPointInClosedCurves(skCurves)
        
        if pnt:
            # Create a sketch point so the result is visible.
            sk.sketchPoints.add(pnt)
            ui.messageBox('Sketch point created in the area of the sketch curves')
        else:
            ui.messageBox('No point was found.')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


# Function that calculates a point that is "inside" the set of input curves.
def getPointInClosedCurves(skCurves):
    try:
        # Build up list of connected points.
        curve = adsk.fusion.SketchCurve.cast(None)
        pointSets = []
        boundBox = None
        for curve in skCurves:
            if not boundBox:
                boundBox = curve.boundingBox
            else:
                boundBox.combine(curve.boundingBox)            
                
            if isinstance(curve, adsk.fusion.SketchLine):
                skLine = adsk.fusion.SketchLine.cast(curve)
                pointSets.append((skLine.startSketchPoint.geometry, skLine.endSketchPoint.geometry))
            else:
                curveEval = adsk.core.CurveEvaluator3D.cast(curve.geometry.evaluator)
                (retVal, startParam, endParam) = curveEval.getParameterExtents()
                
                (retVal, strokePoints) = curveEval.getStrokes(startParam, endParam, 0.1)
                pointSets.append(strokePoints)
            
        # Create two points that define a line that crosses the entire range.  They're moved
        # to be outside the bounding box so there's not problem with coincident points.
        lineVec = boundBox.minPoint.vectorTo(boundBox.maxPoint)
        lineVec.normalize()
        maxPoint = boundBox.maxPoint.copy()
        maxPoint.translateBy(lineVec)
        lineVec.scaleBy(-1)
        minPoint = boundBox.minPoint.copy()
        minPoint.translateBy(lineVec)
    
        # Iterate through all of the lines and get the intersection between the lines
        # and the long crossing line.
        intPointList = []
        for pointSet in pointSets:
            pnt1 = None
            pnt2 = None
            for point in pointSet:
                if not pnt2:
                    pnt2 = point
                else:
                    pnt1 = pnt2
                    pnt2 = point
    
                    intCoords = getLineIntersection(minPoint.x, minPoint.y, maxPoint.x, maxPoint.y, pnt1.x, pnt1.y, pnt2.x, pnt2.y)
                    if intCoords:
                        intPoint = adsk.core.Point3D.create(intCoords[0], intCoords[1], 0)
                        intPointList.append((intPoint, intPoint.distanceTo(minPoint)))
        
        # Make sure at last two intersection points were found.
        if len(intPointList) &amp;gt;= 2:
            # Sort the points by the distance from the min point.
            sortedPoints = sorted(intPointList, key=getKey) 
        
            # Get the first two points and compute a mid point.  That's a point in the area.                
            pnt1 = sortedPoints[0]
            pnt2 = sortedPoints[1]
            midPoint = adsk.core.Point3D.create((pnt1[0].x + pnt2[0].x)/2, (pnt1[0].y + pnt2[0].y)/2, 0)
            return midPoint
        else:
            return False
    except:
        ui = adsk.core.Application.get().userInterface
        ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
    
                                
# Function that's used to get the value to sort with.
def getKey(item):
    return item[1]

                
# Calculate the intersection between two line segments.  This is based on the JS
# sample in the second answer at:
# http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect
def getLineIntersection(p0_x, p0_y, p1_x, p1_y, p2_x, p2_y, p3_x, p3_y):
    s1_x = p1_x - p0_x
    s1_y = p1_y - p0_y
    s2_x = p3_x - p2_x
    s2_y = p3_y - p2_y

    s = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) / (-s2_x * s1_y + s1_x * s2_y)
    t = ( s2_x * (p0_y - p2_y) - s2_y * (p0_x - p2_x)) / (-s2_x * s1_y + s1_x * s2_y)

    if (s &amp;gt;= 0 and s &amp;lt;= 1 and t &amp;gt;= 0 and t &amp;lt;= 1):
        # Collision detected
        i_x = p0_x + (t * s1_x)
        i_y = p0_y + (t * s1_y)
        return (i_x, i_y)

    return False  # No collision&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2016 17:29:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6445402#M19601</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2016-07-18T17:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine a directionPoint to offset an arbitrary sketch loop inwards</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6520998#M19602</link>
      <description>&lt;P&gt;Thanks Brian!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been away from this for a while, will check out your workaround and report back.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rod.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2016 20:27:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-determine-a-directionpoint-to-offset-an-arbitrary-sketch/m-p/6520998#M19602</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-24T20:27:06Z</dc:date>
    </item>
  </channel>
</rss>

