Modify Select Filters with a Macro

Modify Select Filters with a Macro

swalroth8KYHK
Contributor Contributor
1,183 Views
7 Replies
Message 1 of 8

Modify Select Filters with a Macro

swalroth8KYHK
Contributor
Contributor

When creating drawings I have a lot of parts within section views, so I often use the "Edit Select Filters..." option to only pick either Hatch or Edge as needed.  It can get time consuming to jump back and forth between the two.  I was hoping to create a couple VBA macros that could be embedded into the ribbon and/or shortcut menu.

 

The first would clear all filter options, set only "Hatch", and activate the custom filters.

The second would do the same for "Edge". 

 

Beyond that I would like to be able to create more as needed, but I cannot find anything about changing that setting. I tried using "SelectEvents", SelectionPreferences", and "SelectSet", but only seem to affect part and assembly selection options.

0 Likes
1,184 Views
7 Replies
Replies (7)
Message 2 of 8

WCrihfield
Mentor
Mentor

I'm not entirely sure how to select only the Hatch yet, but I have this code for narrowing the SelectionPreferences to kEdgeObject only.

Dim oDoc As DrawingDocument
Set oDoc = ThisDrawing.Document
Dim oSelPref As SelectionPreferences Set oSelPref = oDoc.SelectionPreferences oSelPref.Clear oSelPref.Add(ObjectTypeEnum.kEdgeObject)

When I select the Hatch manually, then attempt to get the ObjectTypeEnum from it, I get the kSectionDrawingViewObject, for some reason.  

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 8

swalroth8KYHK
Contributor
Contributor

I think I must be doing something wrong.  I tried your code and got a 424 error ("Object required") so I switched line 2 to:

 

Set oDoc = ThisApplication.ActiveDocument

 

It runs without issue now, but nothing changes.  The actual filter list does not change nor does my ability to select drawing elements change.

 

I tried something similar to this earlier and had the same issue.  Is there perhaps something wrong with my Inventor preventing this from firing properly?

0 Likes
Message 4 of 8

filippo.toniello
Enthusiast
Enthusiast

It happens the same for me...

is there any other instruction to add?

0 Likes
Message 5 of 8

WCrihfield
Mentor
Mentor

Unfortunately, this setting doesn't appear to stay in place after the macro has finished.  I'm not sure why.

The API documentation says the SelectionPreferences was added in version 2016.

Somehow this doesn't appear to be the same thing as when you manually click the 'Select' tool (within the Quick Access Toolbar), and choose "Edit Select Filters..." from the drop-down, then manually check and uncheck check boxes next to all the different types of objects you want to (or don't want to) be able to select within the drawing environment.  It seems like the folks at Autodesk need to clarify how this is supposed to work (when done purely by code), or at least clarify if this functionality is even available (working) yet.

 

   On another note though, you CAN set the 'SelectionPriority' by VBA macro (or by an iLogic rule) and that setting will stay in-place after the macro has finished though.

The API documentation says the SelectionPriority was added in version 2008.

Here's the VBA code to set the drawing's SelectionPriority to Edges. 

Sub Set_Edge_Selection_Priority()
    If ThisApplication.ActiveDocumentType <> kDrawingDocumentObject Then
        a = MsgBox("This macro only works when a Drawing document is active. Exiting.", vbOKOnly + vbCritical, " ")
        Exit Sub
    End If
    Dim oDDoc As DrawingDocument
    Set oDDoc = ThisApplication.ActiveDocument
    oDDoc.SelectionPriority = kEdgeSelectionPriority
End Sub

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

If you have time, please... Vote For My IDEAS 💡and Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 8

filippo.toniello
Enthusiast
Enthusiast

Thanks for the suggestion but unfortunaltely it is not what it is necessary.

I would like to set custom filters mode and select it in drawing , like suggested in another thread, to avoid to select continuosly and not intentionally views during drafting process.

Like creo does with one click

 

2020-11-06 12_44_09-Marking Menu.png

0 Likes
Message 7 of 8

BLA_fpineda
Enthusiast
Enthusiast
@filippo.toniello Did you find a solution? I'm interested in the same solution such as Set a custom filter using a button or something like that.
0 Likes
Message 8 of 8

filippo.toniello
Enthusiast
Enthusiast

nope

almost in 2020 release

0 Likes