What's new

Alibre Script - script requests

HaroldL

Alibre Super User
On the other hand the end/corner treatment of thin wall features would be a handy thing Alibre could implement right in the thin wall dialog.
I think that would solve a few design issues, at least add some new functionality to Thin features.
Sounds like an enhancement request. Nate, do you want to do the honors?
 

n1kt0

New Member
I have a laser cutter whose control software takes SVG files as input. It would be nice to be able to export Alibre sketches to SVG format so I can use them as input to my cutter.

Is there a way to use the Python scripting interface to iterate through all the elements in a sketch in a part file and export them as 1:1 scaled SVG objects?
 

Max

Administrator
Staff member
I have a laser cutter whose control software takes SVG files as input. It would be nice to be able to export Alibre sketches to SVG format so I can use them as input to my cutter.

Is there a way to use the Python scripting interface to iterate through all the elements in a sketch in a part file and export them as 1:1 scaled SVG objects?

Right click on your sketch > Export SVG:
1701405396299.png
 

Toybuilder

Senior Member
Hi. I would love to use Alibre to generate and export entire family of parts and to name each exported part uniquely.

For example, I have this 3.81mm pitch shrouded header socket modeled so that I can define the size and the number of pins through the global parameter file.
I modify the values in the "Current" configuration and update designs to make each size variation, and then export that to a STEP file before repeating the process for the next number of pins and size.
(PositionD is the distance equivalent of the Positions value, expressed as "mm" so that the body width of Nx3.81+1.0 can be generated)

For now, I've manually created 2, 3, 4, 5 and 6 pin versions in green and in black. I would love to automate the process so it'll generate 2 through 12 pin versions (and to do that over multiple color selections - green, black, blue, orange, red, etc), creating the export filename to match.

Thank you.

1709715405014.png


1709715621877.png


1709716464089.png

1709715375252.png

1709715774335.png
 
Last edited:

ftkalcevic

Member
Name: Constituent search
What it does: Searches the file system for assemblies then searches those assemblies for a particular constituent.
Things it should consider:
I've tried to write something like this, but it is really slow, loading and rendering each assembly.
Rather than searching for a constituent, maybe just list the contents of each assembly to a text file.
 

stepalibre

Alibre Super User
Hi. I would love to use Alibre to generate and export entire family of parts and to name each exported part uniquely.

For example, I have this 3.81mm pitch shrouded header socket modeled so that I can define the size and the number of pins through the global parameter file.
I modify the values in the "Current" configuration and update designs to make each size variation, and then export that to a STEP file before repeating the process for the next number of pins and size.
(PositionD is the distance equivalent of the Positions value, expressed as "mm" so that the body width of Nx3.81+1.0 can be generated)

For now, I've manually created 2, 3, 4, 5 and 6 pin versions in green and in black. I would love to automate the process so it'll generate 2 through 12 pin versions (and to do that over multiple color selections - green, black, blue, orange, red, etc), creating the export filename to match.

Thank you.

Hello @Toybuilder can you break it down into steps?
The program should:
- create new configuration
- create new and/or update parameter or equation
- export to step

Have you tried the part library system? Just curious.

Name: Constituent search
What it does: Searches the file system for assemblies then searches those assemblies for a particular constituent.
Things it should consider:
I've tried to write something like this, but it is really slow, loading and rendering each assembly.
Rather than searching for a constituent, maybe just list the contents of each assembly to a text file.

I use Everything app to find ad_asm or ad_prt files:

1709762284529.png

I export the result list to a json, csv or text file and then pass that file to my tools. Everything does the hard work of finding the files:

Here is the input:

C:\donetoolkit\linqpad\queries\main\-0-Support-Files-And-Content\TopPiece.AD_ASM
C:\donetoolkit\tool-dev\e.AD_ASM
C:\donetoolkit\tool-dev\importing-exporting-data.AD_ASM
C:\donetoolkit\tool-dev\AlibreDesignToDynamoR&D\FromADToDyn.AD_ASM
C:\git\24817-post-168214\layout.AD_ASM
G:\04-12-2023\0_Alibre_Shaver_Assembly\0_Main_Shaver_Assembly.AD_ASM
G:\04-12-2023\0_Alibre_Shaver_Assembly\BladeAssemblyTop.AD_ASM
G:\04-12-2023\0_Alibre_Shaver_Assembly\BladeHouse.AD_ASM
G:\04-12-2023\0_Alibre_Shaver_Assembly\ShaverInterior.AD_ASM
G:\04-12-2023\0_Alibre_Shaver_Assembly\TopPiece.AD_ASM
G:\By-Date\8-12-2021\8-4-2021.AD_ASM

