Minimal working example of creating a Sweep with a Guide Surface through the Python API

Minimal working example of creating a Sweep with a Guide Surface through the Python API

davemurrayrust
Enthusiast Enthusiast
344 Views
4 Replies
Message 1 of 5

Minimal working example of creating a Sweep with a Guide Surface through the Python API

davemurrayrust
Enthusiast
Enthusiast

I'm trying to create a Sweep programatically. I can't make sense of the docs - partly due to the split between python and C++ and the difficulty of debugging, but also partly as it's a bit confusing. The code is in flux at the moment, but it's roughly along the lines of:

# This works fine, it's making a Surface Loft, shows up orange in the timeline
loft_body = loft_feats.add(loft_input) 
... 
sweep_input = sweeps.createInput(profile, path, op)
sweep_input.guideSurfaces = loft_body.bodies.item(0)
sweep_input.distanceOne = 1.0

 

If I run it, it's a C++ type error on line 5 (which I can't copy paste from the dialog 😕 )

 

What *should* I be passing in? And more generally, how should I figure it out?

 

As a side note - how do I get access to the errors and output logs of Scripts? The online docs (https://help.autodesk.com/view/PLM/ENU/?guid=DEV-ERROR-TRACKING) say there should be a yellow warning icon next to the script, but that doesn't match the current UI

0 Likes
Accepted solutions (1)
345 Views
4 Replies
Replies (4)
Message 2 of 5

jeff_strater
Community Manager
Community Manager

I think the problem is that you are passing in a Body.  Instead, what appears to be needed is an array of BRepFace.  This is consistent with the UI - guide surface is a face selection.

 

SweepFeatureInput.guideSurfaces Property 

 

Screenshot 2026-02-06 at 10.52.27 AM.png


Jeff Strater
Engineering Director
Message 3 of 5

davemurrayrust
Enthusiast
Enthusiast

Thanks - and sorry to be dim, but how do I get that from the Body? It's a Surface Loft, so it should be the right form in there somewhere - I can use the output to make a surface sweep through the UI - but I can't figure out the translation steps. I tried looking across the object hierarchy in the API docs, but it wasn't immediately apparent.

0 Likes
Message 4 of 5

jeff_strater
Community Manager
Community Manager
Accepted solution

I'm a little out of my depth here, but, from a BRepBody, you can call the faces() property:  BRepBody.faces Property .  This returns a BRepFaces object, which is a collection of BRepFace.  I think this is different than what Sweep requires (an array of BRepFace).  Here is a code snippet from google that claims to show how to convert this:

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

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

# Assume a body is selected
selectedBody = ui.activeSelections.item(0).entity

# Get the BRepFaces collection
facesCollection = selectedBody.faces

# Convert BRepFaces collection to an array (list) of BRepFace
facesArray = []
for face in facesCollection:
facesArray.append(face)

# Example: Access the first face in the array
if len(facesArray) > 0:
firstFace = facesArray[0]
app.log(f'Found {len(facesArray)} faces. First face ID: {firstFace.tempId}')

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


Jeff Strater
Engineering Director
Message 5 of 5

rosie_lucas1
Autodesk
Autodesk

Hello @davemurrayrust ,

Did the information provided by @jeff_strater help you and answer your question?

If yes, please click on the "Accept Solution" button on the post(s) that solved your problem. This will assist other community users in finding and benefiting from this information.

If not, please do not hesitate to give an update in this thread so all community members receive an update on the progression of your question, and can suggest next steps that may be helpful for you to achieve what you're looking for.

All the best,

Rosie| Community Manager

0 Likes