Automatic exporting a series of .STL files


#1

I have a bunch of polisurfaces to be 3d printed. Is there a plugin or any solution which can export the selected objects in STL one by one into a folder automatically?


(Pascal Golay) #2

Hello - this is a perfect operation to script - I don think I have anything around that does that but I’m pretty sure one or more has been posted here over the years,

-Pascal


(Gustavo Fontana) #3

I have one here by @phcreates that exports by layer, not by object. It might work in the meantime?

also, this is old and it does not work with sublayer, copy what’s below and paste on command line:

-runscript (
’ Written by Peter Harris, 2003
’ Version 1

option explicit

ChooseLayers

Sub ChooseLayers
Dim arrLayers, arrStates(), arrResults, intCount, strLayer, i, arrLayersToExport()
Dim strUnlockCode, blnRedraw, strEmptyLayerTest, blnEmptyOrNot
intCount = 0
arrLayers = Rhino.LayerNames
If IsArray(arrLayers ) Then
For Each strLayer In arrLayers
ReDim Preserve arrStates(intCount)
arrStates(intCount) = Rhino.IsLayerOn(strLayer)
intCount = intCount + 1
Next
arrResults = Rhino.CheckListBox (arrLayers, arrStates, “Choose layers to export”, “Export Layers”)
If IsArray(arrResults) Then
intCount = 0
For i = 0 To UBound(arrLayers)
If arrResults(i) = vbTrue Then
strEmptyLayerTest = arrLayers(i)
blnEmptyOrNot = Rhino.IsLayerEmpty(strEmptyLayerTest)
If blnEmptyOrNot <> True Then
ReDim Preserve arrLayersToExport(intCount)
arrLayersToExport(intCount) = arrLayers(i)
Rhino.LayerMode arrLayers(i), 0
blnRedraw = Rhino.EnableRedraw(vbFalse)
strUnlockCode = “_UnlockSelected -SelLayer " & CHR(34) & arrLayersToExport(intCount) & CHR(34) & " enter”
Rhino.Command strUnlockCode, vbfalse
Rhino.Command “_selnone”, vbFalse
intCount = intCount + 1
End If
End If
Next
blnRedraw = Rhino.EnableRedraw(vbTrue)
If IsArray(arrLayersToExport) Then
GetFormat arrLayersToExport
End If
End If
End If

End Sub

Sub GetFormat (arrLayersToExport)
Dim arrFormatOptions(3), strFormatResult, strExportFormat
Dim strFlavorString, strExportPath
arrFormatOptions(0) = “IGES”
arrFormatOptions(1) = “STEP”
arrFormatOptions(2) = “STL”
arrFormatOptions(3) = “3DM”
strFlavorString = “”
strFormatResult = Rhino.ListBox(arrFormatOptions, “Pick export format:”, “FP Batch Export”)
If Not IsNull(strFormatResult) Then
Select Case strFormatResult
Case “IGES”
strExportFormat = “igs”
strFlavorString = strIGESFlavorStringFunction
Case “STEP”
strExportFormat = “stp”
strFlavorString = strSTEPFlavorStringFunction
Case “STL”
strExportFormat = “stl”
strFlavorString = strStlFlavorStringFunction
Case “3DM”
strExportFormat = “3dm”
strFlavorString = str3dmFlavorStringFunction
End Select
If strFlavorString <> “” Then
strExportPath = strPath
If strExportPath <> “” Then
ExportFiles strExportFormat, strFlavorString, strExportPath, arrLayersToExport

  End If
End If

End if
End Sub

'----------STL-------------
Function strStlFlavorStringFunction
Dim strMeshWarning
strMeshWarning = Rhino.MessageBox (“Please note - only mesh objects will be exported!”, 1)
If strMeshWarning <> 2 then
Rhino.Command “_point 0,0,0 _SelMesh _Invert _Lock”, vbfalse
strStlFlavorStringFunction = " ExportFileAs=Binary ExportUnfinishedObjects=Yes _enter _enter"
End If
End Function

'----------3DM-------------
Function str3dmFlavorStringFunction
str3dmFlavorStringFunction = " "
End Function

'----------STEP-------------
Function strSTEPFlavorStringFunction
Dim arrStepFlavors(2), strExportResult, RunTheScript, strStepFlavor, strStepLetterCode
arrStepFlavors(0) = “AP203ConfigControlDesign”
arrStepFlavors(1) = “AP214AutomotiveDesign”
arrStepFlavors(2) = “AP214AutomotiveDesignCC2”
strStepFlavor = Rhino.ListBox(arrStepFlavors, “Pick STEP flavor:”, “Batch Export”)
If Not IsNull(strStepFlavor) Then
Select Case strStepFlavor
Case “AP203ConfigControlDesign”
strStepLetterCode = “A”
Case “AP214AutomotiveDesign”
strStepLetterCode = “P”
Case “AP214AutomotiveDesignCC2”
strStepLetterCode = “U”
End Select
strSTEPFlavorStringFunction = " s " & strStepLetterCode & " _enter"
End if
End Function

'----------IGES-------------
Function strIGESFlavorStringFunction
Dim arrIgesFlavors(8), strExportResult, RunTheScript, strIgesFlavor
arrIgesFlavors(0) = “Default”
arrIgesFlavors(1) = “Pro/E Windows solids”
arrIgesFlavors(2) = “Pro/E Windows surfaces”
arrIgesFlavors(3) = “SolidWorks Solids”
arrIgesFlavors(4) = “SolidWorks Surfaces”
arrIgesFlavors(5) = “Alias V8.x”
arrIgesFlavors(6) = “Maya”
arrIgesFlavors(7) = “Mastercam”
arrIgesFlavors(8) = “Ashlar Vellum”
strIgesFlavor = Rhino.ListBox(arrIgesFlavors, “Pick IGES flavor:”, “Batch Export”)
If Not IsNull(strIgesFlavor) Then
strIGESFlavorStringFunction = " " & CHR(34) & strIgesFlavor & CHR(34) & " _enter"
End if
End Function

'----------Get the path-------------
Function strPath
Dim strFilename
strFilename = Rhino.SaveFileName (“Pick a folder and create a name prefix”)
If Not IsNull(strFilename) Then
strPath = strFilename
End If
End Function

'----------Export-------------
Sub ExportFiles (strExportFormat, strFlavorString, strExportPath, arrLayersToExport)
Dim strLayerX, strNumOfFiles
strNumOfFiles = 0

For each strLayerX in arrLayersToExport

strNumOfFiles = strNumOfFiles + 1

Rhino.Command “selnone", vbFalse
Rhino.command "-sellayer " & CHR(34) & strLayerX & CHR(34)’, vbfalse
Rhino.command "-export " & CHR(34) & strExportPath & "
” & strLayerX & “.” & strExportFormat & CHR(34) & strFlavorString’, vbfalse
Next
Rhino.command “_selnone”, vbfalse
Rhino.Print “Use Undo to get back to where you were before the export, if needed. Export info has also been sent to clipboard.”

WriteShopInfoToClipboard strNumOfFiles, strExportPath
End Sub

’ ---------------------------- write info to clipboard --------------------------------------
Sub WriteShopInfoToClipboard (strNumOfFiles, strExportPath)
Dim FindSlash, strFileNameForClipboard, strCropped, LengthOfString, CounterX, strRunPath

strRunPath = strExportPath
CounterX = 0
While CounterX < 9
FindSlash = InStr(strExportPath,"")
LengthOfString = Len(strExportPath) - FindSlash
strCropped = Right(strExportPath,LengthOfString)
strExportPath = strCropped
If FindSlash = 0 then
CounterX = 9
End If
Wend

Rhino.ClipboardText ("All " & strNumOfFiles & " files with the prefix " & CHR(34) & strExportPath & CHR(34))
'Rhino.Command "_-Run " & CHR(34) & strRunPath & CHR(34)
End Sub
)


