Surface Patch with curves

Surface Patch with curves

christophe_gothier_guest
Explorer Explorer
311 Views
4 Replies
Message 1 of 5

Surface Patch with curves

christophe_gothier_guest
Explorer
Explorer

Hello everybody,

First, this is my first code and I'm absolutely not familiar with this. I'm trying to do a Patch feature with multiple curves & lines but I don't understand why the feature doesn't work. When I do it manually in the software it works so it's not about unconnected edges.

I'm using a ObjectCollection and putting everythink inside, may someone know what I'm doing wrong ?

 

Thank you !

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

app = adsk.core.Application.get()
ui  = app.userInterface


def run(_context: str):

    try:
        
        #OUTILS#
        design = adsk.fusion.Design.cast(app.activeProduct)
        rootComp = design.rootComponent
        sketches = rootComp.sketches
        planes = rootComp.constructionPlanes
        origin = adsk.core.Point3D.create(0,0,0)
        patches = rootComp.features.patchFeatures

        #1# Création des UP + importation

        diam = str("Diametre")
        mmUnit = str("mm")
        diamExpression = ui.inputBox("Saisir le diamètre (en " + mmUnit + "):",diam,"200")
        diamExpressionReal = adsk.core.ValueInput.createByReal(float(diamExpression[0])/10)
        design.userParameters.add(diam,diamExpressionReal,mmUnit,"Diamètre exterieur")
        diametre = design.userParameters.itemByName("Diametre")
        radius =  float(diamExpression[0])/10/2

        #2# Création des cercles de jonction

        planeInput = planes.createInput()
        XY = rootComp.xYConstructionPlane
        YZ = rootComp.yZConstructionPlane
        XZ = rootComp.xZConstructionPlane
        plane =[XY,YZ,XZ]

        #Plans
        offset_rail_plane =[]
        offset_values = [-diametre.value,diametre.value,diametre.value]
        for i in range (3):
            planeInput.setByOffset(plane[i],adsk.core.ValueInput.createByReal(offset_values[i]))
            offset_rail_plane.append(planes.add(planeInput));

        #Cercles
        cercles = [offset_rail_plane[0],offset_rail_plane[1],offset_rail_plane[2]]
        patchAvant = adsk.core.ObjectCollection.create()
        for i in range(3) :
            sketch = sketches.add(cercles[i])
            sketch.sketchCurves.sketchArcs.addByCenterStartEnd(origin,adsk.core.Point3D.create(radius,0,0),adsk.core.Point3D.create(0,radius,0))
            patchAvant.add(sketch.sketchCurves.item(0))

        #3# Création des rails

        for i in range(3):
            #rails petits
            sketch = sketches.add(plane[i])
            cos45_small = -(math.sqrt(2)/2)*(diametre.value/4)
            small_rail_O = adsk.core.Point3D.create(diametre.value*0.75,diametre.value,0)
            small_rail_A = adsk.core.Point3D.create(diametre.value*0.5,diametre.value,0)
            small_rail_B = adsk.core.Point3D.create(diametre.value*0.75+cos45_small,diametre.value+cos45_small,0)
            small_rail_OO = adsk.core.Point3D.create(diametre.value,diametre.value*.75,0)
            small_rail_C = adsk.core.Point3D.create(diametre.value+cos45_small,diametre.value*0.75+cos45_small,0)
            small_rail_D = adsk.core.Point3D.create(diametre.value,diametre.value*.5,0)

            sketch.sketchCurves.sketchArcs.addByCenterStartEnd(small_rail_O,small_rail_A,small_rail_B)
            sketch.sketchCurves.sketchLines.addByTwoPoints(small_rail_B,small_rail_C)
            sketch.sketchCurves.sketchArcs.addByCenterStartEnd(small_rail_OO,small_rail_C,small_rail_D)
            patchAvant.add(sketch.sketchCurves.item(0))
            patchAvant.add(sketch.sketchCurves.item(1))
            patchAvant.add(sketch.sketchCurves.item(2))
        
        #Patch avant
        patchInput = patches.createInput(patchAvant,adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        patches.add(patchInput);

        
        ui.messageBox(f'"{app.activeDocument.name}" is the active Document.')
    except:  #pylint:disable=bare-except
        # Write the error message to the TEXT COMMANDS window.
        app.log(f'Failed:\n{traceback.format_exc()}')
 
0 Likes
Accepted solutions (1)
312 Views
4 Replies
Replies (4)
Message 2 of 5

BrianEkins
Mentor
Mentor

I played with it a bit and saw the geometry and failure when creating the patch feature. However, I'm not able to create the patch feature interactively either. Can you post an f3d where the patch was created successfully so I can understand what you're doing differently?

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

christophe_gothier_guest
Explorer
Explorer

I've tryed some experiment and it works manually only if the selected curves are folowing each other. "Group edges" flase or true doesn't affect the result.

Maybe the code will work the same way, I will try to do the code like this today.

 

The f3d file is joined

christophe_gothier_guest_0-1747122978746.png

 

0 Likes
Message 4 of 5

christophe_gothier_guest
Explorer
Explorer
Accepted solution

Good news, I've manage to solve the problem !

As I taught, the feature Patch must have the curves following each others & they must be in the struture (here an objectCollection).

 

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

app = adsk.core.Application.get()
ui  = app.userInterface


def run(_context: str):

    try:
        
        #OUTILS#
        design = adsk.fusion.Design.cast(app.activeProduct)
        rootComp = design.rootComponent
        sketches = rootComp.sketches
        planes = rootComp.constructionPlanes
        origin = adsk.core.Point3D.create(0,0,0)
        patches = rootComp.features.patchFeatures

        #1# Création des UP + importation

        diam = str("Diametre")
        mmUnit = str("mm")
        diamExpression = ui.inputBox("Saisir le diamètre (en " + mmUnit + "):",diam,"200")
        diamExpressionReal = adsk.core.ValueInput.createByReal(float(diamExpression[0])/10)
        design.userParameters.add(diam,diamExpressionReal,mmUnit,"Diamètre exterieur")
        diametre = design.userParameters.itemByName("Diametre")
        radius =  float(diamExpression[0])/10/2

        #2# Création des cercles de jonction

        planeInput = planes.createInput()
        XY = rootComp.xYConstructionPlane
        YZ = rootComp.yZConstructionPlane
        XZ = rootComp.xZConstructionPlane
        plane =[XY,YZ,XZ]

        #Plans
        offset_rail_plane =[]
        offset_values = [-diametre.value,diametre.value,diametre.value]
        for i in range (3):
            planeInput.setByOffset(plane[i],adsk.core.ValueInput.createByReal(offset_values[i]))
            offset_rail_plane.append(planes.add(planeInput));

        #Cercles

        cercles = [offset_rail_plane[0],offset_rail_plane[1],offset_rail_plane[2]]

        arcs = [                                    # 3 collections d'objets
            adsk.core.ObjectCollection.create(),    # ici les 4 arcs sur XY
            adsk.core.ObjectCollection.create(),    # idem sur YZ
            adsk.core.ObjectCollection.create()     # idem sur XZ
        ]

        for i in range(3) :
            sketch = sketches.add(cercles[i])
            sketch.sketchCurves.sketchArcs.addByCenterStartEnd(origin,adsk.core.Point3D.create(radius,0,0),adsk.core.Point3D.create(0,radius,0))
            arcs[i].add(sketch.sketchCurves.item(0))

        #3# Création des rails

        ListpatchAvant = []
        for i in range(3):
            sketch = sketches.add(plane[i])
            cos45_small = -(math.sqrt(2)/2)*(diametre.value/4)
            small_rail_O = adsk.core.Point3D.create(diametre.value*0.75,diametre.value,0)
            small_rail_A = adsk.core.Point3D.create(diametre.value*0.5,diametre.value,0)
            small_rail_B = adsk.core.Point3D.create(diametre.value*0.75+cos45_small,diametre.value+cos45_small,0)
            small_rail_OO = adsk.core.Point3D.create(diametre.value,diametre.value*.75,0)
            small_rail_C = adsk.core.Point3D.create(diametre.value+cos45_small,diametre.value*0.75+cos45_small,0)
            small_rail_D = adsk.core.Point3D.create(diametre.value,diametre.value*.5,0)

            sketch.sketchCurves.sketchArcs.addByCenterStartEnd(small_rail_O,small_rail_A,small_rail_B)
            sketch.sketchCurves.sketchLines.addByTwoPoints(small_rail_B,small_rail_C)
            sketch.sketchCurves.sketchArcs.addByCenterStartEnd(small_rail_OO,small_rail_C,small_rail_D)
            ListpatchAvant.append(sketch.sketchCurves.item(0))  #Item à substituer plus tard
            ListpatchAvant.append(sketch.sketchCurves.item(0))
            ListpatchAvant.append(sketch.sketchCurves.item(1))
            ListpatchAvant.append(sketch.sketchCurves.item(2));
        
        #4# Patchs

        #réorganisation de patchAvant
        rota = ListpatchAvant[1]
        ListpatchAvant[0] = arcs[1].item(0)
        ListpatchAvant[1] = ListpatchAvant[3]
        ListpatchAvant[3] = rota
        ListpatchAvant[4] = arcs[2].item(0)
        ListpatchAvant[8] = arcs[0].item(0)

        patchCurves = adsk.core.ObjectCollection.create()
        for c in ListpatchAvant:
            patchCurves.add(c)

        patchInput = patches.createInput(patchCurves, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        patchInput.isGroupEdges=True
        patches.add(patchInput)

        ui.messageBox(f'"{app.activeDocument.name}" is the active Document.')
    except:  #pylint:disable=bare-except
        # Write the error message to the TEXT COMMANDS window.
        app.log(f'Failed:\n{traceback.format_exc()}')

 

 

Have fun ! 

Message 5 of 5

BrianEkins
Mentor
Mentor

I'm glad you were able to figure it out. I'm still unable to create a patch interactively. I'm selecting them in the same order as you add them to the ObjectCollection but the OK button never becomes enabled. There must be something about that command I don't understand.

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