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?
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
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
)
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?
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)
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
Hi Mitc,
Is it a pithyon widget?
No widget. This runs in Rhino and does not need Grasshopper.
thank you it works perfectly!
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âŚ
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?
Certainly it would be better, but the parts are baked geometry. The ID is written on the side of the part too.
OK - which of the two scripts above are you using? (or both)
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.
Thank you very much for your time and kindness. I am at work now. I will try it tonight.
It works great! Thank you!
Hi everyone,
I am trying to save multiple STL files in a subfolder of the current working directory, but it keeps saving the objects in the current working directory (i.e. where the 3dm file is stored) instead of the subfolder. My commands are as following:
curDir=rs.WorkingFolder()
folderDir = curDir+âfragments/â
os.mkdir(folderDir)
for name in objNames:
fileName = os.path.join(folderDir, name+â.stlâ)
rs.Command(â_-Export '+fileName)
But it keeps saving the stl files as
curDir/name+â.stlâ
instead of curDir/fragments/name+â.stlâ
Any suggestions how to solve this?
Thank you!
Simon
I used the code that Helvetosaur sent. However, In my command line there are no âDetailedOptionsâ with the Export command. I can set the Distance, Grid etc, but not decide whether or not to Refine the mesh. Also manually the command line returns it is an invalid option at each step in the command.
Does anyone where the cause of my problem lies?
Thanks!
What version of Rhino are you running? How are you running the script?
Rhino 6. Run the python script in Rhino Python editor:
import rhinoscriptsyntax as rs
def GetSTLSettings():
e_str = "_ExportFileAs=_Binary "
e_str+= "_ExportUnfinishedObjects=_Yes "
e_str+= "_UseSimpleDialog=_No "
e_str+= "_UseSimpleParameters=_No "
e_str+= "_Enter _DetailedOptions "
e_str+= "_JaggedSeams=_Yes "
e_str+= "_PackTextures=_Yes "
e_str+= "_Refine=_Yes "
e_str+= "_SimplePlane=_Yes "
e_str+= "_AdvancedOptions "
e_str+= "_Angle=2 "
e_str+= "_AspectRatio=0 "
e_str+= "_Distance=10 "
e_str+= "_Grid=4 "
e_str+= "_MaxEdgeLength=0 "
e_str+= "_MinEdgeLength=0.003 "
e_str+= "_Enter _Enter"
return e_str
def ExportSTLByObject():
a = rs.GetObject()
rs.SelectObject(a)
stl_sett = GetSTLSettings()
file_name = r'C:\Users\j.vanderidder\Documents\test3.stl'
rs.Command('-_Export "{}" {}'.format(file_name,stl_sett), False)
rs.EnableRedraw(True)
ExportSTLByObject()