<?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 Insert STL and Convert to B-REP using Python Script in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/insert-stl-and-convert-to-b-rep-using-python-script/m-p/10740560#M7673</link>
    <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I'm trying to automate importing a batch of stl files into fusion 360 and converting them to B-REP (the button under mesh --&amp;gt; modify --&amp;gt; convert mesh) using python. Is there any documentation on this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Sounak&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 07 Nov 2021 07:35:48 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-11-07T07:35:48Z</dc:date>
    <item>
      <title>Insert STL and Convert to B-REP using Python Script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/insert-stl-and-convert-to-b-rep-using-python-script/m-p/10740560#M7673</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I'm trying to automate importing a batch of stl files into fusion 360 and converting them to B-REP (the button under mesh --&amp;gt; modify --&amp;gt; convert mesh) using python. Is there any documentation on this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Sounak&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 07:35:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/insert-stl-and-convert-to-b-rep-using-python-script/m-p/10740560#M7673</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-11-07T07:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: Insert STL and Convert to B-REP using Python Script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/insert-stl-and-convert-to-b-rep-using-python-script/m-p/10740863#M7674</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I converted the OBJ file to BRepBody here. I think it can be used in STL with a few modifications.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/fusion-360-api-and-scripts/insert-obj-file/m-p/9640466#M10730" target="_blank"&gt;https://forums.autodesk.com/t5/fusion-360-api-and-scripts/insert-obj-file/m-p/9640466#M10730&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;However, if the number of faces in one body is more than 10,000, a warning dialog appears, and if the number of faces is more than 50,000, it cannot be processed. This is the same even if you use the GUI.&lt;BR /&gt;To avoid this problem, here is a sample of how to split a body until the number of faces in a body is less than 10000, and then convert it.&lt;BR /&gt;However, it is all written in Japanese.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://kantoku.hatenablog.com/entry/2021/04/27/171136" target="_blank" rel="noopener"&gt;https://kantoku.hatenablog.com/entry/2021/04/27/171136&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 13:10:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/insert-stl-and-convert-to-b-rep-using-python-script/m-p/10740863#M7674</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2021-11-07T13:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: Insert STL and Convert to B-REP using Python Script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/insert-stl-and-convert-to-b-rep-using-python-script/m-p/10741055#M7675</link>
      <description>&lt;P&gt;Hi &lt;SPAN&gt;kandennti&amp;nbsp;,&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the python script examples. I've modified the first script to import an STL file. However, I noticed that file explorer pops up, and I still need to manually click on the file I want to work with. Is there any way to automate this part by adding a file path? I've included the modified code below. I mainly changed lines 15, 49, and 80.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Sounak&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Fusion360API Python script  by kantoku
# Mesh2BRep sample
# Changed to Import STL 
import adsk.core, adsk.fusion, traceback

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        # select files
        paths = selectFiles('select STL file')
        if not paths: return

        # new doc
        _app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        des  :adsk.fusion.Design = _app.activeProduct
        des.designType = adsk.fusion.DesignTypes.ParametricDesignType
        root :adsk.fusion.Component = des.rootComponent

        # baseFeature
        baseFeatures = root.features.baseFeatures
        baseFeature = baseFeatures.add()

        baseFeature.startEdit()
        
        # import obj files
        meshs = importMesh(paths ,root.meshBodies, baseFeature)

        # Mesh2BRep
        #execMesh2BRep(meshs)

        #baseFeature.finishEdit()

        # finish
        _ui.messageBox('Done')

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def execMesh2BRep(
    meshBodies):

    # select meshBody
    for mesh in meshBodies:
        _ui.activeSelections.add(mesh)

    # show Mesh2BRep Command dialog
    _app.executeTextCommand(u'Commands.Start Mesh2BRepCommand')

    # push OK button
    _app.executeTextCommand(u'NuCommands.CommitCmd')


def importMesh(
    paths :list,
    meshBodies :adsk.fusion.MeshBodies,
    baseFeature :adsk.fusion.BaseFeature) -&amp;gt; list:

    unitCm = adsk.fusion.MeshUnits.CentimeterMeshUnit
    bodies = []

    for path in paths:
        meshLst = meshBodies.add(path, unitCm, baseFeature)
        [bodies.append(mesh) for mesh in meshLst]

    return bodies


def selectFiles(
    msg :str):

    fileDlg = _ui.createFileDialog()
    fileDlg.isMultiSelectEnabled = True
    fileDlg.title = msg
    fileDlg.filter = '*.stl'
    
    dlgResult = fileDlg.showOpen()
    if dlgResult == adsk.core.DialogResults.DialogOK:
        return fileDlg.filenames&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 16:38:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/insert-stl-and-convert-to-b-rep-using-python-script/m-p/10741055#M7675</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-11-07T16:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: Insert STL and Convert to B-REP using Python Script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/insert-stl-and-convert-to-b-rep-using-python-script/m-p/10741788#M7676</link>
      <description>&lt;P&gt;@Anonymous&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The CommandID of the mesh transformation has been changed and is now fixed.&lt;/P&gt;