Here is the output:

Code:
C:\donetoolkit\linqpad\queries\main\-0-Support-Files-And-Content\TopPiece.AD_ASM
8C45FC46-DC31-4BFB-BC66-30AC233B7118
67552739-EA6B-44BB-AD9B-75734197EA3E
F963A5D9-9BFC-425A-9594-917983AE246C
68BC1673-841F-463D-8617-62EBFB813241
19C44F1A-D331-46D8-B62B-0055D6C9AE23
GrayHolster.AD_PRT
Spring.AD_PRT
Twister.AD_PRT
TwisterButton.AD_PRT
../../../Users/Midas/AppData/Local/Temp/PackageTempFolder0/
../../../Users/Midas/AppData/Local/Temp/PackageTempFolder0/
 
 
C:\donetoolkit\tool-dev\e.AD_ASM
1027A775-7614-4412-9B2C-FAD549116DF9
6095A15D-91D6-489F-A0F8-8D5767AB74CA
e.AD_PRT
 
C:\donetoolkit\tool-dev\importing-exporting-data.AD_ASM
CD973FCE-0302-45F2-A4CA-6402DC9301F6
B3D55B16-18A6-4773-86A0-472BCAC3DBDF
e3.AD_PRT
 
C:\donetoolkit\tool-dev\AlibreDesignToDynamoR&D\FromADToDyn.AD_ASM
8EFF53B2-05A2-4FC1-A961-CA9A11A4C477
32BF71B7-D17D-47CE-AFAA-4A26B3FAB219
profileA.AD_PRT
 
C:\git\24817-post-168214\layout.AD_ASM
14E60174-164C-48E7-AD9E-2457E5C26B2C
E331F84A-0694-4AA0-9941-1533B74FB264
sketch-0.AD_PRT
 
G:\04-12-2023\0_Alibre_Shaver_Assembly\0_Main_Shaver_Assembly.AD_ASM
596CF356-89C2-4B6C-BCB9-3ED2F808B0A2
CCA77DD2-711F-40D1-AEC7-635D67D0B18E
CB2BBBD8-A242-4FE7-9D32-3C79D6789EEE
ShaverInterior.AD_ASM
BladeAssemblyTop.AD_ASM
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
G:\04-12-2023\0_Alibre_Shaver_Assembly\BladeAssemblyTop.AD_ASM
CB2BBBD8-A242-4FE7-9D32-3C79D6789EEE
85902F23-0094-4D58-8210-7C5CFD73A390
AB06C94C-3F58-48B5-B4D0-268DE45CF24A
BladeHouse.AD_ASM
ShinyTop.AD_PRT
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
G:\04-12-2023\0_Alibre_Shaver_Assembly\BladeHouse.AD_ASM
85902F23-0094-4D58-8210-7C5CFD73A390
EA090FEE-7FDE-4427-AAA7-6CA225C6415E
01569738-2A6C-4B74-8EC0-6766C1B6D38D
5CD85257-0BB9-46B9-8AF5-55987543C45D
BladeHousing.AD_PRT
New Part (1).AD_PRT
New Part (2).AD_PRT
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
G:\04-12-2023\0_Alibre_Shaver_Assembly\ShaverInterior.AD_ASM
CCA77DD2-711F-40D1-AEC7-635D67D0B18E
8C45FC46-DC31-4BFB-BC66-30AC233B7118
3B195584-EA0C-4291-B8DC-32C753F01C66
EDE5F504-9506-4EFA-9DB3-BCEE80EAACD5
CC2C3A18-F378-450F-816F-3FA79D7DA961
40781210-4527-4142-926C-BC2FE73171C5
2D00C44A-28E6-4377-9D54-1A5FA09F4C0E
42B528FD-D9E2-469A-850E-38557E2BD9DD
0A3B8D4A-A184-4442-984B-D5EBB4D2EB2C
27E645B2-818A-40E0-8C04-CF25671E8DFB
05B9F4D6-26CE-42B6-9A29-60C9A9B21D0E
TopPiece.AD_ASM
SmallGear.AD_PRT
RotorDriver.AD_PRT
ClampPiece.AD_PRT
GearSupport.AD_PRT
MotorHousing.AD_PRT
LargeGear.AD_PRT
Motorlead.AD_PRT
MotorAxle.AD_PRT
Motorbushing.AD_PRT
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
G:\04-12-2023\0_Alibre_Shaver_Assembly\TopPiece.AD_ASM
8C45FC46-DC31-4BFB-BC66-30AC233B7118
67552739-EA6B-44BB-AD9B-75734197EA3E
F963A5D9-9BFC-425A-9594-917983AE246C
68BC1673-841F-463D-8617-62EBFB813241
19C44F1A-D331-46D8-B62B-0055D6C9AE23
GrayHolster.AD_PRT
Spring.AD_PRT
Twister.AD_PRT
TwisterButton.AD_PRT
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
C:/Users/Midas/AppData/Local/Temp/PackageTempFolder0/
G:\By-Date\8-12-2021\8-4-2021.AD_ASM
A18C2D6F-6672-4D7D-9360-CD72CA3613B6
74C43C26-2B8B-4688-BE87-46A377EF8AFE
remote_design_from_3dm.AD_PRT

