<?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: From Python to C++ in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/from-python-to-c/m-p/10961253#M6718</link>
    <description>&lt;P&gt;Thank you Jérôme. I'll look at this solution as soon as I have some time..... &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 20 Feb 2022 11:11:30 GMT</pubDate>
    <dc:creator>bernard5BABD</dc:creator>
    <dc:date>2022-02-20T11:11:30Z</dc:date>
    <item>
      <title>From Python to C++</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/from-python-to-c/m-p/10920727#M6716</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I have an add-in written in Python, which has been downloaded numerous times. I am thinking about expanding it (or writing a new one based on it), but I would like the new version to be paid for. I believe that to protect the code, I have to write in C++ and compile it.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Is there a way to "translate" Python to C++, or should I prepare myself to rewrite everything in C++?&lt;BR /&gt;The correlative question follows: is there a way to compile and protect Python code? I know you can compile it for standalone programs, but not sure with Fusion 360 API.&lt;BR /&gt;&lt;BR /&gt;Thanks for your help, advice, pointers, and best regards,&lt;/P&gt;&lt;P&gt;Bernard&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 12:43:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/from-python-to-c/m-p/10920727#M6716</guid>
      <dc:creator>bernard5BABD</dc:creator>
      <dc:date>2022-02-01T12:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: From Python to C++</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/from-python-to-c/m-p/10961248#M6717</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10711802"&gt;@bernard5BABD&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;Is there a way to "translate" Python to C++,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;AFAIK, no.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10711802"&gt;@bernard5BABD&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;should I prepare myself to rewrite everything in C++?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well, that depends on your skill in C++ programming. Distribute compiled C++ code is the safer way for sure. But does it worth the effort and the time spent in rewriting the all code ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10711802"&gt;@bernard5BABD&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;is there a way to compile and protect Python code?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can compile Python code in .pyc files using &lt;A href="https://docs.python.org/3/library/compileall.html#module-compileall" target="_blank" rel="noopener"&gt;compileall&lt;/A&gt; or &lt;A href="https://docs.python.org/3/library/py_compile.html" target="_blank" rel="noopener"&gt;py_compile&lt;/A&gt; modules. The .pyc files are binary files not readable by humans (read limitations here: &lt;A href="https://forums.autodesk.com/t5/fusion-360-api-and-scripts/important-python-version-change-information/m-p/10929351" target="_blank" rel="noopener"&gt;Important Python Version Change Information&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I attached a script example to this message. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First I wrote the code in the source/message.py file. Then I opened a terminal, I went to the folder where the py file is, and I runnned the following command (replace &amp;lt;USERNAME&amp;gt; and &amp;lt;FUSION360INSTALLID&amp;gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;C:\Users\&amp;lt;USERNAME&amp;gt;\AppData\Local\Autodesk\webdeploy\production\&amp;lt;FUSION360INSTALLID&amp;gt;\Python\python.exe -m py_compile message.py&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The __pycache__ folder was then created with the .pyc file inside. I copied the file message.cpython-37.pyc in the root folder and I renamed it as message.pyc&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the script that calls the pyc file:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import adsk.core, adsk.fusion, adsk.cam, traceback

from . import message

def run(context):

    app = adsk.core.Application.get()
    ui  = app.userInterface

    try:

        message.hello()

    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;Don't forget to remove the source file when you distribute the add-in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the process can be automated using more Python code. But I keep it short here…&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Feb 2022 10:55:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/from-python-to-c/m-p/10961248#M6717</guid>
      <dc:creator>JeromeBriot</dc:creator>
      <dc:date>2022-02-20T10:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: From Python to C++</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/from-python-to-c/m-p/10961253#M6718</link>
      <description>&lt;P&gt;Thank you Jérôme. I'll look at this solution as soon as I have some time..... &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Feb 2022 11:11:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/from-python-to-c/m-p/10961253#M6718</guid>
      <dc:creator>bernard5BABD</dc:creator>
      <dc:date>2022-02-20T11:11:30Z</dc:date>
    </item>
  </channel>
</rss>

