API - how to find named views and traverse?
API - how to find named views and traverse?
(OP)
I don't have any code to post for this question yet because I cannot even find the methods to use for this: How do I get the names of the named views in a part? I wish to traverse all named views and save them to an array, then search for a particular name or names.
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group






RE: API - how to find named views and traverse?
RE: API - how to find named views and traverse?
CODE
Dim mDoc As SldWorks.ModelDoc2
Dim vViews As Variant
Sub main()
Set swApp = Application.SldWorks
Set mDoc = swApp.ActiveDoc
vViews = mDoc.GetModelViewNames
Stop 'check your Locals window
Set mDoc = Nothing
Set swApp = Nothing
End Sub
http://www.EsoxRepublic.com-SolidWorks API VB programming help
RE: API - how to find named views and traverse?
Thanks for the help. I couldn't find that roaming around the API help.
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
RE: API - how to find named views and traverse?
Thanks for the help...this is what I came up with:
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim ViewList As Variant
Dim i As Long
Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
ViewList = Part.GetModelViewNames
For i = 0 To UBound(ViewList)
If ViewList(i) = "InstantView" Then Call ShowView
Next
Part.NameView "InstantView"
MsgBox "InstantView did not exist. New InstantView saved from current view.", vbInformation
Set Part = Nothing
End
End Sub
Sub ShowView()
'Part.ShowNamedView2 "InstantView", -1
' There is an error with ShowNamedView2 that does not
' allow this function to work as expect in drawings in SW2007
Part.ShowNamedView "InstantView"
Set Part = Nothing
End
End Sub
This, and the companion macro are available here:
http://
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group