How to select an element that is in a reference?

I have an element enumerator that holds elements both in a reference and in the current design file.

Set oEnumerator = ActiveModelReference.GetSelectedElements      'Capture the selected elements
ActiveModelReference.UnselectAllElements                   'Unselect all, ready to re-select only certain identified elements

I interrogate each element:

Set oElement = oEnumerator.Current             'Capture the current element in the set

I need to select certain elements - from either of the files. I can select the ones in the current design file with:

ActiveModelReference.SelectElement oElement

But when oElement is in a reference, I can't seem to select it. I have tried:

oElement.ModelReference.AsAttachment.SelectElement oElement

and various other combinations, but they don't work.

Here's the latest permutation of my code (don't laugh):

If oElement.ModelReference.IsAttachment Then
    ActiveModelReference.Attachments(oElement.ModelReference.Name).SelectElement oElement
Else
    ActiveModelReference.SelectElement oElement
End If

Can someone provide the code needed to select an element in a reference that may be nested 0 or more levels deep?

Thanks,

Graham

Parents Reply Children
  • Thanks for that, but the example doesn't show how to select the element (as in highlight it as if the user has clicked on it).

    Eg. If oElement.IsTextElement then  /// select (highlight) the element.

    Graham

  • If oElement.IsTextElement then

     oElement.Redraw.msdDrawingModeNormal 'or other msd if you put behind of Redraw

    End If

  • Graham said:
    The example doesn't show how to select the element

    Highlighting and selecting are two different things.  An element that is highlighted provides a visual cue that it is temporarily interesting.  'Selected' implies that the element will be the subject of some command using the noun-verb idiom (as opposed to the verb-noun idiom).  It's true that a selected element is often highlighted as well, but not necessarily and the converse is not true.

    Try:

    oElement.IsHighlighted = True

     
    Regards, Jon Summers
    LA Solutions

  • No thanks. Just want to select the element that's in a reference. When I say 'select', I mean the verb usage that Microstation uses, like .SelectElement, as I thought was evident in my original post.

  • Graham said:
    When I say 'select', I mean the verb usage that Microstation uses, like .SelectElement, as I thought was evident in my original post

    I apologise if I misunderstood your intent.

    Graham said:
    If oElement.IsTextElement then  /// select (highlight) the element

    Perhaps I found that misleading.

    Graham said:
    When I say 'select', I mean the verb usage that Microstation uses, like .SelectElement

    What exactly is not working?

    Set oEnumerator = ActiveModelReference.GetSelectedElements

    That does what it says: selects elements in the active model.  If you want to enumerate selected elements in an attachment, you need to say so:

    Set oEnumerator = oAttachment.GetSelectedElements

    When you get an enumerator, in general it contains elements from only one model. If you're looking to combine all selected elements then convert the enumerator from each model to an array, then combine the arrays.

    Fence Enumeration

    An enumeration obtained from a fence may contain elements both from the active model and from attachments.

     
    Regards, Jon Summers
    LA Solutions

  • Oh crap! I have just gone back and run my code with the original ActiveModelReference.SelectElement oElement statement, and when oElement refers to an element in a reference, IT NOW WORKS. As far as I know I haven't changed anything - though obviously something must be different. I have no idea why I was getting errors before.

    My appologies to mediocad and Jon for wasting their time. And thank you for trying to assist in the first place.