×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

API - how to find named views and traverse?

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?

ModelDoc2::GetModelViewNames, perhaps?

RE: API - how to find named views and traverse?

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
Stop 'check your Locals window
Set mDoc = Nothing
Set swApp = Nothing
End Sub

batHonesty may be the best policy, but insanity is a better defense.bat
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: API - how to find named views and traverse?

(OP)
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:

http://sw.fcsuper.com/index.php?name=UpDownload&req=viewdownloaddetails&lid=128

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources