What's new

Access GPF from scripts and Update Designs

VECDESIGN

Senior Member
I am trying to access the actual part and the linked GPF to it from script as first steps as follows. I get the error
Error: No Global Parameter File (GPF) is linked to the current part.
Can you help about about finding the root? Is it better to specifically define hard coded the route to the files and files names?
Thanks.

import math # Import math module for mathematical operations
from AlibreScript import * # Import Alibre Script API
from datetime import datetime # Import for timestamps
import os # Import for file and folder operations


# Debug: Confirm the script starts execution
print("Script has started...") # Notify the user in the console

# Step 1: Access the current part in Alibre
try:
part = CurrentPart() # Attempt to get the currently active part
print("Part loaded: {}".format(part.Name)) # Debug: Part successfully accessed
except Exception as e:
# Handle the error if no part is loaded
print("Error: No part is currently loaded in Alibre.\n{}".format(str(e)))
raise SystemExit # Exit the script if no part is available

# Step 2: Access the Global Parameter File (GPF)
try:
GPF = CurrentGlobalParameters() # Access the GPF linked to the part
print("GPF loaded: {}".format(GPF.Name)) # Debug: GPF successfully accessed
except NameError:
# Handle the error if no GPF is linked
print("Error: No Global Parameter File (GPF) is linked to the current part.")
raise SystemExit # Exit the script if no GPF is available

# Step 3: Create the output folder
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") # Generate a timestamp for unique folder naming
output_folder = os.path.join("C:\\Users\\usuario\\Desktop\\DESIGNBATHS", "{}_{}_{}".format(part.Name, GPF.Name, timestamp))
os.makedirs(output_folder) # Create the output folder
print("Output folder created: {}".format(output_folder)) # Debug: Folder creation successful

# Step 4: Read favorite parameters from the GPF
parameter_names = [param.Name for param in GPF.Parameters if param.IsFavorite] # Retrieve favorite parameters
print("Debug: Favorite parameters found in GPF: {}".format(parameter_names)) # Debug: List of favorite parameters
 

stepalibre

Alibre Super User
Code for the property viewer is open source. It has been a while since I wrote the tool. My motivation was just to gain a better understanding of what was going on inside a part file.
I completely forgot about the data viewer! I use reflection and tracing when debugging but this will go nicely with my current projects to use as a debugging tool.
I forked it a while ago. Is that the latest, I want to pull in any new updates.
 

bolsover

Alibre Super User
I completely forgot about the data viewer! I use reflection and tracing when debugging but this will go nicely with my current projects to use as a debugging tool.
I forked it a while ago. Is that the latest, I want to pull in any new updates.
Code in github repo is almost the latest I'm working on - no time to upload anything more just now.
 

VECDESIGN

Senior Member
I keep testing some capability of the accessing and automation of GLP file data. When I try to rebuild part, current_part.Regenerate() is properly working but the parameters saved in the GLP file are not refreshed in the part. I could not find any refresh design method. Is there any way to do that? I understand the steps are as done manually, first update design, then current_part.Regenerate(). Thanks.
 

NateLiquidGravity

Alibre Super User
I haven't really used global parameters but if the the user must push updates from the global parameter file to the open design then I would assume updates must be pushed similarly using code. Whether exposed in the public AlibreX API or even accessible is another question entirely.
 

stepalibre

Alibre Super User
Yes. At this point, you would have a much better and faster system by using Excel or CSV files and managing the process yourself. I use global parameter files as is without code. When I need to push or pull data, I do it myself. Global parameter files are great for modeling a system and testing equation logic, not for automated workflows or tasks
 

VECDESIGN

Senior Member
I haven't really used global parameters but if the the user must push updates from the global parameter file to the open design then I would assume updates must be pushed similarly using code. Whether exposed in the public AlibreX API or even accessible is another question entirely.
Thanks for replying. I am trying to find a list of all the exposed entities in the public AlibreX API with a good search and parameters explanation but no success. Even searching with current_part.Regenerate() which works fine I can not find. I will keep investigating how to refresh from the global parameter files since seams to be quite basic funcionality.
 

VECDESIGN

