<?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 Python script to create a chain of lines in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-script-to-create-a-chain-of-lines/m-p/7518674#M17309</link>
    <description>&lt;P&gt;Code below is a script example.&lt;/P&gt;&lt;P&gt;Suppose I want lines between the points instead of the spline line, how would I do that?&lt;/P&gt;&lt;P&gt;Do I have to individually name all the little lines or can I make some kind of line collection?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try: 
        app = adsk.core.Application.get()
        ui = app.userInterface

        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        design = app.activeProduct

        # Get the root component of the active design.
        rootComp = design.rootComponent

        # Create a new sketch on the xy plane.
        sketch = rootComp.sketches.add(rootComp.xYConstructionPlane)

        # Create an object collection for the points.
        points = adsk.core.ObjectCollection.create()

        # Define the points the spline with fit through.
        points.add(adsk.core.Point3D.create(0, 0, 0))
        points.add(adsk.core.Point3D.create(5, 1, 0))
        points.add(adsk.core.Point3D.create(6, 4, 3))
        points.add(adsk.core.Point3D.create(7, 6, 6))
        points.add(adsk.core.Point3D.create(2, 3, 0))
        points.add(adsk.core.Point3D.create(0, 1, 0))

        # Create the spline.
        sketch.sketchCurves.sketchFittedSplines.add(points)
    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;</description>
    <pubDate>Sun, 05 Nov 2017 22:36:25 GMT</pubDate>
    <dc:creator>cadTPLWJ</dc:creator>
    <dc:date>2017-11-05T22:36:25Z</dc:date>
    <item>
      <title>Python script to create a chain of lines</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-script-to-create-a-chain-of-lines/m-p/7518674#M17309</link>
      <description>&lt;P&gt;Code below is a script example.&lt;/P&gt;&lt;P&gt;Suppose I want lines between the points instead of the spline line, how would I do that?&lt;/P&gt;&lt;P&gt;Do I have to individually name all the little lines or can I make some kind of line collection?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try: 
        app = adsk.core.Application.get()
        ui = app.userInterface

        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        design = app.activeProduct

        # Get the root component of the active design.
        rootComp = design.rootComponent

        # Create a new sketch on the xy plane.
        sketch = rootComp.sketches.add(rootComp.xYConstructionPlane)

        # Create an object collection for the points.
        points = adsk.core.ObjectCollection.create()

        # Define the points the spline with fit through.
        points.add(adsk.core.Point3D.create(0, 0, 0))
        points.add(adsk.core.Point3D.create(5, 1, 0))
        points.add(adsk.core.Point3D.create(6, 4, 3))
        points.add(adsk.core.Point3D.create(7, 6, 6))
        points.add(adsk.core.Point3D.create(2, 3, 0))
        points.add(adsk.core.Point3D.create(0, 1, 0))

        # Create the spline.
        sketch.sketchCurves.sketchFittedSplines.add(points)
    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;</description>
      <pubDate>Sun, 05 Nov 2017 22:36:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-script-to-create-a-chain-of-lines/m-p/7518674#M17309</guid>
      <dc:creator>cadTPLWJ</dc:creator>
      <dc:date>2017-11-05T22:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to create a chain of lines</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-script-to-create-a-chain-of-lines/m-p/7519340#M17310</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is no API to create a chain of lines like what we create spline. However you should be able to create the lines one by one. Please refer to the codes as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try: 
        app = adsk.core.Application.get()
        ui = app.userInterface

        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        design = app.activeProduct

        # Get the root component of the active design.
        rootComp = design.rootComponent

        # Create a new sketch on the xy plane.
        sketch = rootComp.sketches.add(rootComp.xYConstructionPlane)

        # Create an object collection for the points.
        points = adsk.core.ObjectCollection.create()

        # Define the points the spline with fit through.
        points.add(adsk.core.Point3D.create(0, 0, 0))
        points.add(adsk.core.Point3D.create(5, 1, 0))
        points.add(adsk.core.Point3D.create(6, 4, 3))
        points.add(adsk.core.Point3D.create(7, 6, 6))
        points.add(adsk.core.Point3D.create(2, 3, 0))
        points.add(adsk.core.Point3D.create(0, 1, 0))

        for i in range(points.count-1):
            pt1 = points.item(i)
            pt2 = points.item(i+1)
            sketch.sketchCurves.sketchLines.addByTwoPoints(pt1, pt2)
        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Marshal&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2017 08:35:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-script-to-create-a-chain-of-lines/m-p/7519340#M17310</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-11-06T08:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to create a chain of lines</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-script-to-create-a-chain-of-lines/m-p/7520962#M17311</link>
      <description>&lt;P&gt;The code that Marshal gave you is good and will work.&amp;nbsp; However, the result may be slightly different than what you expect.&amp;nbsp; It creates five completely independent lines.&amp;nbsp; Their endpoints happen to be at the same coordinate but if you use the mouse to drag one of the end points you'll find that the lines are not connected.&amp;nbsp; Here's a slight change to the above code so that existing sketch points are used to create the new lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        for i in range(points.count-1):
            if i == 0:
                pt1 = points.item(i)
            else:
                pt1 = lastLine.endSketchPoint

            pt2 = points.item(i+1)
            lastLine = sketch.sketchCurves.sketchLines.addByTwoPoints(pt1, pt2)
