<?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: Help on executing an API custom command in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/help-on-executing-an-api-custom-command/m-p/10559553#M8154</link>
    <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6985884"&gt;@2way3dtext&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are many things going on, but the yellow part is an error because it is None.&lt;BR /&gt;In addition, when I reached the green part "except:", the error message was not displayed because ui was also None.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 428px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/955081i830CE5DBCF337707/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Also, when I use UserInterface.selectEntity with the command dialog dialogs displayed, it crashes. (red part)&lt;BR /&gt;It has been reported somewhere in the forum that this method is undesirable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't explain it in detail, but I've got it working.&lt;BR /&gt;Please compare.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;・・・

#Create Rounded End Pipe
def CreateRoundedEndPipe(path, pipeDiameter) :
    try:
        pipeRadius =pipeDiameter/2

        product = _app.activeProduct
        design = adsk.fusion.Design.cast(product)
        
        comp = design.rootComponent
        selObj: adsk.fusion.BRepEdge = path

        # create path
        feats = comp.features
        chainedOption = adsk.fusion.ChainedCurveOptions.connectedChainedCurves
        if adsk.fusion.BRepEdge.cast(selObj):
            chainedOption = adsk.fusion.ChainedCurveOptions.tangentChainedCurves
        path = adsk.fusion.Path.create(selObj, chainedOption)
        path = feats.createPath(selObj)
        
        # create profile_1
        planes = comp.constructionPlanes
        planeInput_1 = planes.createInput()
        planeInput_1.setByDistanceOnPath(selObj, adsk.core.ValueInput.createByReal(0))
        plane_1 = planes.add(planeInput_1)
        
        sketches = comp.sketches
        sketch_1 = sketches.add(plane_1)
        
        center_1 = plane_1.geometry.origin
        center_1 = sketch_1.modelToSketchSpace(center_1)
        sketch_1.sketchCurves.sketchCircles.addByCenterRadius(center_1, pipeRadius)
        profile_1 = sketch_1.profiles[0]

        # create profile_2
        planeInput_2 = planes.createInput()
        planeInput_2.setByDistanceOnPath(selObj, adsk.core.ValueInput.createByReal(1))
        plane_2 = planes.add(planeInput_2)

        sketches_2 = comp.sketches
        sketch_2 = sketches_2.add(plane_2)

        center_2 = plane_2.geometry.origin
        center_2 = sketch_2.modelToSketchSpace(center_2)
        circle_2 = sketch_2.sketchCurves.sketchCircles
        sketch_2.sketchCurves.sketchCircles.addByCenterRadius(center_2, pipeRadius)

        sk_2 = comp.sketches.add(plane_2)

        circles_2 = sk_2.sketchCurves.sketchCircles
        circle_2 = circles_2.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), pipeRadius)

        lines_2 = sk_2.sketchCurves.sketchLines
        axisLine_2 = lines_2.addByTwoPoints(adsk.core.Point3D.create(-pipeRadius, 0, 0), adsk.core.Point3D.create(pipeRadius, 0, 0))
        profile_2 = sk_2.profiles.item(0)
        
        # create profile_3
        sketches_3 = comp.sketches
        sketch_3 = sketches.add(plane_1)
        
        center_3 = plane_1.geometry.origin
        center_3 = sketch_1.modelToSketchSpace(center_1)
        sketch_3.sketchCurves.sketchCircles.addByCenterRadius(center_1, pipeRadius)
        profile_3 = sketch_1.profiles[0]  

        sk_3 = comp.sketches.add(plane_1)

        circles_3 = sk_3.sketchCurves.sketchCircles
        circle_3 = circles_3.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), pipeRadius)

        lines_3 = sk_3.sketchCurves.sketchLines
        axisLine_3 = lines_3.addByTwoPoints(adsk.core.Point3D.create(-pipeRadius, 0, 0), adsk.core.Point3D.create(pipeRadius, 0, 0))
        profile_3 = sk_3.profiles.item(0)      
        
        # Create an revolution input to be able to define the input needed for a revolution
        # while specifying the profile and that a new component is to be created
        revolves = comp.features.revolveFeatures
        revInput_2 = revolves.createInput(profile_2, axisLine_2, adsk.fusion.FeatureOperations.NewComponentFeatureOperation)
        revInput_3 = revolves.createInput(profile_3, axisLine_3, adsk.fusion.FeatureOperations.NewComponentFeatureOperation)

        # Define that the extent is an angle of 2*pi to get a sphere
        angle = adsk.core.ValueInput.createByReal(2*math.pi)
        revInput_2.setAngleExtent(False, angle)
        revInput_3.setAngleExtent(False, angle)

        # Create the extrusion.
        ext_2 = revolves.add(revInput_2)
        ext_2 = revolves.add(revInput_3)

        
        # create sweep
        sweepFeats = feats.sweepFeatures
        sweepInput = sweepFeats.createInput(profile_1, path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        sweepInput.orientation = adsk.fusion.SweepOrientationTypes.PerpendicularOrientationType
        sweepFeat = sweepFeats.add(sweepInput)
        
        _app.activeViewport.refresh()

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
・・・
# Event handler for the commandCreated event.
class MyCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
・・・
            path_Input = inputs.addSelectionInput('path_Input', 'Path', 'Select path of pipe')
            path_Input.setSelectionLimits(1,1)
            path_Input.addSelectionFilter('Edges')
            path_Input.addSelectionFilter('SketchCurves')
・・・
&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 20 Aug 2021 00:25:07 GMT</pubDate>
    <dc:creator>kandennti</dc:creator>
    <dc:date>2021-08-20T00:25:07Z</dc:date>
    <item>
      <title>Help on executing an API custom command</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/help-on-executing-an-api-custom-command/m-p/10558666#M8153</link>
      <description>&lt;P&gt;The following code asks the user to select the desired path and diameter of the pipe, however, nothing occurs after all the inputs are selected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would this be an issue with how the inputs are defined?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Select all of the inputs.&lt;/P&gt;&lt;P&gt;um = des.unitsManager&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;path_Input = inputs.addSelectionInput('path_Input', 'Path', 'Select path of pipe')&lt;/P&gt;&lt;P&gt;path_Input.setSelectionLimits(1,1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;pipeDiameter_input = inputs.addValueInput('pipeDiameter_Input', 'Diameter', um.defaultLengthUnits, adsk.core.ValueInput.createByString('1'))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Event handler for the execute event.&lt;/P&gt;&lt;P&gt;class RoundedEndPipeCommandExecuteHandler(adsk.core.CommandEventHandler):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; super().__init__()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def notify(self, args):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;eventArgs = adsk.core.CommandEventArgs.cast(args)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inputs = eventArgs.command.commandInputs&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get the values of all of the inputs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; path = inputs.itemById('path_Input').selection(0).entity&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pipeDiameter = inputs.itemById('pipeDiameter_Input').value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CreateRoundedEndPipe(path, pipeDiameter)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will be very grateful for any suggestions or feedback on fixing this issue.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 16:58:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/help-on-executing-an-api-custom-command/m-p/10558666#M8153</guid>
      <dc:creator>2way3dtext</dc:creator>
      <dc:date>2021-08-19T16:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: Help on executing an API custom command</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/help-on-executing-an-api-custom-command/m-p/10559553#M8154</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6985884"&gt;@2way3dtext&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are many things going on, but the yellow part is an error because it is None.&lt;BR /&gt;In addition, when I reached the green part "except:", the error message was not displayed because ui was also None.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 428px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/955081i830CE5DBCF337707/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Also, when I use UserInterface.selectEntity with the command dialog dialogs displayed, it crashes. (red part)&lt;BR /&gt;It has been reported somewhere in the forum that this method is undesirable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't explain it in detail, but I've got it working.&lt;BR /&gt;Please compare.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;・・・

#Create Rounded End Pipe
def CreateRoundedEndPipe(path, pipeDiameter) :
    try:
        pipeRadius =pipeDiameter/2

        product = _app.activeProduct
        design = adsk.fusion.Design.cast(product)
        
        comp = design.rootComponent
        selObj: adsk.fusion.BRepEdge = path

        # create path
        feats = comp.features
        chainedOption = adsk.fusion.ChainedCurveOptions.connectedChainedCurves
        if adsk.fusion.BRepEdge.cast(selObj):
            chainedOption = adsk.fusion.ChainedCurveOptions.tangentChainedCurves
        path = adsk.fusion.Path.create(selObj, chainedOption)
        path = feats.createPath(selObj)
        
        # create profile_1
        planes = comp.constructionPlanes
        planeInput_1 = planes.createInput()
        planeInput_1.setByDistanceOnPath(selObj, adsk.core.ValueInput.createByReal(0))
        plane_1 = planes.add(planeInput_1)
        
        sketches = comp.sketches
        sketch_1 = sketches.add(plane_1)
        
        center_1 = plane_1.geometry.origin
        center_1 = sketch_1.modelToSketchSpace(center_1)
        sketch_1.sketchCurves.sketchCircles.addByCenterRadius(center_1, pipeRadius)
        profile_1 = sketch_1.profiles[0]

        # create profile_2
        planeInput_2 = planes.createInput()
        planeInput_2.setByDistanceOnPath(selObj, adsk.core.ValueInput.createByReal(1))
        plane_2 = planes.add(planeInput_2)

        sketches_2 = comp.sketches
        sketch_2 = sketches_2.add(plane_2)

        center_2 = plane_2.geometry.origin
        center_2 = sketch_2.modelToSketchSpace(center_2)
        circle_2 = sketch_2.sketchCurves.sketchCircles
        sketch_2.sketchCurves.sketchCircles.addByCenterRadius(center_2, pipeRadius)

        sk_2 = comp.sketches.add(plane_2)

        circles_2 = sk_2.sketchCurves.sketchCircles
        circle_2 = circles_2.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), pipeRadius)

        lines_2 = sk_2.sketchCurves.sketchLines
        axisLine_2 = lines_2.addByTwoPoints(adsk.core.Point3D.create(-pipeRadius, 0, 0), adsk.core.Point3D.create(pipeRadius, 0, 0))
        profile_2 = sk_2.profiles.item(0)
        
        # create profile_3
        sketches_3 = comp.sketches
        sketch_3 = sketches.add(plane_1)
        
        center_3 = plane_1.geometry.origin
        center_3 = sketch_1.modelToSketchSpace(center_1)
        sketch_3.sketchCurves.sketchCircles.addByCenterRadius(center_1, pipeRadius)
        profile_3 = sketch_1.profiles[0]  

        sk_3 = comp.sketches.add(plane_1)

        circles_3 = sk_3.sketchCurves.sketchCircles
        circle_3 = circles_3.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), pipeRadius)

        lines_3 = sk_3.sketchCurves.sketchLines
        axisLine_3 = lines_3.addByTwoPoints(adsk.core.Point3D.create(-pipeRadius, 0, 0), adsk.core.Point3D.create(pipeRadius, 0, 0))
        profile_3 = sk_3.profiles.item(0)      
        
        # Create an revolution input to be able to define the input needed for a revolution
        # while specifying the profile and that a new component is to be created
        revolves = comp.features.revolveFeatures
        revInput_2 = revolves.createInput(profile_2, axisLine_2, adsk.fusion.FeatureOperations.NewComponentFeatureOperation)
        revInput_3 = revolves.createInput(profile_3, axisLine_3, adsk.fusion.FeatureOperations.NewComponentFeatureOperation)

        # Define that the extent is an angle of 2*pi to get a sphere
        angle = adsk.core.ValueInput.createByReal(2*math.pi)
        revInput_2.setAngleExtent(False, angle)
        revInput_3.setAngleExtent(False, angle)

        # Create the extrusion.
        ext_2 = revolves.add(revInput_2)
        ext_2 = revolves.add(revInput_3)

        
        # create sweep
        sweepFeats = feats.sweepFeatures
        sweepInput = sweepFeats.createInput(profile_1, path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        sweepInput.orientation = adsk.fusion.SweepOrientationTypes.PerpendicularOrientationType
        sweepFeat = sweepFeats.add(sweepInput)
        
        _app.activeViewport.refresh()

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
・・・
# Event handler for the commandCreated event.
class MyCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
・・・
            path_Input = inputs.addSelectionInput('path_Input', 'Path', 'Select path of pipe')
            path_Input.setSelectionLimits(1,1)
            path_Input.addSelectionFilter('Edges')
            path_Input.addSelectionFilter('SketchCurves')
・・・
&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 20 Aug 2021 00:25:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/help-on-executing-an-api-custom-command/m-p/10559553#M8154</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2021-08-20T00:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Help on executing an API custom command</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/help-on-executing-an-api-custom-command/m-p/10565386#M8155</link>
      <description>&lt;P&gt;Hello @&lt;A href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3787950" target="_blank"&gt;kandennti&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for looking over my code and pointing out the lines where the errors arise!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I revised the code just as you have shown me, the add-in worked perfectly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again for your generous time and help.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 02:00:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/help-on-executing-an-api-custom-command/m-p/10565386#M8155</guid>
      <dc:creator>2way3dtext</dc:creator>
      <dc:date>2021-08-23T02:00:37Z</dc:date>
    </item>
  </channel>
</rss>