Senior Member
Yes. At this point, you would have a much better and faster system by using Excel or CSV files and managing the process yourself. I use global parameter files as is without code. When I need to push or pull data, I do it myself. Global parameter files are great for modeling a system and testing equation logic, not for automated workflows or tasks
Do you mean with the excel add-on? I understand it will add all the excel power but wonder if it could add connection issues too from other app? For now open. close, read, write, create, delete parameters to the global parameters file seams to works fine. I will keep investigating how to refresh from the global parameter files from a script and keep you posted with the results. Thanks.
 

stepalibre

Alibre Super User
Do you mean with the excel add-on? I understand it will add all the excel power but wonder if it could add connection issues too from other app? For now open. close, read, write, create, delete parameters to the global parameters file seams to works fine. I will keep investigating how to refresh from the global parameter files from a script and keep you posted with the results. Thanks.
No. Reading and writing to Excel or CSV directly. It’s fine to use GPF and scripting it. My point was when you hit a wall with Alibre APIs other options exist. You can try AutoIT, AutoHotKey or any macro software to click the refresh button or assist you further. There are examples on the forum, I made one for the project sketch dialog.

 

NateLiquidGravity

Alibre Super User
If you already are using Alibre Script and need the design sessions open and have a list of parameters names and values you can just assign them directly and skip using the Global Parameters file. I guess we would really need to know more about what you want to accomplish overall.
 

VECDESIGN

Senior Member
No. Reading and writing to Excel or CSV directly. It’s fine to use GPF and scripting it. My point was when you hit a wall with Alibre APIs other options exist. You can try AutoIT, AutoHotKey or any macro software to click the refresh button or assist you further. There are examples on the forum, I made one for the project sketch dialog.

Thanks. Before that, I asked support about that since is full rebuild works from part very well. I understand do that from global parameters file is a must since is very useful for assembly and multiple design management. I will inform you what they suggest and hope if not existing the UPDATE function, they will add some time in the near future.
 
Last edited:

VECDESIGN

Senior Member
If you already are using Alibre Script and need the design sessions open and have a list of parameters names and values you can just assign them directly and skip using the Global Parameters file. I guess we would really need to know more about what you want to accomplish overall.
I have a lot of models build based on global parameter files. A very basic function is motion generation as with the script you shared here Motion script needs update for V27. I am trying to modify it but since I can not UPDATE DESIGNS involved in a global parameters file,
1738525893766.png
It is as easy and estrange to me it can not be done from scripting since it is quite basic if I can open, close, read, modify the global parameters data, non sense to does not expect the models update. It is just make the same as current_part.Regenerate() does for a part design but form the global parameters file. Other option is to read the updated data in the global parameters file form the part design but can not see any function for that. I have also thought in re-load the part design file but it closes the script... I could try close and open of the part design from another part design sharing same global parameters file. When part opened it reads the actual global parameters data. Not sure it is possible to script in one part design file to act other part design files. Thanks.
 

Attachments

  • 1738525855803.png
    1738525855803.png
    12.5 KB · Views: 0
Last edited:

stepalibre

Alibre Super User
All these issues is why my programs save all, kills and restarts Alibre for similar reasons. That’s because I make changes to parts and parameters that aren't pushed or pulled into other parts or assemblies. I have programs and scripts running in the background, Alibre session system don't work well for these tasks. Headless does but is used differently. Making changes, saving and then closing and restarting Alibre works perfectly fine.

Alibre's session system is unique it was clearly designed for a single instance, single project, single user environment at a time. This is what makes PDM more problematic and data siloed. Updates occur on top most session first, then down the list of open files. So changes are pushed from the GPF (parent) to files that use a parameter from it (children). This is likely to prevent conflicts and update issues. A method to update design files from the GPF object might still require all children be regenerated/updated and possibility open. Doing this from a part or assembly would be risky without some indicator or notification.


There is a deep regeneration option I can't remember if it would help here.
 

VECDESIGN

Senior Member
All these issues is why my programs save all, kills and restarts Alibre for similar reasons. That’s because I make changes to parts and parameters that aren't pushed or pulled into other parts or assemblies. I have programs and scripts running in the background, Alibre session system don't work well for these tasks. Headless does but is used differently. Making changes, saving and then closing and restarting Alibre works perfectly fine.

