Offset from brepLoop?

Offset from brepLoop?

m.rackow
Explorer Explorer
517 Views
2 Replies
Message 1 of 3

Offset from brepLoop?

m.rackow
Explorer
Explorer

How can I get an offset curve from an brepLoop? I've tried it that way:

 

import adsk.core, adsk.fusion, traceback, math

 

#app = adsk.core.Application.cast(None)

#ui = adsk.core.UserInterface.cast(None)

 

def run(context):

try:

app = adsk.core.Application.get()

ui = app.userInterface

 

# Select a face

faceSel = ui.selectEntity('Select a face', 'Faces')

if faceSel:

face = adsk.fusion.BRepFace.cast(faceSel.entity)

 

des = adsk.fusion.Design.cast(app.activeProduct)

root = des.rootComponent

distance = adsk.core.ValueInput.createByString('2 mm')

 

# Create a sketch on the selected face

sketch=root.sketches.add(face)

 

# Get the outer loop of the selected face

brepLoops = face.loops

outerLoop = brepLoops.item(0)

 

# Create the offset.

dirPoint = adsk.core.Point3D.create(0, -0.5, 0)

sketch.offset(outerLoop, dirPoint, distance)

 

except:

if ui:

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

 

I'm sure there are some steps missing...

 

0 Likes
Accepted solutions (1)
518 Views
2 Replies
Replies (2)
Message 2 of 3

prainsberry
Autodesk
Autodesk
Accepted solution

Hey i think you are actually almost there.  This is a case where you need to learn a little about ObjectCollections.  Good one to become familiar with.  They are kind of a special iterable that Fusion uses as inputs to various features.  It is also how things are returned.  I think it has something to do with making API more portable across languages, but not sure.  

 

You just need to get the edges of the loop and project them into the sketch.  Technically in this case the edges of a face are in a sketch already if you are sketching on the face, but jsut for completeness I will re-project them into the sketch.

 

I didn't actually test this, just wrote free hand so might still be some bug in here.  Let me know if this gets you moving in the right direction.

 

 

Try adding something like this after you get the loop:

 

loop_edges = outerLoop.edges 
loop_curves = adsk.core.ObjectCollection.create()

for loop_edge in loop_edges:
loop_curve_collection = sketch.project(loop_edge) # Returns a collection, possible that there is more than one sketch entity created per edge
for loop_curve in loop_curve_collection:
loop_curves.add(loop_curve)

# Create the offset.
dirPoint = adsk.core.Point3D.create(0, -0.5, 0)
sketch.offset(
loop_curves, dirPoint, distance)

 



Patrick Rainsberry
Developer Advocate, Fusion 360
0 Likes
Message 3 of 3

m.rackow
Explorer
Explorer

Hello Patrick,

 

yes, this helps me a lot! 🙂

 

I got now the projected lines and one of the offset lines. I'm going to read more about Collections!

 

Thank you very much!

0 Likes