Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

From Python to C++

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
bernard5BABD
406 Views, 2 Replies

From Python to C++

Hello,

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. 

Is there a way to "translate" Python to C++, or should I prepare myself to rewrite everything in C++?
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.

Thanks for your help, advice, pointers, and best regards,

Bernard

Bernard Grosperrin, Retired, Maker, and Autodesk Certified Instructor
Blog : Le Bear CNC | Forum : Le Bear CNC Forum | Addin : Airfoil Sketch from file
2 REPLIES 2
Message 2 of 3
JeromeBriot
in reply to: bernard5BABD

Hello,

 


@bernard5BABD  a écrit :

Is there a way to "translate" Python to C++,


AFAIK, no.

 


@bernard5BABD  a écrit :

should I prepare myself to rewrite everything in C++?

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 ?

 


@bernard5BABD  a écrit :

 is there a way to compile and protect Python code?


You can compile Python code in .pyc files using compileall or py_compile modules. The .pyc files are binary files not readable by humans (read limitations here: Important Python Version Change Information).

 

I attached a script example to this message.

 

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 <USERNAME> and <FUSION360INSTALLID>)

 :

 

 

C:\Users\<USERNAME>\AppData\Local\Autodesk\webdeploy\production\<FUSION360INSTALLID>\Python\python.exe -m py_compile message.py

 

 

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

 

Here is the script that calls the pyc file:

 

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()))

 

Don't forget to remove the source file when you distribute the add-in.

 

All the process can be automated using more Python code. But I keep it short here…

 

Hope it helps.

 

Message 3 of 3
bernard5BABD
in reply to: JeromeBriot

Thank you Jérôme. I'll look at this solution as soon as I have some time..... 😉

Bernard Grosperrin, Retired, Maker, and Autodesk Certified Instructor
Blog : Le Bear CNC | Forum : Le Bear CNC Forum | Addin : Airfoil Sketch from file

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report