IV 11 - Select View By Name/Label

IV 11 - Select View By Name/Label

Anonymous
Not applicable
379 Views
7 Replies
Message 1 of 8

IV 11 - Select View By Name/Label

Anonymous
Not applicable
This line selects a particular drawing view by index:

Set oView = oDrawDoc.Sheets(2).DrawingViews(2)

What would the syntax be to select a drawing view by name and or label?

Set oView = oDrawDoc.Sheets(2).DrawingViews.Name("VIEW5") does not work.
0 Likes
380 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
Unfortunately, there isn't a direct way to retrieve a drawing view by its
name. You would have to iterate over all drawing views and find the one with
the matching Name. Another option is to store a reference key to the drawing
view instead of its name (use DrawingView.GetReferenceKey). You can then
'bind back' to the particular drawing view using
ReferenceKeyManager.BindKeyToObject. This is a much more robust mechanism
than using the name (the name could be localized or edited by the user).

Sanjay-

wrote in message news:5205983@discussion.autodesk.com...
This line selects a particular drawing view by index:

Set oView = oDrawDoc.Sheets(2).DrawingViews(2)

What would the syntax be to select a drawing view by name and or label?

Set oView = oDrawDoc.Sheets(2).DrawingViews.Name("VIEW5") does not work.
0 Likes
Message 3 of 8

Anonymous
Not applicable
OK, going back to the index. How exactly is that determined? If I have say 10 views of different parts on a sheet, are they index 1 thru 10? And does that index number remain constant? Are they indexed in the order they were created or location on the sheet or order in the browser?
If a view is deleted, are the rest re-numbered?
0 Likes
Message 4 of 8

Anonymous
Not applicable
In general, it is not a good idea to rely on the index. In most cases, the
index may match the order of creation and may remain constant (unless views
are deleted). But there is nothing that we do to guarantee this. So, the
only way to reliably identify a drawing view (or any persisted object for
that matter) is to use reference keys.

Sanjay-

wrote in message news:5206171@discussion.autodesk.com...
OK, going back to the index. How exactly is that determined? If I have say
10 views of different parts on a sheet, are they index 1 thru 10? And does
that index number remain constant? Are they indexed in the order they were
created or location on the sheet or order in the browser?
If a view is deleted, are the rest re-numbered?
0 Likes
Message 5 of 8

Anonymous
Not applicable
GET REFERENCE KEY METHOD
Method that generates and returns the reference key for this entity.
Do you determine the reference key for each view outside of the program? (listed in the properties somewhere)
If not, how do you generate a reference key for a view when your not certain which view (entity) your selecting?
0 Likes
Message 6 of 8

Anonymous
Not applicable
Well, you must have had a view to know its name in the first place, correct?
How did you obtain the view name?

Sanjay-

wrote in message news:5206257@discussion.autodesk.com...
GET REFERENCE KEY METHOD
Method that generates and returns the reference key for this entity.
Do you determine the reference key for each view outside of the program?
(listed in the properties somewhere)
If not, how do you generate a reference key for a view when your not certain
which view (entity) your selecting?
0 Likes
Message 7 of 8

Anonymous
Not applicable
I was selecting views by index, but that was consistently inconsistent and didn't seem to be based on any rhyme or reason. That's why I asked about selecting a view by it's name and you replied that's not possible.
So I didn't, and don't, understand how the program can consistently generate a reference key for an entity that can't be consistently selected by the program.
I think my best option for now is to perform the operation on all views. It's unnecessary, but I think it's the only way to make sure I get all of the views I need.
Thanks for your help Sanjay.
Jim
0 Likes
Message 8 of 8

Anonymous
Not applicable
I think you misunderstood what Sanjay said. It is possible to find a view
using the name. It's just that the Item property of the DrawingViews
collection does not support indexing by the name. In order to find a view
by the name you will need to iterate through the set of views and find a
matching name. The reason Sanjay was discouraging this approach, and the
reason the Item property doesn't support indexing by name, is that Inventor
does not enforce unique names for drawing views. You could have multiple
views with the exact same name. The idea if an identifier for an object is
that it should uniquely identify that object, which a view name does not
necessarily do. However, having said that, in most practical cases they are
unique and using the name will be ok. One other issue with using the name
is that the end-user can change the name which could break your program.
But again, in a semi-controlled environment you can probably rely on the
name.

Here's a small sample that demonstrates the look-up process using the name.

Public Sub GetViewSample()
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
Set oSheet = oDoc.ActiveSheet

Dim strViewName As String
strViewName = "VIEW2"
Dim oView As DrawingView
Dim oCheckView As DrawingView
For Each oCheckView In oSheet.DrawingViews
If UCase(strViewName) = UCase(oCheckView.name) Then
Set oView = oCheckView
Exit For
End If
Next

If oView Is Nothing Then
MsgBox "View " & strViewName & " was not found."
Else
MsgBox "View " & strViewName & " has a scale: " & oView.Scale
End If
End Sub
--
Brian Ekins
Autodesk Inventor API

wrote in message news:5206528@discussion.autodesk.com...
I was selecting views by index, but that was consistently inconsistent and
didn't seem to be based on any rhyme or reason. That's why I asked about
selecting a view by it's name and you replied that's not possible.
So I didn't, and don't, understand how the program can consistently generate
a reference key for an entity that can't be consistently selected by the
program.
I think my best option for now is to perform the operation on all views.
It's unnecessary, but I think it's the only way to make sure I get all of
the views I need.
Thanks for your help Sanjay.
Jim