Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

internal validation error when analysing interference multiple times in a script

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
nnamfoh
599 Views, 4 Replies

internal validation error when analysing interference multiple times in a script

I'm experimenting with different uses of the interference calculation in Fusion 360.

One example I'm trying to create is generating the interference of an interfernce body. For example if you create a venn diagram with 3 triangulated circles you get an interior intersection of the 3 circles and 3 outer portions that are the intersection of only two models. I try to create this using this code (below) but I get a InternalValidationError. What is causing this error. I have similar issues in other scripts wheverer I try to calculate and interference multiple times.Capture.PNG

def run(context):
    ui = None
    try:
        global app
        app = adsk.core.Application.get()
        global ui
        ui  = app.userInterface


        # Create a document.
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)

        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        design.designType = adsk.fusion.DesignTypes.DirectDesignType

        # Get the root component of the active design.
        rootComp = design.rootComponent
        features = rootComp.features

        # Create sketch circle on the xz plane.
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xZConstructionPlane)
        sketchCircles = sketch.sketchCurves.sketchCircles
        centerPoint = adsk.core.Point3D.create(0, 0, 0)
        sketchCircles.addByCenterRadius(centerPoint, 10)

        # Create a collection of entities for extrude
        entities0 = adsk.core.ObjectCollection.create()
        entities0.add(sketch.profiles.item(0))

        # Create a cylinder with ExtrudeFeature using the profile above.
        extrudeFeats = features.extrudeFeatures
        extrudeFeatureInput = extrudeFeats.createInput(entities0, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        extrudeFeatureInput.isSolid = True
        extrudeFeatureInput.setDistanceExtent(False, adsk.core.ValueInput.createByReal(2.5))
        extrudeFeature = extrudeFeats.add(extrudeFeatureInput)
        
        # Create second body to do interference
        sketch = sketches.add(rootComp.xZConstructionPlane)
        sketchCircles = sketch.sketchCurves.sketchCircles
        centerPoint = adsk.core.Point3D.create(5, 0, 0)
        sketchCircles.addByCenterRadius(centerPoint, 10)

        entities0.clear()
        entities0.add(sketch.profiles.item(0))

        # Create a cylinder with ExtrudeFeature using the profile above.
        extrudeFeatureInput = extrudeFeats.createInput(entities0, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        extrudeFeatureInput.isSolid = True
        extrudeFeatureInput.setDistanceExtent(False, adsk.core.ValueInput.createByReal(2.5))
        extrudeFeature = extrudeFeats.add(extrudeFeatureInput)
        sketch = sketches.add(rootComp.xZConstructionPlane)
        sketchCircles = sketch.sketchCurves.sketchCircles
        centerPoint = adsk.core.Point3D.create(0, 5, 0)
        sketchCircles.addByCenterRadius(centerPoint, 10)

        entities0.clear()
        entities0.add(sketch.profiles.item(0))

        # Create a cylinder with ExtrudeFeature using the profile above.
        extrudeFeatureInput = extrudeFeats.createInput(entities0, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        extrudeFeatureInput.isSolid = True
        extrudeFeatureInput.setDistanceExtent(False, adsk.core.ValueInput.createByReal(2.5))
        extrudeFeature = extrudeFeats.add(extrudeFeatureInput)
        

        # Create a collection of bodies
        bodies = adsk.core.ObjectCollection.create()
        for body in rootComp.bRepBodies:
            bodies.add(body)

        # Create InterferenceInput
        interferencInput = design.createInterferenceInput(bodies)

        # Analyze interference
        results = design.analyzeInterference(interferencInput)
        results.createBodies(True)
        
        intersection = rootComp.occurrences.item(0)
        newBodies = adsk.core.ObjectCollection.create()
        for body in intersection.component.bRepBodies:
            newBodies.add(body)
        #get next level of interference    
        interferenceInput0 = design.createInterferenceInput(newBodies)
        results1 = design.analyzeInterference(interferenceInput0)
        results.createBodies(True)
4 REPLIES 4
Message 2 of 5
frankzhang
in reply to: nnamfoh

Hello, we are sorry you are having issues with this API, we have identified the problem and will provide a fix as soon as we can.
Message 3 of 5
nnamfoh
in reply to: frankzhang

In the mean time is there a work around that would could calculate the interference of these bodies?

Message 4 of 5
frankzhang
in reply to: nnamfoh

One workaround is to add two lines in your code as shown below in red:

 

# Analyze interference

results = design.analyzeInterference(interferencInput)

results.createBodies(True)

 

del interferencInput

del results

 

intersection = rootComp.occurrences.item(0)

newBodies = adsk.core.ObjectCollection.create()

for body in intersection.component.bRepBodies:

newBodies.add(body)

 

#get next level of interference

interferenceInput0 = design.createInterferenceInput(newBodies)

results1 = design.analyzeInterference(interferenceInput0)

results1.createBodies(True)

Message 5 of 5
nnamfoh
in reply to: frankzhang

Thank you that seems to work. Unfortunatly it does cost the data in results but I suppose I can save that to other data fields if  I need it.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report