Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

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: 

Select SketchConstraints using api

5 REPLIES 5
Reply
Message 1 of 6
Cotral.RD2
941 Views, 5 Replies

Select SketchConstraints using api

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
5 REPLIES 5
Message 2 of 6
kandennti
in reply to: Cotral.RD2

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.

Message 3 of 6
Cotral.RD2
in reply to: kandennti

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
Message 4 of 6
kandennti
in reply to: Cotral.RD2

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

Message 5 of 6
kandennti
in reply to: kandennti

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.

Message 6 of 6
CADacombs
in reply to: Cotral.RD2

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report