And here is a stripped-down version of my program:

Code:
Dim Hook As IAutomationHook
Dim Root As IADRoot
Sub Main()
    Hook = GetObject(, "AlibreX.AutomationHook")
    Root = Hook.Root
    GetConstInfo()
    Hook = Nothing
    Root = Nothing
End Sub
Sub GetConstInfo()
    For Each item As String In File.ReadAllLines("C:\Users\steph\Desktop\ad_asm_file_list.txt")
        Console.WriteLine(item)
        Dim constituentGuids As Object = Nothing
        Dim constituentNames As Object = Nothing
        Dim constituentRelativeFilePaths As Object = Nothing
        Dim guid As String = Nothing
        Root.GetGuidAndConstituentInformation(item, guid, constituentGuids, constituentNames, constituentRelativeFilePaths)
        Console.WriteLine(guid)
        For Each constituentGuid As String In constituentGuids
            Console.WriteLine(constituentGuid)
        Next
        For Each constituentName As String In constituentNames
            Console.WriteLine(constituentName)
        Next
        For Each constituentRelativeFilePath As String In constituentRelativeFilePaths
            Console.WriteLine(constituentRelativeFilePath)
        Next
    Next
End Sub

The output is hard to read because I have a structure that's not included in the example program.

I've tried to write something like this, but it is really slow, loading and rendering each assembly.

To work with GetGuidAndConstituentInformation() you don't need to have any files open only the home window (Alibre Design.exe is running).

Rather than searching for a constituent, maybe just list the contents of each assembly to a text file.

This is an option but will take more time if it is a batch process, headless mode would be faster.
 
Last edited:

Toybuilder

Senior Member
HI @stepalibre - thanks for your response.
I did not use the parts library because what I'd like to do is to have a script to just automatically generate the variations instead of having to create explicit entries in a table/spreadsheet.
I started to poke around the scripting system and got it almost to do what I want in terms of iterating through the sizes. Unfortunately, updating the global parameter and regenerating doesn't work -- I need the equivalent of clicking on the Update Designs button in the Global Parameters editor.
If I click the Update Designs button manually after the script runs and updates the value, the assembly updates correctly based on the global parameter.
1709785961516.png

Python:
# open global parameters, replace with your own path
Params2= GlobalParameters(r'C:\Users\joech\Dropbox\work\altium\library\Terminal Blocks\3.81mm', 'PinCount')
# get access to a parameter and display the current value


