Batch 3d view to STL

I have a list of 3d view that i have isolated a family instances. I can make many of these per project and want to batch export to .STL. We can find Export nodes for most file types, but none i have found for .STL. Are there any nodes or python scripts i can use to export the .STL file from a list of 3d views?

note: i have tried mesh toolkit export, but i appears to have broken for the latest dynamo update.

my final goal is to export to .NC1 file for use in structural fabrication equipment.

Bit of a niche topic, but it’s doable.

This is the Revit API call you’ll need to make. I’ll try and look into it this morning between calls, but give it a shot yourself as I might not have enough time to get anything finished.

This might work for you:

########################################
############## Properties ##############
########################################
__author__ = 'Jacob Small'
__version__ = '0.1.0'
__description__ = """ exports a list of 3d views to STL files of the given name"""
__RevitBuilds__ = "2024.1.1"
__DynamoBuilds__ = "2.18.1"
__ReleaseNotes__ = """ """
__Dependancies__ = ""
__Copyright__ = "2023, Autodesk Inc"
__License__ = """ MIT """

########################################
### Configure the Python environment ###
########################################
### standard imports ###
import sys #add the sys class to the Python environment so we can work with the sys objects
import clr #add the CLR (common language runtime) class to the Python environment so we can work with .net libraries
import RevitServices #import the Revit services class to the Python environment
from RevitServices.Persistence import DocumentManager #import the document manager class to the Python environment 
### Revit API imports ###
clr.AddReference("RevitAPI") #add the Revit API to the CLR
import Autodesk #add the Autodesk class to the Python environment 
from Autodesk.Revit.DB import Document, STLExportOptions #import every class of the Revit API to the Python environment

#########################################
###### Global variables and inputs ######
#########################################
### documents and standard variables ###
doc = DocumentManager.Instance.CurrentDBDocument #the current Revit document
### imports and unwrapping ###
views = UnwrapElement(IN[0]) #import the elements from IN[0] of the Dynamo environment and convert to native Revit elements
if not views.__class__ == [].__class__ : views = [views] #ensure that views is a list, not an individual object, so that we can always prepare for a loop
directory = IN[1] #directory to save the files into
names = IN[2] #the list of file names to save
if not names.__class__ == [].__class__ : names = [names] #ensure that names is a list, not an individual object, so that we can always prepare for a loop

#########################################
########### Export STL files ############
#########################################
results = ["STL Files Created:"]
for view, name in zip(views,names): #for each view and name in the list of views and names
    stlOpts = STLExportOptions() #build a new STL export options object
    stlOpts.ViewId = view.Id #sets the view ID of the STL export options so the view exports correctly
    #### Adjsut additional properties as desired here ####
    stlOpts.ExportColor = True #example showing how to set an STL export options property
    #### Adjsut additional properties as desired here ####
    doc.Export(directory, name, stlOpts) #export the STL file
    results.append("    {0}\{1}.stl".format(directory, name)) #append the file to the results list

OUT = results #return the results list to the Dynamo environment
4 Likes

Perfect this worked great, i will incorporate it not the graph and post a video soon. I find the STL format is easy to preview parts in windows explorer OTB.

I noticed the Exporter had options for resolution and color/units. Is there a way to access these options?
those the script above adopt the previously Preset options?
thanx again.

Check the available properties here: STLExportOptions Properties

You’ll need to add a line for each property you want to configure manually. I noted ‘where’ in the code this has to happen, but you’ll need to add the lines yourself.

3 Likes

here is the script in use, i was aiming at using that OTB windows viewer for stl and it worked great.

2 Likes