What's new

AlibreScript.Reflected | Reference project using .NET Reflection/Source Generators to help generate Alibre Script stub files.

stepalibre

Alibre Super User


AlibreScript.Reflected uses reflection of AlibreScriptAddOn.dll to generate the python source. Similar to the other stub files, it was made to help working with Alibre Script code outside of Alibre Design. This is another attempt at it.

Parameter information is included in the python source:
1702871138381.png

You can use GitHub's symbols and other code navigation features to inspect the code without downloading anything:
1702875090412.png

This can be useful as a reference when learning and programming Alibre Script, which is my primary use for it, along with the other stub files I've created.

Why build this? I'm working on reflection and C# Source Generator projects and thought about Alibre Script as a quick test case/example project.


Code:
│   AlibreScript.Reflected.code-workspace
│   generate.py
│   README.md
│
├───bin
│       AlibreScript.py
│       ex_0.py
│       ex_1.py
│       main.py
│       Notebook.ipynb
│
├───output
│       AssembledSubAssembly.py
│       Assembly.py
│       Axis.py
│       Bspline.py
│       Bspline3D.py
│       Circle.py
│       CircularArc.py
│       CircularArc3D.py
│       Configuration.py
│       CSharp.py
│       Edge.py
│       Ellipse.py
│       EllipticalArc.py
│       Face.py
│       Feature.py
│       GearSketch.py
│       GlobalParameters.py
│       IAssembled.py
│       IAxis.py
│       IChamferable.py
│       IConstrainable.py
│       ICrossSection.py
│       IFilletable.py
│       IInstance.py
│       IPlane.py
│       IPoint.py
│       ISelectableGeometry.py
│       ISketchFigure.py
│       ISketchFigure3D.py
│       ISketchSurface.py
│       ISweepPath.py
│       Line.py
│       Line3D.py
│       Material.py
│       Parameter.py
│       Part.py
│       Plane.py
│       Point.py
│       Polyline.py
│       Polyline3D.py
│       PolylinePoint.py
│       PolylinePoint3D.py
│       Sketch.py
│       Sketch3D.py
│       SketchPoint.py
│       SketchPoint3D.py
│       ThreeD.py
│       TwoD.py
│       Units.py
│       Vertex.py
│       Windows.py
│
├───sources
│       AlibreScript.API.AssembledSubAssembly.txt
│       AlibreScript.API.Assembly.txt
│       AlibreScript.API.Axis.txt
│       AlibreScript.API.Bspline.txt
│       AlibreScript.API.Bspline3D.txt
│       AlibreScript.API.Circle.txt
│       AlibreScript.API.CircularArc.txt
│       AlibreScript.API.CircularArc3D.txt
│       AlibreScript.API.Configuration.txt
│       AlibreScript.API.CSharp.txt
│       AlibreScript.API.Edge.txt
│       AlibreScript.API.Ellipse.txt
│       AlibreScript.API.EllipticalArc.txt
│       AlibreScript.API.Face.txt
│       AlibreScript.API.Feature.txt
│       AlibreScript.API.GearSketch.txt
│       AlibreScript.API.GlobalParameters.txt
│       AlibreScript.API.IAssembled.txt
│       AlibreScript.API.IAxis.txt
│       AlibreScript.API.IChamferable.txt
│       AlibreScript.API.IConstrainable.txt
│       AlibreScript.API.ICrossSection.txt
│       AlibreScript.API.IFilletable.txt
│       AlibreScript.API.IInstance.txt
│       AlibreScript.API.IPlane.txt
│       AlibreScript.API.IPoint.txt
│       AlibreScript.API.ISelectableGeometry.txt
│       AlibreScript.API.ISketchFigure.txt
│       AlibreScript.API.ISketchFigure3D.txt
│       AlibreScript.API.ISketchSurface.txt
│       AlibreScript.API.ISweepPath.txt
│       AlibreScript.API.Line.txt
│       AlibreScript.API.Line3D.txt
│       AlibreScript.API.Material.txt
│       AlibreScript.API.Parameter.txt
│       AlibreScript.API.Part.txt
│       AlibreScript.API.Plane.txt
│       AlibreScript.API.Point.txt
│       AlibreScript.API.Polyline.txt
│       AlibreScript.API.Polyline3D.txt
│       AlibreScript.API.PolylinePoint.txt
│       AlibreScript.API.PolylinePoint3D.txt
│       AlibreScript.API.Sketch.txt
│       AlibreScript.API.Sketch3D.txt
│       AlibreScript.API.SketchPoint.txt
│       AlibreScript.API.SketchPoint3D.txt
│       AlibreScript.API.ThreeD.txt
│       AlibreScript.API.TwoD.txt
│       AlibreScript.API.Units.txt
│       AlibreScript.API.Vertex.txt
│       AlibreScript.API.Windows.txt
│
└───test.packages
    ├───alibrescript_package
    │   │   setup.py
    │   │
    │   └───alibrescript_package
    │           AlibreScript.py
    │           __init__.py
    │
    └───alibrescript_windows_package
        │   setup.py
        │
        └───alibrescript_windows_package
                Windows.py
                __init__.py
 
