How to create an operation from a sketch?

How to create an operation from a sketch?

janHUUUQ
Participant Participant
729 Views
5 Replies
Message 1 of 6

How to create an operation from a sketch?

janHUUUQ
Participant
Participant

Is it possible to create an operation using a sketch for geometry selection?

I tried to adapt Manufacturing Workflow API Sample more specifically I took this piece from the linked code:

# limitEdge.classType() == 'adsk::fusion::BRepEdge'
cadcontours2dParam: adsk.cam.CadContours2dParameterValue = input.parameters.itemByName('machiningBoundarySel').value
chains = cadcontours2dParam.getCurveSelections()
chain = chains.createNewChainSelection()
chain.inputGeometry = [limitEdge]
cadcontours2dParam.applyCurveSelections(chains)

And tried to replace the line that sets the geometry with something like:

# sketch_lines.classType() == 'adsk::fusion::SketchLineList'
chain.inputGeometry = sketch_lines

 

Which gave me:

TypeError: in method 'CurveSelection__set_inputGeometry', argument 2 of type 'std::vector< adsk::core::Ptr< adsk::core::Base >,std::allocator< adsk::core::Ptr< adsk::core::Base > > > const &'

I also tried to pass a list `[sketch_lines]` instead, which gave a similar error.

* Is it possible to select an operation geometry based on a sketch?

* What types can inputGeometry handle? The only hint in the docs I found was, which is too broad to help me:

This is a read/write property whose value is an array of type Base.

 

0 Likes
Accepted solutions (2)
730 Views
5 Replies
Replies (5)
Message 2 of 6

kandennti
Mentor
Mentor
Accepted solution

Hi @janHUUUQ -San.

 

I set the inputGeometry property as a list and the error no longer occurs.

Please modify some of the linked samples and run them.

・・・
        if limitEdge:
            # apply the limits edge to the operation
            cadcontours2dParam: adsk.cam.CadContours2dParameterValue = input.parameters.itemByName('machiningBoundarySel').value
            chains = cadcontours2dParam.getCurveSelections()
            chain = chains.createNewChainSelection()
            # chain.inputGeometry = [limitEdge]
            # cadcontours2dParam.applyCurveSelections(chains)

            circle: adsk.fusion.SketchCircle = create_circle(cam)
            chain.inputGeometry = [circle]
            cadcontours2dParam.applyCurveSelections(chains)
・・・
def create_circle(cam: adsk.cam.CAM) -> adsk.fusion.SketchCircle:
    rootOcc: adsk.fusion.Occurrence = cam.designRootOccurrence
    root: adsk.fusion.Component = rootOcc.component

    skt: adsk.fusion.Sketch = root.sketches.add(
        root.xYConstructionPlane
    )

    sktCircles: adsk.fusion.SketchCircles = skt.sketchCurves.sketchCircles
    return sktCircles.addByCenterRadius(
        adsk.core.Point3D.create(0,0,0),
        1,
    )

 

Message 3 of 6

janHUUUQ
Participant
Participant

Thanks a lot! Your snippet works for me, I did pass wrong types. Here are some types I tried and what worked for me:

  • FAIL: adsk.Fusion.SketchLineList
  • FAIL: list[adsk.Fusion.SketchLineList]
  • FAIL: adsk.fusion.Sketch
  • SUCCESS: list[adsk.fusion.Sketch]
  • FAIL: adsk.fusion.SketchCircle
  • SUCCESS: list[adsk.fusion.SketchCircle]
Message 4 of 6

janHUUUQ
Participant
Participant

I still have issues.I adapted your function as follows:

 

 

def create_rect(cam: adsk.cam.CAM) -> adsk.fusion.Sketch:
    rootOcc: adsk.fusion.Occurrence = cam.designRootOccurrence
    root: adsk.fusion.Component = rootOcc.component

    skt: adsk.fusion.Sketch = root.sketches.add(
        root.xYConstructionPlane
    )

    lines = skt.sketchCurves.sketchLines
    rect_lines = lines.addTwoPointRectangle(
        adsk.core.Point3D.create(-1, -1, 5),
        adsk.core.Point3D.create(1, 1, 5),
    )
    return skt

 

 

 

While I can pass my rectangle as a `list[adsk.fusion.Sketch]` without getting an exception, I somehow get a toolpath that does not seem to care about my rectangle:

janHUUUQ_0-1689238181093.png

 

If I manually reselect the sketch boundary in the gui the restriction works as expected:

janHUUUQ_1-1689238236878.png

This is what the API call gave me:

janHUUUQ_0-1689238505079.png

 

And this is what works:

janHUUUQ_1-1689238526009.png

 

0 Likes
Message 5 of 6

kandennti
Mentor
Mentor
Accepted solution

@janHUUUQ -San.

 

The return value of the function was changed to "rect_lines" instead of the sketch itself.

The type of "rect_lines" was "adsk::fusion::SketchLineList", but it was necessary to convert it to a list.

・・・
        if limitEdge:
            # apply the limits edge to the operation
            cadcontours2dParam: adsk.cam.CadContours2dParameterValue = input.parameters.itemByName('machiningBoundarySel').value
            chains = cadcontours2dParam.getCurveSelections()
            chain = chains.createNewChainSelection()
            # chain.inputGeometry = [limitEdge]*************
            # cadcontours2dParam.applyCurveSelections(chains)

            rectLines = create_rect(cam)
            print(rectLines.objectType) # -> adsk::fusion::SketchLineList - NG
            chain.inputGeometry = list(rectLines)
            cadcontours2dParam.applyCurveSelections(chains)
・・・
def create_rect(cam: adsk.cam.CAM) -> adsk.fusion.Sketch:
    rootOcc: adsk.fusion.Occurrence = cam.designRootOccurrence
    root: adsk.fusion.Component = rootOcc.component

    skt: adsk.fusion.Sketch = root.sketches.add(
        root.xYConstructionPlane
    )

    lines = skt.sketchCurves.sketchLines
    rect_lines = lines.addTwoPointRectangle(
        adsk.core.Point3D.create(-1, -1, 5),
        adsk.core.Point3D.create(1, 1, 5),
    )

    # return skt
    return rect_lines
Message 6 of 6

janHUUUQ
Participant
Participant

Awesome this works!