<?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: fusion api sketches lines in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/fusion-api-sketches-lines/m-p/11283619#M5774</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7077527"&gt;@grosfaignan&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here you have a fragment of python code to create sketch lines and dimension one of them with a user parameter:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;app: adsk.core.Application = adsk.core.Application.get()
DISTANCE_PARAMETER = 'distance'
design = adsk.fusion.Design.cast(app.activeProduct)

# 1) user parameter
distParam = design.userParameters.itemByName(DISTANCE_PARAMETER)
if not distParam:
    # create user parameter if not found
    distVal = adsk.core.ValueInput.createByString('35 mm')
    distParam = design.userParameters.add(DISTANCE_PARAMETER, distVal, 'mm', '')

# 2) sketch
rootComp = adsk.fusion.Component.cast(design.rootComponent)
# Create a new sketch on the xy plane.
sketches = rootComp.sketches
sketch = sketches.itemByName('xySketch')
sketch.areDimensionsShown = True  #display dimensions on the sketch
if not sketch:
    # create sketch if not found
    xyPlane = rootComp.xYConstructionPlane
    sketch = adsk.fusion.Sketch.cast(sketches.add(xyPlane))
    sketch.name = 'xySketch'

    # 3) create sketch points
    p1 = sketch.sketchPoints.add(adsk.core.Point3D.create(1, 0, 0))
    p2 = sketch.sketchPoints.add(adsk.core.Point3D.create(3, 1, 0))

    # 4) create 2 lines, sharing p1 as a coincident constraint
    line1 = sketch.sketchCurves.sketchLines.addByTwoPoints(sketch.originPoint, p1)
    line2 = sketch.sketchCurves.sketchLines.addByTwoPoints(p1, p2)

    # 5) add dimension to line1
    sld = sketch.sketchDimensions.addDistanceDimension(sketch.originPoint, p1, adsk.fusion.DimensionOrientations.AlignedDimensionOrientation, adsk.core.Point3D.create(0, 2, 0))

    # 6) get model parameter from the sketch dimension and assign a user parameter to its expression
    modelParam = adsk.fusion.ModelParameter.cast(sld.parameter)
    modelParam.expression = DISTANCE_PARAMETER&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Captura de pantalla 2022-07-07 112440.png" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1089095iE28C8C2884C0CE3B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Captura de pantalla 2022-07-07 112440.png" alt="Captura de pantalla 2022-07-07 112440.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;&lt;P&gt;Let me know if it works for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jorge&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Jul 2022 16:25:46 GMT</pubDate>
    <dc:creator>Jorge_Jaramillo</dc:creator>
    <dc:date>2022-07-07T16:25:46Z</dc:date>
    <item>
      <title>fusion api sketches lines</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/fusion-api-sketches-lines/m-p/11281233#M5772</link>
      <description>&lt;P&gt;hi there, i need to create some lines in python scripts, then add them length and then add them dimension (placement) from origin, how can i do that ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 18:57:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/fusion-api-sketches-lines/m-p/11281233#M5772</guid>
      <dc:creator>grosfaignan</dc:creator>
      <dc:date>2022-07-06T18:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: fusion api sketches lines</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/fusion-api-sketches-lines/m-p/11282338#M5773</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7077527"&gt;@grosfaignan&lt;/a&gt;&amp;nbsp;here are some sample links that demonstrate creating sketch lines and adding sketch dimensions.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-98e163be-fd07-11e4-9c39-3417ebd3d5be" target="_blank"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-98e163be-fd07-11e4-9c39-3417ebd3d5be&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-B727AD04-37B6-49A2-BF16-394EBEE9F527" target="_blank"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-B727AD04-37B6-49A2-BF16-394EBEE9F527&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Here is another link explaining the sketch dimensions object &lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-GUID-ea0faa88-65eb-4845-b2ce-22d0640bedf4" target="_blank"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-GUID-ea0faa88-65eb-4845-b2ce-22d0640bedf4 .&lt;/A&gt;Under the topic Samples, there few more examples related to dimension.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;------------------------------------------------------------------------------------------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If my reply was helpful, please click the "Accept as Solution" button. It helps others get the answer quickly! A "Like" is always welcomed.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2022 07:19:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/fusion-api-sketches-lines/m-p/11282338#M5773</guid>
      <dc:creator>Rushikesh.kadam</dc:creator>
      <dc:date>2022-07-07T07:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: fusion api sketches lines</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/fusion-api-sketches-lines/m-p/11283619#M5774</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7077527"&gt;@grosfaignan&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here you have a fragment of python code to create sketch lines and dimension one of them with a user parameter:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;app: adsk.core.Application = adsk.core.Application.get()
