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