for i in range(4,5):
  Positions=Params2.GetParameter('Positions')
  PositionD=Params2.GetParameter('PositionD')
  print Positions.Value
  print PositionD.Value
  # change the value of the parameter
  Positions.Value=i
  PositionD.Value=i
  MyAssembly = CurrentAssembly()
  MyAssembly.GetConfiguration('Green').Activate()
  MyAssembly.Regenerate()
  for P in MyAssembly.Parts:
    print '%s in %s' % (P, MyAssembly)
    P. Regenerate()
  MyAssembly.ExportSTEP214('c:/temp/green'+str(i)+'.step')
  MyAssembly.GetConfiguration('Black').Activate()
  MyAssembly.Regenerate()
  for P in MyAssembly.Parts:
    print '%s in %s' % (P, MyAssembly)
    P. Regenerate()
  MyAssembly.ExportSTEP214('c:/temp/black'+str(i)+'.step')
 

Toybuilder

Senior Member
Oh, wait, I got it to work by opening the assembly after each parameter update, and then closing it before updating the parameter to the new value and repeating the process.
I have to run the script in a different window than the assembly being worked on -- it's a bit different workflow than to update the open assembly in place.

Code:
# open global parameters, replace with your own path
Params2= GlobalParameters(r'C:\Users\joech\Dropbox\work\altium\library\Terminal Blocks\3.81mm', 'PinCount')
# get access to a parameter and display the current value

for i in range(1,12):
  Positions=Params2.GetParameter('Positions')
  PositionD=Params2.GetParameter('PositionD')
  # change the value of the parameter
  Positions.Value=i
  PositionD.Value=i
  print Positions.Value
  print PositionD.Value
  Params2.Save()
  MyAssembly = Assembly('C:/Users/joech/Dropbox/work/altium/library/Terminal Blocks/3.81mm','HDR_3.81MM.')
  MyAssembly.GetConfiguration('Green').Activate()
  MyAssembly.Regenerate()
  for P in MyAssembly.Parts:
    print '%s in %s' % (P, MyAssembly)
    P. Regenerate()
  MyAssembly.ExportSTEP214('c:/temp/green'+str(i)+'.step')
  MyAssembly.GetConfiguration('Black').Activate()
  MyAssembly.Regenerate()
  for P in MyAssembly.Parts:
    print '%s in %s' % (P, MyAssembly)
    P. Regenerate()
  MyAssembly.ExportSTEP214('c:/temp/black'+str(i)+'.step')
  MyAssembly.Close()

BTW, there's an interesting quirk -- if there is a dot in the filename, it will truncate the "extension" (.81MM in the example above) so I had to add an extra trailing dot.

This is cool -- I now have a way to auto-generate STEP bodies for families of parts used in my EE design tool (Altium)!
1709792143815.png
 

Attachments

  • 1709792116313.png
    1709792116313.png
    83.2 KB · Views: 0

stepalibre

Alibre Super User
Oh, wait, I got it to work by opening the assembly after each parameter update, and then closing it before updating the parameter to the new value and repeating the process.
I have to run the script in a different window than the assembly being worked on -- it's a bit different workflow than to update the open assembly in place.

Code:
# open global parameters, replace with your own path
Params2= GlobalParameters(r'C:\Users\joech\Dropbox\work\altium\library\Terminal Blocks\3.81mm', 'PinCount')
# get access to a parameter and display the current value

for i in range(1,12):
  Positions=Params2.GetParameter('Positions')
  PositionD=Params2.GetParameter('PositionD')
  # change the value of the parameter
  Positions.Value=i
  PositionD.Value=i
  print Positions.Value
  print PositionD.Value
  Params2.Save()
  MyAssembly = Assembly('C:/Users/joech/Dropbox/work/altium/library/Terminal Blocks/3.81mm','HDR_3.81MM.')
  MyAssembly.GetConfiguration('Green').Activate()
  MyAssembly.Regenerate()
  for P in MyAssembly.Parts:
    print '%s in %s' % (P, MyAssembly)
    P. Regenerate()
  MyAssembly.ExportSTEP214('c:/temp/green'+str(i)+'.step')
  MyAssembly.GetConfiguration('Black').Activate()
  MyAssembly.Regenerate()
  for P in MyAssembly.Parts:
    print '%s in %s' % (P, MyAssembly)
    P. Regenerate()
  MyAssembly.ExportSTEP214('c:/temp/black'+str(i)+'.step')
  MyAssembly.Close()

