CATScript Export Binary STL

Purpose:

This script can be used to save the actual catpart as a binary STL file.

You can easily create STL files with the “Catia SaveAs..” native dialog. The only drawback is that Catia by default creates STL in plain text format.

The benefit of a binary STL file format:

  • file size is abut factor 5 smaller so you can save quite a lot of space on the file server,

  • post processing (loading STL files with other programs) usually is quicker

  • binary file format can also be converted back to text format easily (for whatever reason), use the stlconverter provided here to convert in both directions.

Usage of the macro:

Before the macro can be used, the source code needs to be edited.

The only thing that needs to be configured is the file path of the executable which performs the conversation.

So please search for the STL_CONVERTER_EXE variable in the source-code and enter the full path to the STLConverter.exe executable as required.

For convenience, the macro and as well the executable can be stored in the same directory.

' -----------------------------------------------------------------------------
' PRT_ExportBinarySTL.CATscript --
' -----------------------------------------------------------------------------
' (c) 2018, Johann Oberdorfer - Engineering Support | CAD | Software
'     johann.oberdorfer [at] gmail [dot] com
'     www.johann-oberdorfer.eu
' -----------------------------------------------------------------------------
' This source file is distributed under the BSD license.
'   This program is distributed in the hope that it will be useful,
'   but WITHOUT ANY WARRANTY; without even the implied warranty of
'   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
'   See the BSD License for more details.
' -----------------------------------------------------------------------------
' -----------------------------------------------------------------------------

' Option Explicit
Language = "VBSCRIPT"

Const CATSCRIPT_NAME = "Export STL V0.1"
Const EXPORT_FILE_EXT = "stl"
Const STL_CONVERTER_EXE = "DRIVE:\<path where to find executable>\STLConverter.exe"


Sub CATMain ()

	Dim stl_name As String
	Dim current_doc As PartDocument

	' -- check, if there is an active document and the document is a CATPart

	Err.Clear : On Error Resume Next
	Set current_doc = CATIA.ActiveDocument

	If ( Err.Number <> 0 OR _
		InStr(current_doc.Name, ".CATPart") = 0) Then
	
		MsgBox _
			"The active document must be a CATPart!" + vBNewline _
		+	"Please try again!" + vBNewline, _
			vbExclamation + vbOKOnly, "ERROR in Makro: " + CATSCRIPT_NAME

		Exit Sub
	End If
	
	Err.Clear : On Error Goto 0

	CATIA.RefreshDisplay = False


	stl_name = Replace (current_doc.FullName, ".CATPart", "." + EXPORT_FILE_EXT, 1, -1, vbTextCompare)
	' MsgBox "--> " + stl_name

	' export to stl file...
	current_doc.ExportData stl_name, EXPORT_FILE_EXT

	' and create binary file ...
	' ---------------------------------------------------------------------
	CATIA.SystemService.ExecuteProcessus STL_CONVERTER_EXE + " " + stl_name
	' ---------------------------------------------------------------------
	
	' finally remove the ascii STL file:

	Dim fs As FileSystem
	Set fs = CATIA.FileSystem
	
	fs.DeleteFile stl_name

	' MsgBox _
	' 	"Binary STL file successfully created." + vBNewline, + _
	' +	vbInformation + vbOKOnly, CATSCRIPT_NAME

End Sub

Download:

The macro can also be downloaded from the following link:


File name:Size / byte:
export-binary-stl.zip3602775