&lt;P&gt;Enter the path of the desired STL file in the "paths" variable to avoid specifying the file in the dialog.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script
import adsk.core
import adsk.fusion
import traceback

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        # import stl files list
        paths = [
            r'C:\temp\hoge.stl',
            r'C:\temp\piyo.stl',
        ]

        # new doc
        _app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        des  :adsk.fusion.Design = _app.activeProduct
        des.designType = adsk.fusion.DesignTypes.ParametricDesignType
        root :adsk.fusion.Component = des.rootComponent

        # baseFeature
        baseFeatures = root.features.baseFeatures
        baseFeature = baseFeatures.add()

        baseFeature.startEdit()
        
        # import obj files
        meshs = importMesh(paths ,root.meshBodies, baseFeature)

        # Mesh2BRep
        execMesh2BRep(meshs)

        baseFeature.finishEdit()

        # finish
        _ui.messageBox('Done')

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def execMesh2BRep(
    meshBodies):

    # select meshBody
    for mesh in meshBodies:
        _ui.activeSelections.add(mesh)

        # show ParaMeshConvertCommand Command dialog
        _app.executeTextCommand(u'Commands.Start ParaMeshConvertCommand')

        # push OK button
        _app.executeTextCommand(u'NuCommands.CommitCmd')


def importMesh(
    paths :list,
    meshBodies :adsk.fusion.MeshBodies,
    baseFeature :adsk.fusion.BaseFeature) -&amp;gt; list:

    unitCm = adsk.fusion.MeshUnits.CentimeterMeshUnit
    bodies = []

    for path in paths:
        meshLst = meshBodies.add(path, unitCm, baseFeature)
        [bodies.append(mesh) for mesh in meshLst]

    return bodies&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 08 Nov 2021 05:26:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/insert-stl-and-convert-to-b-rep-using-python-script/m-p/10741788#M7676</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2021-11-08T05:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Insert STL and Convert to B-REP using Python Script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/insert-stl-and-convert-to-b-rep-using-python-script/m-p/10741809#M7677</link>
      <description>&lt;P&gt;Hi kandennti,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the help! Here's the new code implementing the ParaMeshConvertCommand.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import adsk.core, adsk.fusion, adsk.cam, traceback
import os 
def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        test_name = '1test_file'
        #Find project by name
        # Get the root folder of the project
        for data_file in app.activeDocument.dataFile.parentFolder.dataFiles:
            #if data_file.fileExtension == 'stl':                    
            if test_name == data_file.name:
                msg = str(data_file.name)
                ui.messageBox(msg)
                app.documents.open(data_file)
                des :adsk.fusion.Design = app.activeProduct
                root :adsk.fusion.Component = des.rootComponent
                sels :adsk.core.Selections = ui.activeSelections
                sels.clear()
                cmDefs = ui.commandDefinitions
                
                for mesh in root.meshBodies:
                    msg = str(mesh.name)
                    ui.messageBox(msg)
                    sels.add(mesh)
                    # show ParaMeshConvertCommand Command dialog
                    app.executeTextCommand(u'Commands.Start ParaMeshConvertCommand')
                    # push OK button
                    app.executeTextCommand(u'NuCommands.CommitCmd')
                    #cmDef = cmDefs.itemById("ParaMeshConvertCommand")
                    #cmDef.controlDefinition.isEnabled
                    #cmDef.execute()
                msg = 'brep conversion complete'
                ui.messageBox(msg)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I looked at your other examples on how to select meshes.&amp;nbsp; Before, I saw your most recent reply, I was actually trying to use the commandDefinitions to execute the ParaMeshConvert command. If you comment out the text commands and uncomment the commandDefinition lines,&amp;nbsp; I got to the point where I just needed to press the enter key. Just out of curiosity, would you know how I can use keyboard events?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, thank you for the help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Sounak&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Nov 2021 05:55:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/insert-stl-and-convert-to-b-rep-using-python-script/m-p/10741809#M7677</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-11-08T05:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Insert STL and Convert to B-REP using Python Script</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/insert-stl-and-convert-to-b-rep-using-python-script/m-p/12616745#M7678</link>
      <description>&lt;P&gt;This used to work until recently. Any ideas why it doesn't anymore?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2024 15:50:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/insert-stl-and-convert-to-b-rep-using-python-script/m-p/12616745#M7678</guid>
      <dc:creator>arndt.grossmann</dc:creator>
      <dc:date>2024-03-05T15:50:28Z</dc:date>
    </item>
  </channel>
</rss>

