What's new

Alibre Script - script requests

idslk

Alibre Super User
Hello @Mika ,
if it can be activated from settings. Default it's no need to be visible.
do you want to "hide" the script functionality in general (which is given with script launch button) or do you want to "hide" selected scripts in particular?
Are your scripts are stored on a server or on the each workstation?
If your CAD workers do not have to alter the scripts (-> no need to see the code) it's the best you save them as protected and run them as protected.
[Copied from post gridgenerator:
Ps.: If you create a folder named Auto or some name with eg. A as the first letter inside your skript library
and put the protected scripts into, you gone have a kind of text buttons for quick access of "functions"...
index.php

]
Do you have the need to transfer the scripts with your part or assembly file?
May you can describe a sample workflow for your job.
Regards
Stefan
 

Mika

Senior Member
Hide the scripts functionality in general, it could be actually hidden as default when you do clean install of Alibre
 

idslk

Alibre Super User
Hello @Mika ,
there is no clean install neccessary.
If you want to disable the scripting functionality in general, goto Addon Manager on Home Window and uncheck Alibrescript.
This will remove the script tab from your menu as long as it is unchecked...
upload_2020-1-25_15-20-41.png

upload_2020-1-25_15-21-42.png

upload_2020-1-25_15-24-52.png
Regards
Stefan
 

jokejoke

Member
Hello,

does anyone have a script that can export every part from assembly model into separate *.stl? I have assembly model with for example 20 parts - and if I want print it on 3D printer I have to open separately every part and export it like *.stl. And assembly model has also many non printable parts (nuts, bolts etc...) it could by perfect if exist same type of part attribut (printable/non-printable) and than export only printable parts. Thank you :)
 

NateLiquidGravity

Alibre Super User
Hello,

does anyone have a script that can export every part from assembly model into separate *.stl? I have assembly model with for example 20 parts - and if I want print it on 3D printer I have to open separately every part and export it like *.stl. And assembly model has also many non printable parts (nuts, bolts etc...) it could by perfect if exist same type of part attribut (printable/non-printable) and than export only printable parts. Thank you :)
This is just a fast one that exports every part as an STL into the selected folder. It is based on the STL Exporter example - however this one I removed the options and bottom face selection.
Code:
# exports rotated STLs with a specific face on the bottom
import os
import re

ScriptName = 'STL Exporter Assembly'

Win = Windows()


# called when an input changes in the dialog window
def InputChanged(Index, Value):
    return

# updates the user interface based on the current selections made
def UpdateUserInterface():
    return

# get current settings, if any
CurrentSettings = CurrentAssembly().GetUserData('alibre.stlexporter.settings')
if CurrentSettings == None:
  CurrentSettings = {}

# define options to show in dialog window
Options = []
Options.append(['Folder Name', WindowsInputTypes.Folder, CurrentSettings['FolderName'] if 'FolderName' in CurrentSettings else None])
Index_FolderName = 0

# show dialog to user, get inputs
Values = Win.OptionsDialog(ScriptName, Options, 170, InputChanged, UpdateUserInterface)
if Values == None:
  sys.exit()

# get the inputs
CurrentSettings['FolderName'] = Values[Index_FolderName]

# update settings on assembly
CurrentAssembly().SetUserData('alibre.stlexporter.settings', CurrentSettings)

if CurrentSettings['FolderName'] == "":
  Win.ErrorDialog('No FolderName entered', ScriptName)
  sys.exit()
 

# export stl
Assem = CurrentAssembly()
print('Exporting:')
for p in Assem.Parts:
    MyPart = p
    MyPartName = MyPart.Name
    MyPartNameClean = re.sub(r'[\\/\:*"<>\|\.%\$\^&£]', '', MyPartName)
    MyFullPath = os.path.join(CurrentSettings['FolderName'], MyPartNameClean)
    print(MyFullPath)
    MyPart.ExportSTL(MyFullPath)

Win.InfoDialog('Export completed', ScriptName)
 
Last edited:

jokejoke

Member
Thank you @NateLiqGrav - it is very helpful :) For 3D printing would be great define bottom face directly in the individual models and then the script can directly export it in correct orientation.
 

NateLiquidGravity

Alibre Super User
Thank you @NateLiqGravFor 3D printing would be great define bottom face directly in the individual models and then the script can directly export it in correct orientation.
Note: This will loop thru EVERY part in the assembly. Each part will open in another window for selecting the face. If you don't select a face it will output without reorienting or using any options. THIS CAN CAUSE MISMATCHED SCALES.
Code:
# exports rotated STLs with a specific face on the bottom
import os
import re

ScriptName = 'STL Exporter'

Win = Windows()


# get current settings, if any
CurrentSettings = CurrentAssembly().GetUserData('alibre.stlexporter.settings')
if CurrentSettings == None:
  CurrentSettings = {}

