Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

BREP body point containment Issue

Anonymous

BREP body point containment Issue

Anonymous
Not applicable

Hello, so I've been trying to figure out whether there is a cavity/hole in a layer of a BREP body, however the BREP Body.pointContainment() function doesn't seem to work correctly.
For example, I have a cube, with 2 cavities in it, one at x1, y1, z1 and another at x2, y2, z2, both 50mm apart. When I'm looking at layer 1, which is a layer at height z1, the body.pointContainment() method using point1(x1,y1,z1) and point2(x2,y2,z1) returns 2 for both of them, which means that they are both outside of the body. However, point2 should be returning 0, since there is no cavity at that coordinate. The same thing happens when I look at layer 2 which is at height z2.

0 Likes
Reply
Accepted solutions (1)
657 Views
5 Replies
Replies (5)

BrianEkins
Mentor
Mentor

Can you post the f3d file and the specific coordinates you're using?

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes

Anonymous
Not applicable

Here is the model I'm testing with. I've also placed the code I've been using below.

 

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)

model = design.activeComponent

bodies = model.bRepBodies

body = bodies.item(0)

Point1 = adsk.core.Point3D.create(6, 20, 0.4)#20mm high

Point2 = adsk.core.Point3D.create(18.5, 14.5, 0.4)#80mm high

sketches = model.sketches

newComp = adsk.fusion.Component.cast(design.rootComponent)

sketch = sketches.add(newComp.xZConstructionPlane)

lines = sketch.sketchCurves.sketchLines

lines.addByTwoPoints(Point1, Point2)

ui.messageBox("is there a hole at 6, 20, 0.4? : "+str(body.pointContainment(Point1)))

ui.messageBox("is there a hole at 18.5, 14.5, 0.4? : "+str(body.pointContainment(Point2)))

 

except:

if ui:

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

 

0 Likes

BrianEkins
Mentor
Mentor
Accepted solution

The problem is that your working with two different coordinate systems.  A sketch defines its own coordinate system.  It's a full 3D coordinate system that's positioned within 3D space.  The line you create is defined with respect to that coordinate system.  The body exists within the root component and its coordinate system.  I added two lines to your program and modified your last two lines so that the points are now in model space (the root component coordinate system) and now get the expected results.

 

modelPoint1 = sketch.sketchToModelSpace(Point1)
modelPoint2 = sketch.sketchToModelSpace(Point2)

ui.messageBox("is there a hole at 6, 20, 0.4? : "+str(body.pointContainment(modelPoint1)))
ui.messageBox("is there a hole at 18.5, 14.5, 0.4? : "+str(body.pointContainment(modelPoint2)))    

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like

BrianEkins
Mentor
Mentor

A tip is that if you want to draw something in a sketch to better visualize a position in the model, create a sketch on the XY plane in the root component.  In this case, the sketches coordinate system aligns with the model coordinate system.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like

Anonymous
Not applicable

Thank you very much, it works now.

0 Likes