Interference between the components

Interference between the components

eswaranmec92
Explorer Explorer
652 Views
4 Replies
Message 1 of 5

Interference between the components

eswaranmec92
Explorer
Explorer
I prepared script for analyzing the interference between the components in the assembly product. While i running the script , only the component 5 is highlighted. Please help me to find out the solution for the below issue.
 
#Author-
#Description-
import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context😞
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        design.designType = adsk.fusion.DesignTypes.DirectDesignType
        root = design.rootComponent
        occurrences = root.occurrences

        body1 = occurrences.item(0).bRepBodies.item(0)
        body2 = occurrences.item(1).bRepBodies
        body3 = occurrences.item(2).bRepBodies
        body4 = occurrences.item(3).bRepBodies
        body5 = occurrences.item(4).bRepBodies

        inputcomp = adsk.core.ObjectCollection.create()
        inputcomp.add(body1)
        inputcomp.add(body2)
        inputcomp.add(body3)
        inputcomp.add(body4)
        inputcomp.add(body5)
        input = design.createInterferenceInput(inputcomp)
        input.areCoincidentFacesIncluded = True
        results = design.analyzeInterference(input)
        interferenceBodies = results.createBodies(True)
        resultsOccurrence = occurrences.item(occurrences.count-1)
        resultsOccurrence.activate()
       
            # Fit the view        
        viewport = app.activeViewport
        viewport.fit()
        bod = 0        
        for res in results:
            comp1Name = res.entityOne.parentComponent.name
            comp2Name = res.entityTwo.parentComponent.name
            bodyVolume = str(round(res.interferenceBody.volume, 2))
            interferenceBodies.item(bod).name = 'Interference between ' + comp1Name + ' & ' + comp2Name
            ui.messageBox('There is interference between ' + comp1Name + ' and ' + comp2Name + ' with a volume of ' + bodyVolume + ' cubic centimeters')
            bod += 1

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Accepted solutions (1)
653 Views
4 Replies
Replies (4)
Message 2 of 5

kandennti
Mentor
Mentor
Accepted solution

Hi @eswaranmec92 .

 

Because bRepBodies is assigned to ObjectCollection, interference is not checked.

Fixed as follows.

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        design.designType = adsk.fusion.DesignTypes.DirectDesignType
        root = design.rootComponent
        occurrences = root.occurrences

        body1 = occurrences.item(0).bRepBodies.item(0)
        body2 = occurrences.item(1).bRepBodies
        body3 = occurrences.item(2).bRepBodies
        body4 = occurrences.item(3).bRepBodies
        body5 = occurrences.item(4).bRepBodies

        inputcomp = adsk.core.ObjectCollection.create()
        inputcomp.add(body1)
        # inputcomp.add(body2)
        [inputcomp.add(b) for b in body2]
        # inputcomp.add(body3)
        [inputcomp.add(b) for b in body3]
        # inputcomp.add(body4)
        [inputcomp.add(b) for b in body4]
        # inputcomp.add(body5)
        [inputcomp.add(b) for b in body5]
        input = design.createInterferenceInput(inputcomp)
        input.areCoincidentFacesIncluded = True
        results = design.analyzeInterference(input)
        interferenceBodies = results.createBodies(True)
        # resultsOccurrence = occurrences.item(occurrences.count-1)
        # resultsOccurrence.activate()
       
        # Fit the view        
        viewport = app.activeViewport
        viewport.fit()
        bod = 0        
        for res in results:
            comp1Name = res.entityOne.parentComponent.name
            comp2Name = res.entityTwo.parentComponent.name
            bodyVolume = str(round(res.interferenceBody.volume, 2))
            interferenceBodies.item(bod).name = 'Interference between ' + comp1Name + ' & ' + comp2Name
            ui.messageBox('There is interference between ' + comp1Name + ' and ' + comp2Name + ' with a volume of ' + bodyVolume + ' cubic centimeters')
            bod += 1

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

eswaranmec92
Explorer
Explorer

Respected sir, Thank you for your valuable response. 

Any possibility to analyze clash between the components by using  fusion 360 API script. For example I want to analyze the clash of Component 1 with all other components and similarly component 2 with all other components and vice versa...  If possible , please help me to find out the solution for the above stated problem.

 

 

0 Likes
Message 4 of 5

eswaranmec92
Explorer
Explorer

For the above script, the following results obtained.

 

First displayed:

There is interference between CONNECTOR and Part1 with a volume of 0.0 cubic centimeters

Next Display: sows the following issue.

Failed:

Traceback (most recent call last):

File "C:/Users/MECH LAB/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/com/com.py", line 45, in run

interferenceBodies.item(bod).name = 'Interference between ' + comp1Name + ' & ' + comp2Name

AttributeError: 'NoneType' object has no attribute 'name'

 

 

Please guide me to get the solution.

 

 

 

 

0 Likes
Message 5 of 5

kandennti
Mentor
Mentor

@eswaranmec92 .

 

How about a way to check for interference in the bodies of all components and check the entityOne and entityTwo in the InterferenceResult object?

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-GUID-F5EE87C8-EACB-4D90-B5FF-607ECB6E285B 

 

This sample creates 100 spheres and extracts only the interfering parts of the first 10 and the remaining 90 bodies.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/find-any-interferance-with-active-objects-...