#4

Hi Gustavo,
Thank you very much sharing his script with me. Unfortunately I am using standard Grasshopper widgets, and I am not familiar with programming. How can use this?


#5

Here are two somewhat more recent scripts from my library.

This one has 4 pre-made settings choices: Coarse, Medium, Fine and Extra Fine… choose one.

BatchExportSTLByObjWSett.py (3.9 KB)

This one just has one setting, you can open the script file in any text editor and change the settings as you like and then re-save the file. You will recognize the settings from the Rhino mesh detailed options.

BatchExportSTLByObjWFixedSettings.py (1.8 KB)

image

In both cases the export is by object - one file per object exported - and will export directly to the folder with the original Rhino 3dm file, or if the file has not been saved it will ask you to choose a folder.

To run the script, save it somewhere on your hard drive and then use

! _-RunPythonScript "full path to script file"

or just open it in the script editor (EditPythonScript) and run it from there.

–Mitch


#6

Hi Mitc,
Is it a pithyon widget?


#7

No widget. This runs in Rhino and does not need Grasshopper.


#8

thank you it works perfectly!


#9

Is it possibele to decide from which number starts the numbering? I am processing several group of obejects.
If something goes wrong it would be much esaiser to figure out which part should be produced again…


#10

It’s certainly possible to add that…

Wouldn’t it be better in that case to name/number the objects themselves and have the filename correspond with the name/number of the object?


#11

Certainly it would be better, but the parts are baked geometry. The ID is written on the side of the part too.


#12

OK - which of the two scripts above are you using? (or both)


#13

I have tried the one with four setting, but I need usually one extraifine setting in the future, so I think I would use the second one.


#14

OK, have a go with this one…

BatchExportSTLByObjWFixedSettingsPlus.py (1.9 KB)


#15

Thank you very much for your time and kindness. I am at work now. I will try it tonight.


#16

It works great! Thank you!