Last edited:

stepalibre

Alibre Super User
AI tools can help further improve the Python files to make them more Pythonic. For example you can have AI make parameter names fit Python casing:
Prompt/Input
remove comments and keep the function names as is but make the parameter names Pythonic in case only
From this:
Python:
class GlobalParameters:
    def __init__(self, Name, ParameterList, ConfigurationList, Parameters, Configurations):
        pass
        self.Name = Name
        self.ParameterList = ParameterList
        self.ConfigurationList = ConfigurationList
        self.Parameters = Parameters
        self.Configurations = Configurations
    def GetParameter(self, StringName):
        pass
    def GetConfiguration(self, StringName):
        pass
    def GetActiveConfiguration(self,):
        pass
    def AddParameter(self, StringName, ParameterTypesType, DoubleValue):
        pass
    def AddParameter(self, StringName, ParameterTypesType, StringEquation):
        pass
    def AddConfiguration(self, StringName):
        pass
    def AddConfiguration(self, StringName, StringBaseConfigurationName):
        pass
    def Save(self):
        pass
    def Save(self, StringFolder):
        pass
    def SaveAs(self, StringFolder, StringNewName):
        pass
    def Close(self):
        pass
to this:
Python:
class GlobalParameters:
    def __init__(self, name, parameter_list, configuration_list, parameters, configurations):
        self.Name = name
        self.ParameterList = parameter_list
        self.ConfigurationList = configuration_list
        self.Parameters = parameters
        self.Configurations = configurations
    def GetParameter(self, string_name):
        pass
    def GetConfiguration(self, string_name):
        pass
    def GetActiveConfiguration(self):
        pass
    def AddParameter(self, string_name, parameter_type, double_value):
        pass
    def AddParameter(self, string_name, parameter_type, string_equation):
        pass
    def AddConfiguration(self, string_name):
        pass
    def AddConfiguration(self, string_name, string_base_configuration_name):
        pass
    def Save(self):
        pass
    def Save(self, string_folder):
        pass
    def SaveAs(self, string_folder, string_new_name):
        pass
    def Close(self):
        pass
I won't update this project therefore, AI tools are great if you want to use it. This is true for all my stub file projects, as AI tools can understand them quite well for general use and understanding. With ChatGPT, Bard, Custom GPTs, Copilot Chat, localGPT and other tools, I have enough data sources that make it relatively straightforward for the AI tools to do what I want. The parameter info being included in this project really helps AI tools along with your guidance. Much more work to do, but with AI, things are changing so much and so fast that I'm rethinking traditional workflows completely.

Some prompts/inputs and ideas:
- Python 3 to IronPython 2.7 (or Python 2.7 they are not the same but related).
- IronPython 2.7 compatible code in Python 3 (variations of the same question do matter sometimes).
- Any questions or commands related to Python 3 and IronPython 2.7 should work as expected.
- If you have existing code or code in a structure you want to match or add to the stub files AI can help.
- You can explain missing code to have added to AlibreScript.py or the individual Python source files.
- Any errors inside editors/IDEs can be used as input to the AI.
- Cleanup can be done with regexes and Find and Replace.
- Remove self with Find and Replace (which I include based on some tests to make PyCharm or Jupyter happy but is not needed depending on how you import the file, editor settings, etc.)
- Example scripts can help train/guide the AI
- https://github.com/Testbed-for-Alibre-Design/alibre-script-examples/blob/master/README.md
- https://github.com/Testbed-for-Alibre-Design/alibre-script-library-examples/blob/master/README.md
- Enums, missing code, return types and other things that didn't convert properly or at all from .NET to Python can be fixed using AI. I didn't spend much time on the converter code, and my Python skills are at a scripter level.

It is possible, of course, to only use a single or subset of the output Python source files for your project or curiosity if the merged AlibreScript.py in the bin folder is too much.

This thread/post concludes my work on Alibre Script stub files and related topics on the forum.

Happy Holidays and Happy New Year!:)

Edit:
I pushed some changes to master -> Added AlibreScript2.py removed self and misc. changes
Here is the previous commit tree -> https://github.com/Testbed-for-Alib...tree/fd246518c26cb1809f819970d7c7b98cff8b5f55
 
Last edited:
Top