Cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

Select all button in block styler dialog

Experimenter
Experimenter

Hi,

I'm trying to find way how to create button (selectAllNotes) to add all object with specific parametres (for example all annotation notes in layer 41) to previous selection block (selectNotes) in block styler dialog.

 

            ElseIf block Is selectAllNotes Then

                Dim visibleObjects() As DisplayableObject
                visibleObjects = theWorkPart.Views.WorkView.AskVisibleObjects

                For Each memView As Drawings.DraftingView In drfViews
                    Dim dispObjs As DisplayableObject() = theWorkPart.Views.WorkView.AskVisibleObjects()

                    For Each aDispObj As DisplayableObject In dispObjs

                        If TypeOf aDispObj Is Annotations.Note Then

                            If aDispObj.Layer = 41 Then
                                Dim aDispObjTaggedObject As TaggedObject = Utilities.NXObjectManager.Get(aDispObj.Tag)
                                selectNotes.SetSelectedObjects(aDispObjTaggedObject)
                            End If
                        End If
                    Next
                Next

 

Problem is, that SetSelectedObjects needs to value of type TaggedObject(), but aDispObjTaggedObject is type TaggedObject. Can I convert somehow type of this object?

1 REPLY 1

Re: Select all button in block styler dialog

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

 There are a few things going on in this code that I'd like to discuss, but first things first. To answer your question, if you have a single variable, but the function/method expects an array, you will need to create an array and assign your variable to it; something like below:

 

dim myVar as DisplayableObject
'assign something to myVar

'create array
dim multipleVars(0) as DisplayableObject
multipleVars(0) = myVar

.SetSelectedObjects(multipleVars)

 

VB.net has a shortcut for this where you can enclose the variable in curly braces to have the compiler treat it as an array with one member:

 

dim myVar as DisplayableObject
'assign something to myVar

.SetSelectedObjects({myVar})

 

 

On to the extra credit...

 

The code iterates over the drafting views in "drfViews". I assume that drfViews is the drafting view collection of the part. If that is the case, you might not find any note objects. Notes generally belong to the drawing sheet view, not individual drafting views. It is possible to create notes as view dependent in a drafting view, but it is not the normal use case. An alternative, one that would find all the notes, is to iterate over the part's .Notes collection. This would return all the notes whether on the sheet or in a view, and only the notes (not other object types). However, if you are only interested in the visible notes or notes on a certain sheet, you would need to filter for those.

 

In the NXOpen API object hierarchy, the note object is derived from the displayable object which is derived from the tagged object (there are other object types in between, but they are not important right now). You can think of a note object as a specialized tagged object. Any function/method that requires a tagged object as input can take a note object as input (or any object that inherits from the tagged object type). The upshot of this is that you don't need to convert from a displayable object type to a tagged object type before calling the .SetSelectedObjects method.

 

I've not done much work with block styler selections, so I'm unsure if the .SetSelectedObjects method appends the specified objects to the current selection or if it clears the selection and makes the specified objects the new selection. If it clears the selection, you will want to collect all the desired notes into an array (or, even better, a list) before passing them to the .SetSelectedObjects method.