# define options to show in dialog window
Options = []
Options.append(['Folder Name', WindowsInputTypes.Folder, CurrentSettings['FolderName'] if 'FolderName' in CurrentSettings else None])
Options.append([None, WindowsInputTypes.Label, "Note: This will loop thru EVERY part in the assembly. Each part will open in another window for selecting the face. If you don't select a face it will output without reorienting or using any options."])
Index_FolderName = 0

# show dialog to user, get inputs
Values = Win.OptionsDialog(ScriptName, Options, 300)
if Values == None:
  sys.exit()

# get the inputs
CurrentSettings['FolderName'] = Values[Index_FolderName]

if CurrentSettings['FolderName'] == "":
  Win.ErrorDialog('No FolderName entered', ScriptName)
  sys.exit()


def ExportWithOptions(MyPart):
  
    # called when an input changes in the dialog window
    def InputChanged(Index, Value):
        # use custom settings changed
        if Index == Index_UseCustom:
            UpdateUserInterface()
        return

    # updates the user interface based on the current selections made
    def UpdateUserInterface():
        UseCustom = Win.GetInputValue(Index_UseCustom)
        if UseCustom == True:
            Win.EnableInput(Index_MaxCellSize)
            Win.EnableInput(Index_NormalDeviation)
            Win.EnableInput(Index_SurfaceDeviation)
        else:
            Win.DisableInput(Index_MaxCellSize)
            Win.DisableInput(Index_NormalDeviation)
            Win.DisableInput(Index_SurfaceDeviation)
        return
      
    MyPartName = MyPart.Name
    MyPartNameFirstPass = re.sub(r'<.*>', '', MyPartName)
    MyPartNameClean = re.sub(r'[\\/\:*"<>\|\.%\$\^&£]', '', MyPartNameFirstPass)
    MyFullPath = os.path.join(CurrentSettings['FolderName'], str(MyPartNameClean) + ".stl")
    print('\n')
    print(MyPartName)
    TempPart = Part(MyPart.FileName, 0)
    imgPath = os.path.join(CurrentSettings['FolderName'],"Temp.bmp")
    TempPart.SaveSnapshot(imgPath,800,600,1,0)
  
    # define options to show in dialog window
    Options = []
    Options.append(['File Name', WindowsInputTypes.SaveFile, MyFullPath])
    Index_FileName = 0
    Options.append(["Note:\nEach part will open in\nanother window for\nselecting the face.\nIf you don't select a\nface it will output\nwithout reorienting or\nusing any options.", WindowsInputTypes.Image, imgPath, 170])
    Options.append(['Bottom Face', WindowsInputTypes.Face, None])
    Index_BottomFace = 2
    Options.append(['Force STL units to millimeters', WindowsInputTypes.Boolean, CurrentSettings['ForceMM'] if 'ForceMM' in CurrentSettings else False])
    Index_ForceMM = 3
    Options.append(['Use Custom Settings', WindowsInputTypes.Boolean, CurrentSettings['UseCustom'] if 'UseCustom' in CurrentSettings else False])
    Index_UseCustom = 4

    Options.append(['Custom Normal Deviation', WindowsInputTypes.Real, CurrentSettings['NormalDev'] if 'NormalDev' in CurrentSettings else 10])
    Index_NormalDeviation = 5
    Options.append([None, WindowsInputTypes.Image, 'NormalDeviation.jpg', 100])

    Options.append(['Custom Surface Deviation', WindowsInputTypes.Real, CurrentSettings['SurfaceDev'] if 'SurfaceDev' in CurrentSettings else 0])
    Index_SurfaceDeviation = 7
    Options.append([None, WindowsInputTypes.Image, 'SurfaceDeviation.jpg', 100])

    Options.append(['Custom Max Cell Size', WindowsInputTypes.Real, CurrentSettings['MaxCellSize'] if 'MaxCellSize' in CurrentSettings else 0])
    Index_MaxCellSize = 9
    Options.append([None, WindowsInputTypes.Image, 'MaxCellSize.jpg', 100])
    #Options.append([None, WindowsInputTypes.Label, "Note:\nEach part will open in another window for selecting the face. If you don't select a face it will output without reorienting or using any options."])
  
    

    # show dialog to user, get inputs
    Values = Win.OptionsDialog(str(ScriptName) + ': ' + str(MyPartName), Options, 170, InputChanged, UpdateUserInterface)
    if Values == None:
        print('^ Skipped')
        TempPart.Close()
        return

    # get the inputs
    BottomFace = Values[Index_BottomFace]
    if BottomFace == None:
        print('^ No bottom face selected - Exported without reorienting or using any options.')
        TempPart.ExportSTL(MyFullPath)
        print('Saved: ' + str(CurrentSettings['FileName']))
        TempPart.Close()
        return
    CurrentSettings['BottomFace'] = BottomFace.Name
    CurrentSettings['FileName'] = Values[Index_FileName]
    CurrentSettings['ForceMM'] = Values[Index_ForceMM]
    CurrentSettings['UseCustom'] = Values[Index_UseCustom]
    CurrentSettings['MaxCellSize'] = Values[Index_MaxCellSize]
    CurrentSettings['NormalDev'] = Values[Index_NormalDeviation]
    CurrentSettings['SurfaceDev'] = Values[Index_SurfaceDeviation]

    # update settings on part
    CurrentAssembly().SetUserData('alibre.stlexporter.settings', CurrentSettings)

    if CurrentSettings['FileName'] == "":
        print('^ No filename entered')
        Win.ErrorDialog('No filename entered', ScriptName)
        TempPart.Close()
        return
    

    # export rotated stl
    TempPart.ExportRotatedSTL(CurrentSettings['FileName'], BottomFace,
        CurrentSettings['ForceMM'], CurrentSettings['UseCustom'], CurrentSettings['MaxCellSize'],
        CurrentSettings['NormalDev'], CurrentSettings['SurfaceDev'])
    print('Saved: ' + str(CurrentSettings['FileName']))
    TempPart.Close()
    return


