Export STL script

I found this useful script by @Helvetosaur for automated STL export (including meshing with presets).
Is it possible to modify it so that:
a) current document name is assigned as STL name?
b) it skips mesh setting if meshes are selected for export (not to modify existing mesh)?

Option Explicit
'Script by Mitch Heynick
'Version Thursday, 11 February, 2010

Call ExportSTLWithSettings()

Sub ExportSTLWithSettings()

	Dim arrObjs,strFileName,strSett

	arrObjs = Rhino.GetObjects("Select objects to export as .stl", 8 + 16 + 32,, True)
	If Not IsArray(arrObjs) Then Exit Sub

	strFileName = Rhino.SaveFileName("Export STL", "STL Files (*.stl)|*.stl||")
	If IsNull(strFilename) Then Exit Sub

	strSett = STLSettings() 'gets your settings from the function below
	If IsNull(strSett) Then
		Call Rhino.Print("Unable to get export settings")
		Exit Sub
	End If
	Call Rhino.SelectObjects(arrObjs) 'selects your objects

	'runs the export using the file name/path and your settings
	Call Rhino.Command("-_Export " & chr(34) & strFileName & chr(34) & " " & strSett)

End Sub

Function STLSettings()

	STLSettings = Null
	Dim str1,str2,str3,str4,str5,str6,str7,str8,str9,str10
	Dim str11,str12,str13,str14,str15,str16,str17,str18
	Dim strComb

	str1 = "_ExportFileAs=_Binary "
	str2 = "_ExportUnfinishedObjects=_Yes "
	str3 = "_UseSimpleDialog=_No "
	str4 = "_UseSimpleParameters=_No "
	str5 = "_Enter _DetailedOptions "
	str6 = "_JaggedSeams=_No "
	str7 = "_PackTextures=_No "
	str8 = "_Refine=_Yes "
	str9 = "_SimplePlane=_No "
	str10 = "_Weld=_No "
	str11 = "_AdvancedOptions "
	str12 = "_Angle=15 "
	str13 = "_AspectRatio=0 "
	str14 = "_Distance=0.01 "
	str15 = "_Grid=16 "
	str16 = "_MaxEdgeLength=0 "
	str17 = "_MinEdgeLength=0.0001 "
	str18 = "_Enter _Enter"

	strComb = str1 & str2 & str3 & str4 & str5 & str6 & str7 & str8 & str9 & str10
	strComb = strComb & str11 & str12 & str13 & str14 & str15 & str16 & str17 & str18

	STLSettings = strComb
End Function

You just need an updated version of the script…

This will use the current file name and propose to save the STL to the same directory as the Rhino file as long as it has been saved, otherwise it will ask for a file name/directory.

You can modify the meshing parameters to suit in the lower half of the script. Note that the meshing settings do not affect meshes, as Rhino does not re-mesh mesh objects - simply if there are quads in the mesh object, they will be triangulated on stl export (STL only supports triangles).

If you want to choose the directory independently, I can modify the script, let me know…</del.>

–Mitch

ExportSTLWithSettings.rvb (2.0 KB)

Thanks, that’s it!

Yeah, it was just a simple triangulation, no magic…

HI All!
It really works great!
The only thing that I would like to modify - get rid of long triangles. Which parameter is responsible for this?

For example, take a standard cylinder and export it to STL.
You can see a large number of long triangles

_
_
_
_
_

I would like to see the same size triangles and regular shape.

Or even be something like that

Thanks

Well, you could try changing the aspect ratio (str13 near the bottom) to something like 3… Or you could put some number in the MaxEdgeLength (str16) - that number is absolute in file units, so all your triangles will have sides no longer than that value…

If you hit Help (F1) while in the Mesh command you will get a good description of what the individual settings do…

–Mitch

Thank you Mitch!
This is very valuable information for me.
Now I want to assign this script on the toolbar button.

I copied the text of the script and make appropriate adjustments to export meshs.

! _-Runscript (
“contents of the script”

but the script does not work.

Help me understand what was going on.

Maybe you forgot the close parentheses at the end?

! _-Runscript ( <contents of the script> )

Maybe the script is not loaded?
You could try adding the RVB file to the list under Options/RhinoScript or just use LoadScript instead of RunScript:

-_LoadScript "C:\...rvb"

Thank you very Much!
I do not understand what has caused but now works :slight_smile:

Mitch, I a little altered your script for export to DXF.
Works fine but I do not know how to implement the Function DXFSettings()
Is it possible to exclude export surface and polysurface, export curves only?

            ! _-Runscript (
Option Explicit
'Script by Mitch Heynick
'Version 21 March 2012
'added current file name and folder default

Call ExportDXF()

Sub ExportDXF()
	
Dim arrObjs,strCurrDP,strCurrDN,strSaveDN,strFileName,strSett,filt	
	
	arrObjs = Rhino.GetObjects("Select objects to export as .DXF")
	If Not IsArray(arrObjs) Then Exit Sub
	
	strCurrDP = Rhino.DocumentPath()
	strCurrDN = Rhino.DocumentName()
	filt = "DXF Files (*.DXF)|*.DXF||"
	
	If Not IsNull(strCurrDN) Then
		strSaveDN =Left(strCurrDN,Len(strCurrDN)-3)&"DXF"
		strFileName = Rhino.SaveFileName("Export DXF", filt, strCurrDP, strSaveDN)
	Else
		strFileName = Rhino.SaveFileName("Export DXF", filt)
	End If
	If IsNull(strFilename) Then Exit Sub
	
	strSett = DXFSettings() 'gets your settings from the function below
	If IsNull(strSett) Then
		Call Rhino.Print("Unable to get export settings")
		Exit Sub
	End If
	Call Rhino.SelectObjects(arrObjs) 'selects your objects
	
	'runs the export using the file name/path and your settings
	Call Rhino.Command("-_Export " & chr(34) & strFileName & chr(34) & " " & strSett, False)
	
End Sub

This script woks with R64 only
with R32 doesnt work

Hi
Is it possible to modify this script so that take and assign name from properties and save it name as name STL file

And another script to import STL.
So that to take the name of the imported STL and assign this name to properties

Thanks

2020-03-11_3-03-49