What's new

AlibreScript Python 3 (AlibreScriptPython3) compatible coding early concept.

stepalibre

Alibre Super User
To all,

I'm at a stopping point for now and would love some feedback from users before I continue. I would like to include your ideas and to understand if this is relevant to how you use AlibreScript.

AlibreScriptPython3 is a way to use AlibreScript API inside of Python 3 supported text editors and IDEs. It will allow for autocomplete and type hinting along with other possible python language features. This can make it easier to build AlibreScripts and work inside the Python ecosystem. Using it can be as simple as AlibreScripting is today. You would instead use a Python editor of your choice. I plan to package it into a ready to use library and files available under MIT license.

AlibreScript:
Python:
Win = Windows()
Win.InfoDialog('I am about to create a part', 'My Script')
Win.ErrorDialog("Oops. That didn't go as planned", 'My Script')
print Win.QuestionDialog('Shall I stop?', 'My Script')

AlibreScriptPython3:
Python:
from AlibreScriptPython3 import *
win = ErrorDialog('I am about to create a part', 'My Script')
InfoDialog('I am about to create a part', 'My Script')
print(QuestionDialog('Shall I stop?', 'My Script'))

There are difference between AlibreScript (ironpython2.7) and AlibreScriptPython3 (py3) but these can be solved and discussed later.

AlibreScriptPython3 is the full AlibreScript API which is 700+ members.

1695770924556.png

1695770576265.png

1695770690041.png

This can become many things far beyond what I have made, this is AlibreScript inside Python. The way it works can be changed and made much simpler and can grow and be updated alongside AlibreScript.

Tools to convert to and from AlibreScript scripts and AlibreScriptPython3 are not made yet. An addon and other tools can be developed. This is very early work.
Thanks for your help.
 
Last edited:

NateLiquidGravity

Alibre Super User
If I understand correctly it's an interesting idea. I think it would be improved to use the classes of AlibreScript and the IronPython 2.7 syntax of AlibreScript. This would allow the existing scripts to be used and to prevent code posted in the forum from being so troublesome to new users.

If you maintained the same classes and syntax then potentially you could have the AlibreScriptPython module check if it is running in Alibre Design on import and and pass on the responsibly to AlibreScript instead.

Additionally there are limitations that IronPython 2.7 (and potentially IronPython 3.4) and therefore AlibreScript have compared to regular Python. For example Tkinter, NumPy,... don't work in AlibreScript. Perhaps in the future we will mend that.

But maybe I'm not understanding the intention correctly?
 

albie0803

Alibre Super User
A better editor would be a marvellous thing. If it gave the ability to step through a program, I would be so happy!
 

stepalibre

Alibre Super User
If I understand correctly it's an interesting idea. I think it would be improved to use the classes of AlibreScript and the IronPython 2.7 syntax of AlibreScript. This would allow the existing scripts to be used and to prevent code posted in the forum from being so troublesome to new users.
Yes, I have one to one classes but with a function only approach for most, because it's easier to make. This is mocking AlibreScript. Two styles AlibreScript mock (classes) and top level API (without classes).

Python:
class Windows:
    def CloseForm():
        pass

    def GetDisplayedForm():   
        pass

    def UtilityDialog():     
        pass

    def UtilityDialog():   
        pass

    def OptionsDialog():   
        pass

    def OptionsDialog():     
        pass

    def DisableInput():     
        pass

    def EnableInput():
        pass

    def GetInputValue():     
        pass

    def SetStringList():     
        pass

    def SetInputValue(): 
        pass

    def OpenFileDialog():
        pass

    def SaveFileDialog():
        pass

    def SelectFolderDialog():
        pass

    def InfoDialog(self,a,b):
        pass

    def ErrorDialog():
        pass

    def QuestionDialog():
        pass

win = Windows()
win.InfoDialog('I am about to create a part', 'My Script')

Matching them 1to1 is where issues will need to be solved and takes more time. I can copy and paste with only minor adjustments for it to work in AlibreScript using the top level style . I use ipy3, it should work with AlibreScriptPython3 as is.

I like a more modern top level API style which doesn't match the class structure. I will make both styles. My use is forward-looking, to help me use AlibreScript code in my other projects.

If you maintained the same classes and syntax then potentially you could have the AlibreScriptPython module check if it is running in Alibre Design on import and and pass on the responsibly to AlibreScript instead.

Yes. I plan to make scripts written in AlibreScriptPython3 work in AlibreScript. We may not need to think about classes and syntax when using converter tools. It would worry about matching ironpython2.7. Users shouldn't need to worry about these details at all.

Additionally there are limitations that IronPython 2.7 (and potentially IronPython 3.4) and therefore AlibreScript have compared to regular Python. For example Tkinter, NumPy,... don't work in AlibreScript. Perhaps in the future we will mend that.

Yes. It Is possible already using PythonNET and other techniques. A first step could be to expose AlibreX to Python 3 and newer versions of .NET which is what I'm doing. This is a separate, standalone project. I have another that is a more simplified AlibreX library for newer .NETs.

AlibreScriptPython3:
- Full AlibreScriptAPI in Python 3
- Two styles top level (modern and latest py) and class mock/stub (more like AlibreScript/IronPyton2.7 syntax) version
- Conversion and generation tools
- this will be made available after I have it in a more professional state for others to look at and use for own purposes.

Also newer tools have better support for Python 3. I'm including ChatGPT/OpenAPI into all of my work. All of this can all be made simpler which is what I'm working on in general.
For example, I use notebooks. It makes it 10x faster to work with python code and debug this work.:)

1695811678002.png

1695811148279.png

A more formal list of must haves may be worth making to be clear and on the record.
Thanks.
 

stepalibre

Alibre Super User
If it gave the ability to step through a program, I would be so happy!

That would need to attach to Alibre running process. This is possible but I haven't started thinking about debugging running python code. I'll see if it is possible without an addon. I can build external tools faster than a full integrated addon experience like AlibreScript.

And. This can't work with AlibreScript directly. It would be AlibreX under the hood and some newer component to talk to AlibreScript/AlibreScriptPython3 python code running inside Alibre. I don't know but it is possible.
 
Last edited:

stepalibre

Alibre Super User
I'll focus on getting the example AlibreScript scripts:


Converted and working as is from AlibreScriptPython3 to AlibreScripts.
 
Last edited:

stepalibre

Alibre Super User
To close for the day... This side by side workflow is great!
1695826348270.png
 

Attachments

  • 1695826225477.png
    1695826225477.png
    1.2 MB · Views: 13

stepalibre

Alibre Super User
I need to pay the bills. I will return sometime next month.
I think it would be improved to use the classes of AlibreScript and the IronPython 2.7 syntax of AlibreScript.
I was thinking it would be better to use Python 3 syntax and then a conversion tool to make it work in AlibreScript. It does make sense to match AlibreScript, but would be harder to maintained. I'll do both to get started and go from there.
 

NateLiquidGravity

Alibre Super User
I'll be taking a look at them for sure. I'm still unclear on what your goal of the project is. Are you making a new add-on that runs Python code or what?
 

stepalibre

Alibre Super User
Yes, the project will be included in an app running outside of Alibre. I'm combining everything into a single project to streamline development and maintenance. I don't think it's worth the hassle to support IronPython 2.7. If AlibreScript is upgraded to IronPython 3, then it would be worth considering. ChatGPT can help with language conversion and code fixes moving to/from Python versions.

VSCode or VSCodium will be the text editors used for debugging Alibre Python code and AlibreX C#. This is the bare minimum, but it works. About mid next month I will have more details. Thanks
1696116491780.png
 
Top