Iterate through open documents with vba?

Is there a way to iterate through all open documents (Parts, Assemblies,
Drawings) with a "for loop" or array?
Can't find anything in the API, accept iterating through all sheets in a
drawing with "GetSheetNames"
Thanks
Reply to
What-a-Tool
Loading thread data ...
Go to SW help search and look for "Get Names of Open Documents Example (VB)". This example goes through all the open docs.
WT
Reply to
Wayne Tiffany
Looked in help and API help - can't find it. (using 04 rite now.) Searched online api help and can't find. Please give more detail?
Reply to
What-a-Tool
You want to start with the EnumDocuments2 object, which is SW's collection of loaded documents. It's a bit klunky, but it works. See example cited in orhter message.
What-a-Tool wrote:
Assemblies,
Reply to
That70sTick
Sorry, I was in 2005. But,,,, I can't, for the life of me, figure out why I can't find the same example in 2004. I looked at the methods and they were available in 2001+ or so. Anyway, I have listed the example here for you. I don't know just ow it will parse out the lines, so pay attention. Or, let me know and I will email it directly to you.
WT
Get Names of Open Documents Example (VB) This example shows how to get the name of the documents open in a SolidWorks session.
'-------------------------------------
'
' Preconditions: SolidWorks application is running.
'
' Postconditions: None
'
'-------------------------------------
Option Explicit
Public Enum swDocumentTypes_e
swDocNONE = 0 ' Used to be TYPE_NONE
swDocPART = 1 ' Used to be TYPE_PART
swDocASSEMBLY = 2 ' Used to be TYPE_ASSEMBLY
swDocDRAWING = 3 ' Used to be TYPE_DRAWING
End Enum
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelTitle As SldWorks.ModelDoc2
Dim swModelPath As SldWorks.ModelDoc2
Dim cTitle As New Collection
Dim vTitle As Variant
Dim cPath As New Collection
Dim vPath As Variant
Set swApp = Application.SldWorks
Set swModel = swApp.GetFirstDocument
While Not swModel Is Nothing
' Assembly components are opened, but are not visible
' until opened by the user
Debug.Print swModel.GetPathName & " [" & swModel.Visible & "]"
Debug.Print " " & swModel.GetTitle & " [" & swModel.GetType & "]"
' The document name contains a filename extension
' if the document has been already saved
' and is subject to Microsoft Explorer setting;
' the document name does not contain a
' filename extension if the document has not been saved;
' ModelDoc2::GetPathName is blank until the file is saved
cTitle.Add swModel.GetTitle
cPath.Add swModel.GetPathName
Set swModel = swModel.GetNext
Wend
Debug.Print "--------------------------"
For Each vTitle In cTitle
Set swModelTitle = swApp.GetOpenDocument(vTitle): Debug.Assert Not swModelTitle Is Nothing
Debug.Print swModelTitle.GetPathName & " [" & swModelTitle.Visible & "]"
Debug.Print " " & swModelTitle.GetTitle & " [" & swModelTitle.GetType & "]"
Next vTitle
Debug.Print "--------------------------"
For Each vPath In cPath
Set swModelPath = swApp.GetOpenDocument(vPath)
If Not swModelPath Is Nothing Then
Debug.Print swModelPath.GetPathName & " [" & swModelPath.Visible & "]"
Debug.Print " " & swModelPath.GetTitle & " [" & swModelPath.GetType & "]"
End If
Next vPath
Debug.Print "--------------------------"
End Sub
'-------------------------------------
message
Reply to
Wayne Tiffany
"Wayne Tiffany" wrote in news: snipped-for-privacy@uni-berlin.de:
I seem to remember reading in some release notes somewhere that a lot of examples were added to the API help for 05. The must be a new one.
Reply to
Dale Dunn
I posted something not too long ago. Do a search on this group under my name and "Close All Open Documents" and you should find the code.
The SW sample was kinda sketchy, so I ended up rewriting their code.
Evan
message
Reply to
Evan T. Basalik

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.