DISTANCE_PARAMETER = 'distance'
design = adsk.fusion.Design.cast(app.activeProduct)

# 1) user parameter
distParam = design.userParameters.itemByName(DISTANCE_PARAMETER)
if not distParam:
    # create user parameter if not found
    distVal = adsk.core.ValueInput.createByString('35 mm')
    distParam = design.userParameters.add(DISTANCE_PARAMETER, distVal, 'mm', '')

# 2) sketch
rootComp = adsk.fusion.Component.cast(design.rootComponent)
# Create a new sketch on the xy plane.
sketches = rootComp.sketches
sketch = sketches.itemByName('xySketch')
sketch.areDimensionsShown = True  #display dimensions on the sketch
if not sketch:
    # create sketch if not found
    xyPlane = rootComp.xYConstructionPlane
    sketch = adsk.fusion.Sketch.cast(sketches.add(xyPlane))
    sketch.name = 'xySketch'

    # 3) create sketch points
    p1 = sketch.sketchPoints.add(adsk.core.Point3D.create(1, 0, 0))
    p2 = sketch.sketchPoints.add(adsk.core.Point3D.create(3, 1, 0))

    # 4) create 2 lines, sharing p1 as a coincident constraint
    line1 = sketch.sketchCurves.sketchLines.addByTwoPoints(sketch.originPoint, p1)
    line2 = sketch.sketchCurves.sketchLines.addByTwoPoints(p1, p2)

    # 5) add dimension to line1
    sld = sketch.sketchDimensions.addDistanceDimension(sketch.originPoint, p1, adsk.fusion.DimensionOrientations.AlignedDimensionOrientation, adsk.core.Point3D.create(0, 2, 0))

    # 6) get model parameter from the sketch dimension and assign a user parameter to its expression
    modelParam = adsk.fusion.ModelParameter.cast(sld.parameter)
    modelParam.expression = DISTANCE_PARAMETER&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Captura de pantalla 2022-07-07 112440.png" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1089095iE28C8C2884C0CE3B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Captura de pantalla 2022-07-07 112440.png" alt="Captura de pantalla 2022-07-07 112440.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;&lt;P&gt;Let me know if it works for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jorge&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2022 16:25:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/fusion-api-sketches-lines/m-p/11283619#M5774</guid>
      <dc:creator>Jorge_Jaramillo</dc:creator>
      <dc:date>2022-07-07T16:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: fusion api sketches lines</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/fusion-api-sketches-lines/m-p/11283626#M5775</link>
      <description>Please correct in the previous code, moving this line :&lt;BR /&gt;sketch.areDimensionsShown = True&lt;BR /&gt;after&lt;BR /&gt;sketch.name = 'xySketch'.&lt;BR /&gt;Sorry!!.</description>
      <pubDate>Thu, 07 Jul 2022 16:30:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/fusion-api-sketches-lines/m-p/11283626#M5775</guid>
      <dc:creator>Jorge_Jaramillo</dc:creator>
      <dc:date>2022-07-07T16:30:23Z</dc:date>
    </item>
  </channel>
</rss>

