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: 

Sketch.projectToSurface Method error

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
BradAndersonJr
412 Views, 5 Replies

Sketch.projectToSurface Method error

Hey!

 

When I try to run my script using projectToSurface I get the error:

NotImplementedError: Wrong number or type of arguments for overloaded function 'Sketch_projectToSurface'.

 

The line of code is: 

 

fretProject = sketch8.projectToSurface(topFace, fretLines, adsk.fusion.SurfaceProjectTypes.AlongVectorSurfaceProjectType, dirLine)

 

According to the Object inspector in Spyder 2 it states: 

Sketch.projectToSurface(faces, curves, projectType, directionEntity):

 

Hopefully I'm just missing something simple... again.

 

Thanks!

 

 

 

Brad Anderson Jr
Fusion 360 Hobbyist
Fusion 360 Luthiers Facebook Group
5 REPLIES 5
Message 2 of 6
marshaltu
in reply to: BradAndersonJr

Hello,

 

I did a testing and it worked well in my side. I created a box and several sketch curves and then project the curves to faces of the box. 

 

Thanks,

Marshal

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        design = adsk.fusion.Design.cast(app.activeProduct)
        root = design.rootComponent
        
        body = root.bRepBodies.item(0)
        faces = []
        for face in body.faces:
            faces.append(face)
        
        sketch = root.sketches.item(0)
        curves = []
        for curve in sketch.sketchCurves:
            curves.append(curve)
            
        newsketch = root.sketches.add(root.xZConstructionPlane)
        newsketch.projectToSurface(faces, curves, adsk.fusion.SurfaceProjectTypes.AlongVectorSurfaceProjectType, root.yConstructionAxis)

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


Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Message 3 of 6
BradAndersonJr
in reply to: marshaltu

Hey Marshal!

 

Thanks for the reply!  I played with the code you supplied it and worked great.  Is there a way to project to only 1 face, and not the whole body?  

 

Thanks!

Brad Anderson Jr
Fusion 360 Hobbyist
Fusion 360 Luthiers Facebook Group
Message 4 of 6
marshaltu
in reply to: BradAndersonJr

Hello,

 

You can probably declare a list of faces and append only on face and then call sketch.projectToSurface API.

 

Thanks,

Marshal

 

faces = []
faces.append(yourface)


Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Message 5 of 6
BradAndersonJr
in reply to: marshaltu

Thanks again Marshal!

 

From my attempts I've found that .projectToSurface requires:

 

faces : An array of BRepFace objects that the curves will be projected onto.

 

Whenever I tried using a single face from my list, the script would fail.  As soon as I used multiple faces it would properly execute the script.  I don't know if this is intended to not allow a single face to be called.  I found a work around by specifying the single face I wanted to project curves onto using a slice within the list and setting an iteration to skip the rest of the faces.  My results look like:

 

body = rootComp.bRepBodies.item(0)

bodyFaces = []

for face in body.faces:

    bodyFaces.append(face)

bodySurf = bodyFaces[6::2]

 

 

Thanks again!

Brad Anderson Jr
Fusion 360 Hobbyist
Fusion 360 Luthiers Facebook Group
Message 6 of 6
marshaltu
in reply to: BradAndersonJr

Hello,

 

I guess the root cause was because the face you picked is parallel to project direction so that no curves can be projected. I give a quick test. I will see an error message if I pick a invalid face. It successes if I pick a valid face.

 

Thanks,

Marshal

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        design = adsk.fusion.Design.cast(app.activeProduct)
        root = design.rootComponent
        
        face = ui.activeSelections.item(0).entity
        faces = []
        faces.append(face)
        
        sketch = root.sketches.item(0)
        curves = []
        for curve in sketch.sketchCurves:
            curves.append(curve)
            
        newsketch = root.sketches.add(root.xZConstructionPlane)
        newsketch.projectToSurface(faces, curves, adsk.fusion.SurfaceProjectTypes.AlongVectorSurfaceProjectType, root.yConstructionAxis)

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


Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

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