What's new

Alibre Scripting Assistance

VECDESIGN

Senior Member
I am trying to develop some custom scripts for Alibre. Do you know what AI assistance could be helping based on your experience and limitations? Thanks.
 

stepalibre

Alibre Super User
Be sure to understand what the Alibre Script API includes.

Working examples:



Alibre Script R&D:



Help content: (useful for searching for something in the help (content is for V27)


My GPTs are not using my current AI workflow or datasets. ChatGPT or any AI chat tool might give you better results.

My current Alibre AI focus are these databases and related tooling:

Alibre Script

C#/VB/Python

How to get an AI to do what we want is not a simple task. In general providing code that you know works is a good starting point. Always include example code and very clear instructions. The limitations of Gen AI is difficult to answer without a real example. This is what makes generative AI such a game changer and is also what make it difficult to use.
Note:
Alibre Script is IronPython 2.7
Alibre Script and by extension Alibre Design are not widely used with content available for an AI to be trained enough to create Alibre Script code. Over time this should improve.

I'm developing techniques and datasets that can increase code generation accuracy. My code databases are the results. If you can share the types of scripts you're thinking about building I can help step through the process in detail. What is your programming skill level and languages you can code? Today I threw my old function library out the window, and started a new function library project for C#, VB and Python 3 (Pythonnet) that uses AlibreX directly not Alibre Script.
Example:
 

VECDESIGN

Senior Member
Thanks so much for sharing this summary, I will review the info and feedback. It is long time I do not spend my time to programming. My first program was in a SPECTRUM 128K in BASIC and followed with FORTRAN, ASSEMBLY and data management with C end of university. I want to return to that. I know the basic and how data can be structured but lost the language due to non-frequent use. I have developed with a dev team several softwares in my life using VB, PHP as complete ERP and others and we also program microcontrollers for electronics products. I have tried some scripts for testing basic functionalities and I think it promises. Example in next post with issue GPT READING IN SCRIPT.
 
Last edited:

VECDESIGN

Senior Member
I have tried some sections of a bigger script and results are not working yet but I understand it will progress soon. Best results I have got with GTP4o1 not tunned but very similar to the AlibreScript Code Assistant and Alibre Script API Expert. My two main conclusions after a couple of days trying are:
1. If some complex tasks it uses to repeat errors and I have found interesting to prompt advise to prevent these then iterations are much less. Example of these are:
Please take into account next general instructions when generating or reviewing code.
  • Make the code like an expert in Alibre Design Scripting and Alibre Design API.
  • Import all Alibre classes and functions.
  • The script must be done and reviews in all versions with IronPython 2.7.10.0 which is the version used by Alibre Design Scripting section and API.
  • Load all the needed general library and functions for Alibre Script with IronPython 2.7.10.0
  • Integrate Win = Windows() into the script for consistency or potential future use.
  • Do not use f-string Compatibility since is not compatible, use .format() or string concatenation to ensure compatibility with IronPython 2.7.10.0
  • The use of a main() function is not standard, as scripts in Alibre are typically executed directly from the scripting console without requiring an explicit entry point. To adapt your script to this style, please remove the main() function and ensure the logic runs at the global scope without affecting functionality.
  • The exit() function is not directly available in IronPython 2.7, which is used in the Alibre Design scripting environment. To properly handle script termination, use the return statement.
  • The return statement outside of any function is not valid in IronPython scripts for Alibre Design. In the Alibre Design scripting environment, scripts are executed directly without requiring an explicit entry point (like a main() function). The return statement in this context is unnecessary and should be replaced with a different way.
  • The windows object does not have an OpenPart method. Instead, the correct way to work with the current part in the Alibre scripting environment is by using CurrentPart() to get the currently active part in the session.
  • The GlobalParameters object has to be utilized to open, modify, and save the parameter values properly about the GPF.
  • Alibre Script, Parameters is a property, not a callable method.
  • Add debugging prints for console feedback in each step of the scripts so that we can see in console what the script is doing and then we can understand the reading, outputs and other data are properly managed and generated.
  • To display messages to the user, in Alibre scripts use console messages (print()) for debugging and not the Win.Prompt() method neither Win.MessageBox().
  • Comment each line with the detail of what each line is doing and how work the related glasses, methods and functions involved in the line with main parameters and attribute used and available for these.
2. For doing some scripts I definitively need significant help from a human very familiar with Alibre Scripting or become familiar by in depth analyze of each class, method, functions and process involved in the particula Alibre Scripting.

EXAMPLE OF PROMPT USED + GENERAL SPECS ABOVEç
I am not sure it can be really done with actual API but I am trying just to follow and iteration to iteration fix the errors.

Please create a script to read parameters ranges and steps from the GPF, global parameters file. The number of parameters to read data, NUM_USED_PRM, is equal to the number of parameters in the GPF which are marked as favorite in it. There are 4 types of data to read associated to each parameter marked as favorite. The order of the parameters defined must be the order in the list of favorite parameters in the read GPF.
  • First interesting data is the name of each global parameter used,
  • Second used data to set for each parameter is the minimum value each parameter will take in next operations and is called MINV_PRM_ followed by the name of the parameter. We need to read this value from the GPF and it is defined in the GPF so that it is not favorite and is the name of the related parameter followed by _MIN.
  • Third used data to set for each parameter is the minimum value each parameter will take in next operations and is called MAXV_PRM_ followed by the name of the parameter. We need to read this value from the GPF and it is defined in the GPF so that it is not favorite and is the name of the related parameter followed by _MAX.
  • Fourth used data is set for each parameter is an integer, the number of different values that the parameter will have in next operations. It is called NUMV_PRM_ followed by the name of the parameter. We need to read this value from the GPF and it is defined in the GPF so that it is not favorite and is the name of the related parameter followed by _STEPS.
Print each read data in the console for proper execution tracking and debugging.
 

stepalibre

Alibre Super User
Please take into account next general instructions when generating or reviewing code.
  • Make the code like an expert in Alibre Design Scripting and Alibre Design API.
  • Import all Alibre classes and functions.
  • The script must be done and reviews in all versions with IronPython 2.7.10.0 which is the version used by Alibre Design Scripting section and API.
  • Load all the needed general library and functions for Alibre Script with IronPython 2.7.10.0
  • Integrate Win = Windows() into the script for consistency or potential future use.
  • Do not use f-string Compatibility since is not compatible, use .format() or string concatenation to ensure compatibility with IronPython 2.7.10.0
  • The use of a main() function is not standard, as scripts in Alibre are typically executed directly from the scripting console without requiring an explicit entry point. To adapt your script to this style, please remove the main() function and ensure the logic runs at the global scope without affecting functionality.
  • The exit() function is not directly available in IronPython 2.7, which is used in the Alibre Design scripting environment. To properly handle script termination, use the return statement.
  • The return statement outside of any function is not valid in IronPython scripts for Alibre Design. In the Alibre Design scripting environment, scripts are executed directly without requiring an explicit entry point (like a main() function). The return statement in this context is unnecessary and should be replaced with a different way.
  • The windows object does not have an OpenPart method. Instead, the correct way to work with the current part in the Alibre scripting environment is by using CurrentPart() to get the currently active part in the session.
  • The GlobalParameters object has to be utilized to open, modify, and save the parameter values properly about the GPF.
  • Alibre Script, Parameters is a property, not a callable method.
  • Add debugging prints for console feedback in each step of the scripts so that we can see in console what the script is doing and then we can understand the reading, outputs and other data are properly managed and generated.
  • To display messages to the user, in Alibre scripts use console messages (print()) for debugging and not the Win.Prompt() method neither Win.MessageBox().
  • Comment each line with the detail of what each line is doing and how work the related glasses, methods and functions involved in the line with main parameters and attribute used and available for these.
Those are essentially rules in my rules engine, with separate programs that address issues outside of prompting. They are CLI tools that run as tasks, performing checks and adding or removing content.

AlibreScript Code Assistant and Alibre Script API Expert both use my old approach which was based on a subset of the API signatures and example logic. I've since learned to improve accuracy by using separate programs (headless) to process the input/prompt/instruction, system messages and output/responses throughout the process. This reduces token/request count, keeps the chat history clean and is much faster and reliable among other benefits. A very common use case is a program that remove code comments from the chat session. Comments add unnecessary information not needed for the AI to understand the code. I don't like comments in my code during development except for simple notes and commenting out lines. It's fine to add comments after the code is complete and ready to publish or share. For C# and VB I don't mind comments but I've recently started generating source files with and without comments.

Thanks for the feedback.


I forgot to mention this, distracted by football.
You can give instructions to exclude comments, but this is not what I want in every case. The comments generated by AI are useful for understanding what a particular line or function is intended to do. The keywords and information provided in the comments are very valuable especially in long and complex programs. I remove the comments from the session but keep them locally. This allows me to review the entire history comparing the raw session with my modified version.
 
Top