Importing STL file as a mesh script error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a script that automatically imports an STL file as a mesh into fusion using the meshBodies.add() function. When I run this script I am getting a weird error that I have never seen before:
"RuntimeError: 2 : InternalValidationError : insertProcessor.execute(pInsertRequest.get())"
What is especially weird is that this script works perfectly fine if I use the selectFiles() function at the end of the script to prompt the user to select an STL file. This error only arises when I input the path to the file location of the STL file. This is the ideal way to use this as I don't want to have to select the file everytime.
If anyone can help me figure out what this error means and why it is only showing up when I put the file location in my script it would be much appreciated.
- Ben
Here is the code:
import adsk.core, adsk.fusion, adsk.cam, traceback
_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)
def run(context):
try:
global _app, _ui
_app = adsk.core.Application.get()
_ui = _app.userInterface
# import stl file
path = r'Downloads\powder.stl'
#Line below can be used to prompt user to select file instead of using file path
#paths = selectFiles('select STL file')
# new doc
_app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
des :adsk.fusion.Design = _app.activeProduct
des.designType = adsk.fusion.DesignTypes.ParametricDesignType
root :adsk.fusion.Component = des.rootComponent
# baseFeature
baseFeatures = root.features.baseFeatures
baseFeature = baseFeatures.add()
baseFeature.startEdit()
# import obj files
meshs = importMesh(path ,root.meshBodies, baseFeature)
baseFeature.finishEdit()
# finish
_ui.messageBox('Done')
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def importMesh(
path :list,
meshBodies :adsk.fusion.MeshBodies,
baseFeature :adsk.fusion.BaseFeature) -> list:
unitCm = adsk.fusion.MeshUnits.CentimeterMeshUnit
mesh = meshBodies.add(path, unitCm, baseFeature)
return mesh
def selectFiles(
msg :str):
fileDlg = _ui.createFileDialog()
fileDlg.isMultiSelectEnabled = True
fileDlg.title = msg
fileDlg.filter = '*.stl'
dlgResult = fileDlg.showOpen()
if dlgResult == adsk.core.DialogResults.DialogOK:
return fileDlg.filenames