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: 

Analyze inteference between plane and body

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
io16231
512 Views, 5 Replies

Analyze inteference between plane and body

I'm currently trying to return the result of whether or not a created plane interfers with a body or not. 

 

The plane is based off the bounding box of the bottom two faces of the object as plotted. Eventually I want the script will iterate through these to try and find planes that will not intersect with the body. Corners is a list of lists containing all the x,y,z coordinates of all the corners of the bounding boxs (for two faces)

 

The itertools goes through Corners to randomly select three points which will be used to create the plane. This plane and the body are then added to an object collection and the interference is analysed, however I repeatedly obtain 'False' as the output of the interference analysis.

 

Do you know the source of this error? Or if a plane is even a valid interference object?

 

Here's the code I'm using:

 

Planedefined=list(itertools.combinations(Corners, 3))

print(Planedefined[0][0][0])

print(Planedefined[0][0][1])

print(Planedefined[0][0][2])

print(Planedefined[0][0])

positionOne = adsk.core.Point3D.create(Planedefined[279][0][0],Planedefined[279][0][1],Planedefined[279][0][2])

sketchPointOne = sketchPoints.add(positionOne)

positionTwo = adsk.core.Point3D.create(Planedefined[279][1][0],Planedefined[279][1][1],Planedefined[279][1][2])

sketchPointTwo = sketchPoints.add(positionTwo)

positionThree = adsk.core.Point3D.create(Planedefined[279][2][0],Planedefined[279][2][1],Planedefined[279][2][2])

sketchPointThree = sketchPoints.add(positionThree)

 

#Create the splitting plane

planes = rootComp.constructionPlanes

planeInput = planes.createInput()

planeInput.setByThreePoints(sketchPointOne, sketchPointTwo, sketchPointThree)

splittingPlane=planes.add(planeInput)

 

interference = adsk.core.ObjectCollection.create()

interference.add(planeInput)

interference.add(body)

input = design.createInterferenceInput(interference)

results = design.analyzeInterference(input)

print(bool(results))

5 REPLIES 5
Message 2 of 6
kandennti
in reply to: io16231

Hi @io16231 .

 

The return value of the analyzeInterference method is like an InterferenceResults object.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-7B17A057-49A7-4332-ACD1-F6FA4EA84C88 

 

Isn't the cause because you are casting to bool?

Message 3 of 6
io16231
in reply to: kandennti

Even if instead of returning a bool I say print(results.count), the count still returns as 0. I feel like this might suggest there just isn't an InterferenceResults object created?

 

I'm not sure how to interpret the examples provided since there's a region of interference which is used to create a body, which throws an error when I try it with mine (probably because there isn't a bounded region of interference).

Message 4 of 6
kandennti
in reply to: io16231

I tried using GUI,
・Solid-Solid: OK
・Solid-Surface: NG
・Solid-Plane: NG
So, I think it is impossible with constructionPlane.

As an alternative, why not use the Plane Object's intersectWithSurface Method?
#Fusion360API Python script


import adsk.core, adsk.fusion, traceback

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

        msg :str = 'Select Body'
        selFiltter :str = 'Bodies'
        sel :adsk.core.Selection = selectEnt(ui, msg ,selFiltter)
        if not sel: return
        body :adsk.fusion.BRepBody = sel.entity

        msg = 'Select ConstructionPlane'
        selFiltter = 'ConstructionPlanes'
        sel = selectEnt(ui, msg ,selFiltter)
        if not sel: return
        plane :adsk.fusion.ConstructionPlane = sel.entity

        if isCollision(body, plane):
            msg = 'Collision!!'
        else:
            msg = 'Safe'

        ui.messageBox(msg)

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

# https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-fb0ab39e-66b3-4772-b057-a1b741aa1919
def isCollision(
    body :adsk.fusion.BRepBody,
    plane :adsk.fusion.ConstructionPlane
    ) -> bool:

    geoPlane :adsk.core.Plane = plane.geometry

    faces :adsk.fusion.BRepFaces = body.faces
    face = adsk.fusion.BRepFace.cast(None)
    for face in faces:
        geo = face.geometry
        res = geoPlane.intersectWithSurface(geo)
        if res.count > 0:
            return True
        
    return False


def selectEnt(
        ui :adsk.core.UserInterface,
        msg :str, 
        filtterStr :str) -> adsk.core.Selection :

    try:
        sel = ui.selectEntity(msg, filtterStr)
        return sel
    except:
        return None
Message 5 of 6
io16231
in reply to: kandennti

Thanks this seems like a good way to do it, but the script you sent seems to return the result as collision regardless of whether they're intersecting or not. Have tried on different models and it happens every time-any ideas why this is happening?

Message 6 of 6
kandennti
in reply to: io16231

I'm sorry, I only tested on a sphere.

Replace the isCollision function with:
The intersectWithCurve method was also used.
# https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-fb0ab39e-66b3-4772-b057-a1b741aa1919
# https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-2064166e-fa1e-4e50-9f92-587aff8b9864
def isCollision(
    body :adsk.fusion.BRepBody,
    plane :adsk.fusion.ConstructionPlane
    ) -> bool:

    geoPlane :adsk.core.Plane = plane.geometry

    faces :adsk.fusion.BRepFaces = body.faces
    face = adsk.fusion.BRepFace.cast(None)
    for face in faces:

        edges :adsk.fusion.BRepEdges = face.edges
        if edges.count > 0:
            for edge in edges:
                res = geoPlane.intersectWithCurve(edge.geometry)

                if res.count > 0:
                    return True
        else:
            geo = face.geometry
            res = geoPlane.intersectWithSurface(geo)

            if res.count > 0:
                return True
            
    return False
 
This year, I put up a puzzle on a Japanese forum.
The answer confirmation add-in was created this way.

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