Select SketchConstraints using api

Cotral.RD2
Advocate
Advocate

Select SketchConstraints using api

Cotral.RD2
Advocate
Advocate

Hi i am trying to select a linear dimension using a command input but without success. I am using the filter 

"SketchConstraints" for the selection filter but i can only choose geometric constraints but not dimensional constraints.

according to the documentation 

SketchConstraints = Selects sketch geometric and dimensions constraints.

but doesent seem to support dimensions constraints.

Pavan HEMMEGE VENKATAPPA
Fusion 360 Ultimate User
1 Like
Reply
955 Views
5 Replies
Replies (5)

kandennti
Mentor
Mentor

hi.p.hemmege

 

'SketchConstraints' certainly seems to be unusable.

I was interested in 'Selection Filters', so I made the following code.

import adsk.core, adsk.fusion, traceback

def InitFilterList():
    return [
        'Bodies',
        'SolidBodies',
        'SurfaceBodies',
        'MeshBodies',
        'Faces',
        'SolidFaces',
        'SurfaceFaces',
        'PlanarFaces',
        'CylindricalFaces',
        'ConicalFaces',
        'SphericalFaces',
        'ToroidalFaces',
        'SplineFaces',
        'Edges',
        'LinearEdges',
        'CircularEdges',
        'EllipticalEdges',
        'TangentEdges',
        'NonTangentEdges',
        'Vertices',
        'RootComponents',
        'Occurrences',
        'Sketches',
        'SketchConstraints',
        'Profiles',
        'Texts',
        'SketchCurves',
        'SketchLines',
        'SketchCircles',
        'SketchPoints',
        'ConstructionPoints',
        'ConstructionLines',
        'ConstructionPlanes',
        'Features',
        'Canvases',
        'Decals',
        'JointOrigins',
        'Joints'
        ]
    
def run(context):
    app = adsk.core.Application.get()
    ui = app.userInterface
    
    filterLst = InitFilterList()
    print('')
    print('** Fusion360 ver:{} **'.format(app.version))
    for filter in filterLst:
        try:
            ui.selectEntity('Select / ESC-Cancel', filter)
            print('{}'.format(filter).ljust(20,' ')+':ok')
        except RuntimeError:
            print('{}'.format(filter).ljust(20,' ')+':RuntimeError')
        except:
            pass

The results are as follows.

** Fusion360 ver:2.0.4126 **
Bodies              :ok
SolidBodies         :ok
SurfaceBodies       :ok
MeshBodies          :ok
Faces               :ok
SolidFaces          :ok
SurfaceFaces        :ok
PlanarFaces         :ok
CylindricalFaces    :ok
ConicalFaces        :ok
SphericalFaces      :RuntimeError
ToroidalFaces       :ok
SplineFaces         :ok
Edges               :ok
LinearEdges         :ok
CircularEdges       :ok
EllipticalEdges     :ok
TangentEdges        :ok
NonTangentEdges     :ok
Vertices            :ok
RootComponents      :ok
Occurrences         :ok
Sketches            :ok
SketchConstraints   :ok
Profiles            :ok
Texts               :ok
SketchCurves        :ok
SketchLines         :ok
SketchCircles       :ok
SketchPoints        :ok
ConstructionPoints  :ok
ConstructionLines   :ok
ConstructionPlanes  :ok
Features            :ok
Canvases            :ok
Decals              :ok
JointOrigins        :ok
Joints              :ok

'SphericalFaces' will not function, it will result in an error.

 

https://forums.autodesk.com/t5/fusion-360-ri-ben-yu/api-selection-filters-no-sphericalfaces-ga-ji-ne...

 

Even if it is described in the Japanese forum, it is hardly to be opponent.

0 Likes

Cotral.RD2
Advocate
Advocate

ok but have you tried the SketchConstraints ? and were you able to selecet the dimensional constraints with this?

Pavan HEMMEGE VENKATAPPA
Fusion 360 Ultimate User
0 Likes

kandennti
Mentor
Mentor

Although it will not be an error, I also 'SketchConstraints' will not succeed.

0 Likes

kandennti
Mentor
Mentor

Sorry for taking out old topics.

 

It has not been improved yet due to the bug of Selection Filters-SketchConstraints here. (Fusion360 Ver2.0.7402)

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-03033DE6-AD8E-46B3-B4E6-DADA8D389E4E 

 

Recently, I came up with a way to get around this.

 

I learned that using the Command.preSelect Event, you can get the element under the mouse cursor.
You can check the type and operate the selection.

I made a sample here.
https://github.com/kantoku-code/Fusion360-SelectFilter_T_Sample 

I can't give detailed explanations in English, so if you are interested, please take a look.

 

CATIA macros have a similar selection function, and filters can use object names.

2 Likes

CADacombs
Enthusiast
Enthusiast

Bump

 

Although Fusion Help | Selection Filters | Autodesk states "SketchConstraints Selects sketch geometric and dimensions constraints.", when this filter is used, sketch dimensions are ignored. No other filter appears to work. With no filter set, as when using Fusion Help | CommandInputs.addSelectionInput Method | Autodesk , sketch dimensions can be selected and their objectType tested afterward, but this is an awkward solution and doesn't work with Fusion Help | UserInterface.selectEntity Method | Autodesk.

 

SketchConstraints_filter_bug.gif

import adsk.core, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        while True:
            try:
                sel = ui.selectEntity("Select a sketch dimension", "SketchConstraints")
                ui.messageBox(f"{sel.entity.objectType = }")
            except:
                return

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

 

Thank you

1 Like