ExportManager(stlOptions) RuntimeError: 2 : InternalValidationError : success

ExportManager(stlOptions) RuntimeError: 2 : InternalValidationError : success

Le_Bear
Collaborator Collaborator
685 Views
3 Replies
Message 1 of 4

ExportManager(stlOptions) RuntimeError: 2 : InternalValidationError : success

Le_Bear
Collaborator
Collaborator

Ok I must say, I love it ! 😍

I get an error to tell me "success" 🤣

Anyway, this is pretty annoying , as the script stop working, after running properly for a while.
Here is the exact error I am getting (sorry, repetitive errors trying to upload that tiny image)

 

here is the script itself, s it's pretty short:

 

 

#Author-BG
#Description-Copy bodies from a full assembly into a single component, to make it easier to export a STL

# The goal is to copy bodies from a full assembly into a new component, so that it will be possible
# to export as STL from Fusion with a common origin (and axis)

# Beginning on 23/2/2020 :59 by BG

# Now the script DO NOT copy bodies, just export them as STL, only if the component is visible


import adsk.core, adsk.fusion, traceback

# Create a collection to store our bodies 
sourceBodies = adsk.core.ObjectCollection.create()

folder = "C:/Users/bgros/Documents/Rosetta/Machine Nicolas/ApiExport"
   
def traverse(occurences):
    # recursive method to get all bodies from components and sub-components
    for occ in occurences: 
        visiFlag = occ.isLightBulbOn                         
        bodies = occ.bRepBodies          
        for bod in bodies:
            if visiFlag:
                bod.name = occ.fullPathName                
                sourceBodies.add(bod) 
                adsk.doEvents()  
                visiFlag = False

        if occ.childOccurrences:
            traverse(occ.childOccurrences)
    
def run(context):
    ui = None   
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        

        # Get active design
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        if not design:
            ui.messageBox('It is not supported in current workspace, please change to MODEL workspace and try again.')
            return

        # History must be captured for this to work
        if design.designType == adsk.fusion.DesignTypes.DirectDesignType:
            design.designType = adsk.fusion.DesignTypes.ParametricDesignType

 
        # Get root component in this design
        rootComp = design.rootComponent
               
        # Get all Components below root       
        occs = rootComp.occurrences

        # add all bodies from all components in the collection 
        traverse(occs)

        # # create the new component , adding "for STL Export" to the name       
        # newComp = occs.addNewComponent(adsk.core.Matrix3D.create())                
        # newComp.component.name = rootComp.name + " for STL Export"
        adsk.doEvents() 
        # copy paste ALL bodies to the new component
        #newComp.component.features.copyPasteBodies.add(sourceBodies)
        for oneBody in sourceBodies:
            #oneBody.name = rootComp.name + " " + oneBody.name    
            # newComp.component.features.copyPasteBodies.add(oneBody)
            # Construct the output filename.
            oneBody.name = oneBody.name.replace(":", "-")
            filename = folder + "/" + oneBody.name + '.stl'            
            # Save the file as STL.
            exportMgr = adsk.fusion.ExportManager.cast(design.exportManager)
            stlOptions = exportMgr.createSTLExportOptions(oneBody, filename)            
            stlOptions.meshRefinement = adsk.fusion.MeshRefinementSettings.MeshRefinementHigh
            stlOptions.isOneFilePerBody = True
            stlOptions.sendToPrintUtility = False
            exportMgr.execute(stlOptions)
            adsk.doEvents() 

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

 

 



Bernard Grosperrin

Autodesk Certified Instructor

FaceBook Group | Forum | YouTube

Group Network Leader
 
0 Likes
686 Views
3 Replies
Replies (3)
Message 2 of 4

Le_Bear
Collaborator
Collaborator

It looks like it may be linked to the full pathname being too long. I would like if someone in the known could confirm, and also if it would be possible to have an helping exception, rather than the quite cryptic "success".

Bernard Grosperrin

Autodesk Certified Instructor

FaceBook Group | Forum | YouTube

Group Network Leader
 
0 Likes
Message 3 of 4

BrianEkins
Mentor
Mentor

This is a known issue that True is returned even when the translation has failed.  Hopefully, it will be addressed soon.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 4 of 4

Le_Bear
Collaborator
Collaborator

@BrianEkins wrote:

This is a known issue that True is returned even when the translation has failed.  Hopefully, it will be addressed soon.


Translation ? Into an STL, you mean? OK, good to know it is known, not just some mistake from me. Is there any workaround possible ? At least to know what could make it fail.

Thanks for your help.

Bernard Grosperrin

Autodesk Certified Instructor

FaceBook Group | Forum | YouTube

Group Network Leader
 
0 Likes