# export rotated stl
Assem = CurrentAssembly()
print('Exporting:')
for p in Assem.Parts:
    ExportWithOptions(p)

Win.InfoDialog('Export completed', ScriptName)
 

jokejoke

Member
Hello @NateLiqGrav,

you are a master of coding :) When I try the second script I got these error:

Code:
Exporting:

HeatSink_v0<1>
Traceback (most recent call last):
  File "<string>", line 139, in <module>
  File "<string>", line 94, in ExportWithOptions
IOError: [Errno 2] C:\Users\Martin\Desktop\NormalDeviation.jpg

It creates only one *.bmp file in the selected folder.
 

NateLiquidGravity

Alibre Super User
Yes, sorry - I should have explained more. It uses the example STL Exporter script as a base - including the images. That script must be saved in the same folder as the images or the images must be copied to the folder with the script. I'm away from my computer but I believe the folder is named something like Alibre Scripts/Examples/Import and Export.
 

jokejoke

Member
Yes, sorry - I should have explained more. It uses the example STL Exporter script as a base - including the images. That script must be saved in the same folder as the images or the images must be copied to the folder with the script. I'm away from my computer but I believe the folder is named something like Alibre Scripts/Examples/Import and Export.
Thank you I will try it, but I think that the first script is better for my purposes :)
 

TimoCAD

Senior Member
Name: dxf2partsketch
What it does: The User imports a dxf file into an existing or new 2dsketch of an existing or a New part file *.ad_prt
Things it should consider:
- Should work in an existing or New part
- Should work in an existing or New sketch
- dxf check if closed contour would be fine
 

TimoCAD

Senior Member
Name: animate_assembly
What it does: The script animates an assembly based on it's assembly constraints for Video creation and presentation of a mechanical assembly
Things it should consider:
- modes: animates once, animates loop
- Animation over time to synchronize different constraint actuators
- Video export in severe file formats
- doing measurements during Animation and export those over the timesteps
 

HaroldL

Alibre Super User
This is for one of the programming gurus if they're feeling ambitious.

Name:
60 Degree Thread Form - Unified and Metric
What it does: Creates the 60 degree thread profile and performs a Helical Cut on a cylindrical part to a user defined length. The thread form it creates can be either internal or external threads.
Things it should consider: It should give the user a dialog to enter the diameter of the part and length of the threaded portion along the part. The diameter could be either by keyed in or "read" by mouse selection of the part edge. The user can also select if the thread is internal or external.
Using a matrix of thread data it would create the profile and position it at the end of the part then perform the Helical cut to create the thread feature.
The thread data could be taken from the info I have uploaded in the Resources.
 

HaroldL

Alibre Super User
Does anyone have a script that draws a Rack and Pinion set? That draws 2 separate drawings, 1 for the gear and 1 for the rack.

Here is a picture (I found on the web) of what I am trying to model. I really like the helx gear becuase there will be very little slop/backlash:


View attachment 29030
Is it just me or is something wrong with the rack in the picture in this post? It doesn't look like it will mesh with the pinion gear.o_O
 

oldfox

Alibre Super User
Hey Harold, it looks fine to me, but ya gotta use the secret trick. (pssssst... for your eyes only... don't pass this on to anyone else)

Close one eye, squint the other and then cock your head to the squinted side at 35.2783 degrees and then look at it.

See??? Works just fine.:D

ps. You're right!
 

HaroldL

Alibre Super User
Nothing wrong, it's a helical rack and pinion.
It must be the angle the photo is taken from, it appears that the rack teeth are perpendicular to the sides of the rack and would crash into the pinion. The rack gear angle is not as apparent as in this image:

Helical-Rack-and-Pinion-Options-for-Higher-Performance-1080x607.jpg
 
Top