Alibre's session system is unique it was clearly designed for a single instance, single project, single user environment at a time. This is what makes PDM more problematic and data siloed. Updates occur on top most session first, then down the list of open files. So changes are pushed from the GPF (parent) to files that use a parameter from it (children). This is likely to prevent conflicts and update issues. A method to update design files from the GPF object might still require all children be regenerated/updated and possibility open. Doing this from a part or assembly would be risky without some indicator or notification.


There is a deep regeneration option I can't remember if it would help here.
I understand and agree that this approach should offer more stable performance and full control over regenerating exactly what you need, as programmed. This method also addresses an issue I’ve frequently encountered with certain models. Specifically, when regenerating parts, some operations (like shell, surface offsetting, and fillets involving spline-based surfaces) occasionally fail to execute with the same accuracy or produce identical results compared to when the file is closed and reopened. I suspect this discrepancy stems from differences in regeneration strategies, accuracy settings, or memory handling between manual regeneration (e.g., clicking "Regenerate") and the full regeneration that occurs when opening the file from scratch.

If anyone is aware of a "deep regeneration" option or tool within the GPL framework that could resolve this, I’d greatly appreciate the insight.

I’ll share updates once I receive a response from Alibre support. If no such option exists, we may need to define specific parameters for these operations using .xlsx or .csv data management to ensure consistency.

Thanks for your input. I’ll keep you posted.
 

stepalibre

Alibre Super User
If anyone is aware of a "deep regeneration" option or tool within the GPL framework that could resolve this, I’d greatly appreciate the insight.
This is likely unrelated to the GPF. It regenerates constituents if set to true. I was thinking the global parameter file was a constituent.
1738702819071.png

It (GPF) appear to be excluded from the update loop.
 

VECDESIGN

Senior Member
Oooh! Unfortunately, I must confirm that it is not possible to update designs from GPF via the API, and no time to implement this feature in the upcoming V28 SP3 release. The good news is that the request has been logged in JIRA for a future version. As multi-license user for a whole life, I’m pleased that one of our improvement requests is being considered. I will provide estimated implementation dates as soon as I have them.

In the meantime, I have also asked for confirmation whether it might be possible to achieve this all models update parts and/or assembly using an .xlsx or .csv file (serving as a container for the model parameters) instead of GPF. For example using external process to Alibre, all open models could be updated by running the corresponding scripts in each or in the external process. I will keep you updated on any progress regarding this functionality and a guide for doing that if I get it. I understand it is very basic function when working with scripting and API, just easy full regeneration and update designs after some changes.
 

VECDESIGN

Senior Member
I am back exploring the update all options from scripting since the GPF has no option. I would like to know if it is possible from the EXCEL ADD-INS. The `process would be to have the designs opened, then one or more sessions and all this files linked to the same excel file with the parameters. Does anyone knows if it is possible to script from only one of the designs so that it can be done a loop in the excel file through all the opened sessions and update all from this excel file? I am seen that the excel is properly updating but I have to select the session manually, it is not updating all sessions even I click Update All. All should be only all parameters. If the excel functions of the EXCEL ADD-INS are exposed by the API, I understand it could be done. Thanks in advance.
 

bolsover

Alibre Super User
Are all the designs to be updated part of a single assembly? If not, I think you would have to manually open each design to be updated - unless you could put all the designs in a single directory. TBH I'm not sure I'd want to do this from Excel - possibly better to write a C# add-on that can read the excel and iterate each of the parts to be updated. Whatever I suspect there are more than a few challenges!
 

VECDESIGN

Senior Member
Are all the designs to be updated part of a single assembly? If not, I think you would have to manually open each design to be updated - unless you could put all the designs in a single directory. TBH I'm not sure I'd want to do this from Excel - possibly better to write a C# add-on that can read the excel and iterate each of the parts to be updated. Whatever I suspect there are more than a few challenges!
Yes all can be parts of the same single assembly. Or even working with only single part design. The excel add-ins actually is not updating even the assembly when parameters are modified in the assembly. You have to regenerate all so that the assembly is updated, Position constrains for example. And for updating the parameters you have to manually select each session. If a way to script a loop to the excel from the assembly, probably it could work. I can not find any info in the API help about any functions for managing the excel associated to the parameters.
 

bolsover

Alibre Super User
C# can read and manipulate excel files and the Alibre API can read and manipulate the part/ assembly files. I think the tricky part is ensuring all the part parameters are named consistently.
 
Top