Duplicate a sketch on the opposite side.

Duplicate a sketch on the opposite side.

Anonymous
Not applicable
615 Views
2 Replies
Message 1 of 3

Duplicate a sketch on the opposite side.

Anonymous
Not applicable

Hi all

 

I have some beginner problems with API. I want to select some face and sketch circle 10mm from some edge (or center of this face. centroid?) Then make extrude and rectangular pattern. Issue I have on left side that sketch goes outside of the face

right sideright sideleft sideleft side

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
        rootComp = adsk.fusion.Component.cast(design.rootComponent)
        sketches = rootComp.sketches
        faceSel = ui.selectEntity('Select a face', 'Faces')
        if faceSel:
            selectedFace = adsk.fusion.BRepFace.cast(faceSel.entity)
            sketch = sketches.add(selectedFace)
            circles = sketch.sketchCurves.sketchCircles
            circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(2,1,0),0.5)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

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

Anonymous
Not applicable

Create, not duplicate, sry

0 Likes
Message 3 of 3

kandennti
Mentor
Mentor
Accepted solution

Hi stupadmitry.

 

The algorithm on the opposite side is not so good,
but we will create an circle on the selected surface.

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        design = app.activeProduct
        rootComp = adsk.fusion.Component.cast(design.rootComponent)
        sketches = rootComp.sketches
        faceSel = ui.selectEntity('Select a face', 'Faces')
        if faceSel:
            
            selectedFace = adsk.fusion.BRepFace.cast(faceSel.entity)
            sketch = sketches.add(selectedFace)
            circles = sketch.sketchCurves.sketchCircles
#            circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(2,1,0),0.5)
            
            #coordinate
            circle_center_pos = [2, 1, 0]
            UVpos_try_list = [circle_center_pos ,
                             [circle_center_pos[0]*-1,circle_center_pos[1],0],
                             [circle_center_pos[0],circle_center_pos[1]*-1,0],
                             [circle_center_pos[0]*-1,circle_center_pos[1]*-1],0]
                             
            #Evaluator
            surfEva = adsk.core.SurfaceEvaluator.cast(selectedFace.evaluator)
            
            for pos in UVpos_try_list:
                #create circle
                circle1 = circles.addByCenterRadius(
                    adsk.core.Point3D.create(pos[0],pos[1],pos[2]),0.5)
                center = circle1.centerSketchPoint.worldGeometry
                
                #parameter
                returnValue, center_prm = surfEva.getParameterAtPoint(center)
                if not returnValue :
                    circle1.deleteMe()
                    continue
                
                #judgment
                if surfEva.isParameterOnFace(center_prm):
                    break
                else:
                    circle1.deleteMe()
            
            ui.messageBox('Done')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

Use the 'BRepFace.evaluator.isParameterOnFace' method to determine
if the center of the circle is on the surface.

0 Likes