&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Nov 2017 17:36:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-script-to-create-a-chain-of-lines/m-p/7520962#M17311</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2017-11-06T17:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to create a chain of lines</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-script-to-create-a-chain-of-lines/m-p/7521657#M17312</link>
      <description>&lt;P&gt;Same code for a closed polygon:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    lines = sketch.sketchCurves.sketchLines

    pt1 = points.item(0)
    pt2 = points.item(1)
    firstLine = lines.addByTwoPoints(pt1, pt2)
    lastLine = firstLine

    for i in range(1,points.count-1):
        pt1 = lastLine.endSketchPoint
        pt2 = points.item(i+1)
        lastLine = lines.addByTwoPoints(pt1, pt2)

    pt1 = lastLine.endSketchPoint
    pt2 = firstLine.startSketchPoint
    lines.addByTwoPoints(pt1, pt2)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2017 21:23:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-script-to-create-a-chain-of-lines/m-p/7521657#M17312</guid>
      <dc:creator>JeromeBriot</dc:creator>
      <dc:date>2017-11-06T21:23:25Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to create a chain of lines</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-script-to-create-a-chain-of-lines/m-p/9351794#M17313</link>
      <description>&lt;P&gt;Hi Brian,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is cool...it works, but could you explain what's happening, I try to wrap my head around it but I'm having a hard time.&lt;/P&gt;&lt;P&gt;Let's say I was trying to make a sketch of a closed square. I wrote this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;points = adsk.core.ObjectCollection.create()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;points.add(adsk.core.Point3D.create(0,0,0))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;points.add(adsk.core.Point3D.create(0,2,0))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;points.add(adsk.core.Point3D.create(2,2,0))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;points.add(adsk.core.Point3D.create(2,0,0))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;points.add(adsk.core.Point3D.create(0,0,0))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I added your lines and it works, I have a closed square in a sketch. But...how? So if I am not mistaken: &lt;STRONG&gt;&lt;U&gt;adsk.core.ObjectCollection.create()&lt;/U&gt;&lt;/STRONG&gt; creates an object called "points" that will include the points below. How does it put it in my sketch?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also,&amp;nbsp; can you break down your loop? I'm sorry if I'm asking too much or if I sound like a newb...I did coding in college 12 years ago and I'm trying to dig this back to the surface of my memory but it's hidden way deep in there&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot, I appreciate it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 02:28:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/python-script-to-create-a-chain-of-lines/m-p/9351794#M17313</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-02T02:28:08Z</dc:date>
    </item>
  </channel>
</rss>