BTW, there's an interesting quirk -- if there is a dot in the filename, it will truncate the "extension" (.81MM in the example above) so I had to add an extra trailing dot.

This is cool -- I now have a way to auto-generate STEP bodies for families of parts used in my EE design tool (Altium)!
View attachment 41248

Yes, the files that reference the global parameters file need to be opened and updated somehow. I often work with multiple instances of Alibre Design running at a time 2 to 3 so I can isolate the sessions by task or project. Another approach you could take is to do everything in code instead of using Alibre's configuration system, essentially building your own. Headless mode would work nicely for this task.
 
Last edited:

NateLiquidGravity

Alibre Super User
@Toybuilder
If you are already scripting the changes you don't need to use the global parameters file at all. You can change the parameters in the assembly directly with the script instead.
 

NateLiquidGravity

Alibre Super User
Name: Constituent search
What it does: Searches the file system for assemblies then searches those assemblies for a particular constituent.
Things it should consider:
I've tried to write something like this, but it is really slow, loading and rendering each assembly.
Rather than searching for a constituent, maybe just list the contents of each assembly to a text file.
Check out ZDB PDM for Alibre Design and Atom3D. It scans for Alibre files and stores the info into a database for faster searching. https://www.alibre.com/forum/index.php?threads/zdb-pdm-for-alibre-design-and-atom3d.22283/
 

stepalibre

Alibre Super User
@Toybuilder
If you are already scripting the changes you don't need to use the global parameters file at all. You can change the parameters in the assembly directly with the script instead.
I was thinking the same thing. Just do it all in code. Using parameters is required for configurations he want, I see two separate use cases here. He could do both all in code.
 

Toybuilder

Senior Member
But aren't parameters local to the assembly or the part? You can't have a parameter from a parent assembly drive the part or vice-versa? Isn't that the reason why global parameters exist?

Or am I looking at this incorrectly?
 

NateLiquidGravity

Alibre Super User
But aren't parameters local to the assembly or the part? You can't have a parameter from a parent assembly drive the part or vice-versa? Isn't that the reason why global parameters exist?

Or am I looking at this incorrectly?
If you aren't scripting that is true. However you can drive assemblies and the parts from the same script - so (unless you use plan to use the global parameters file manually later) the global parameters file just adds an extra layer that is unnecessary.
 

Toybuilder

Senior Member
The parts are not created by the script. They are just being modified. My intent is to be able to point the script at any assembly with constituent parts and sub-assemblies to update themselves without having the script have to know explicitly what parameters to modify - that's the reason why I took the approach I did. Otherwise, my script would need to know the internal details of the assemblies?
 

NateLiquidGravity

Alibre Super User
You would still model your parts and assembly using the parameters names like "Positions" and "PositionD". You would just use Assembly.GetParameter() and Part.GetParameter() and adjust them directly.

There isn't anything wrong with using the global parameters file. It's just a different way to do it.
 

Toybuilder

Senior Member
Ok - so what you're suggesting is that the script would walk through all parts/assemblies in the design and update the parameter in every one of them?

I think one use case that I had in mind but hadn't described earlier is that I might want to open a design and quickly do a one-off version -- like a "50 pin version" when I don't necessarily want to generate all the intermediate sizes by script. As you said, it's just a different way to do it!

Thanks!
 

stepalibre

Alibre Super User
The exporting can be thought of as a separate process from the rest. You could make templates that include the parameters you want by hand and then have a script that does the updating.

Another approach is to do it all in a script the creation, updates and export with or without the global param file.

Another technique is to save the data to a txt or csv file written/read in by your script acting as a global parameter file but it would be more flexible and faster than using AD_GLP.

It wouldn't hurt to try out different solutions to figure out what will work best for you.
 

Toybuilder

Senior Member
The AD_GLP approach is a bit sluggish but easier to understand, I think, as there is only one place where values are updated and then the change flows through the design.
I've already realized quite the time savings with this. I realized that I had one small feature modeled incorrectly. Fixed that and regenerated STEP files for all 24 variations, letting Alibre run in the background for a few minutes while I did other things!

If there was a way to virtually push that "Update all" button, it would really help, though!
 
Top