Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

API - how to find named views and traverse?

Status
Not open for further replies.

fcsuper

Mechanical
Apr 20, 2006
2,204
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
 
Replies continue below

Recommended for you

Sample code:

Code:
Dim swApp As SldWorks.SldWorks
Dim mDoc As SldWorks.ModelDoc2
Dim vViews As Variant
Sub main()

Set swApp = Application.SldWorks
Set mDoc = swApp.ActiveDoc
vViews = mDoc.GetModelViewNames
[b]Stop [COLOR=green]'check your Locals window[/color][/b]
Set mDoc = Nothing
Set swApp = Nothing
End Sub

[bat]Honesty may be the best policy, but insanity is a better defense.[bat]
-SolidWorks API VB programming help
 
Roland,

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:


Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor