API: EnumDocuments2.Next
API: EnumDocuments2.Next
(OP)
I can't seem to get this to work. I've tried many different ways of defining rGelt, but no go. I keep getting a type mismatch error when I run.
pasted from API help:
Syntax (OLE Automation)
retval = EnumDocuments2.Next ( celt, rgelt, &pceltFetched )
Input:
(long) celt
Number of documents desired for the enumerated list
Output:
(LPMODELDOC2*) rgelt
Pointer to an array of size celt to hold the documents
Output:
(long) pceltFetched
Pointer to the number of documents returned from the list; this value can be less than celt if you ask for more documents than exist, or it can be NULL if no more documents exist.
end of pasted text
Private Sub cmdEnum_Click()
Dim f As Long
Dim eList As SldWorks.EnumDocuments2
Dim eItem As SldWorks.ModelDoc2
Dim Celt As Long
Dim rGelt(0 To 0) As SldWorks.ModelDoc2
Dim pCeltFetched As Long
Dim DocList() As String
Dim DocCounter As Long
Celt = 1
DocCounter = -1
Set eList = swApp.EnumDocuments2
eList.Reset
Do
retVal = eList.Next(Celt, rGelt, pCeltFetched)
If pCeltFetched < 1 Then Exit Do
DocCounter = DocCounter + 1
ReDim Preserve DocList(0 To DocCounter)
DocList(DocCounter) = rGelt(LBound(rGelt)).GetPathName
Loop
Files = DocList
lboDocs.Clear
lboDocs.List = Files
End Sub
pasted from API help:
Syntax (OLE Automation)
retval = EnumDocuments2.Next ( celt, rgelt, &pceltFetched )
Input:
(long) celt
Number of documents desired for the enumerated list
Output:
(LPMODELDOC2*) rgelt
Pointer to an array of size celt to hold the documents
Output:
(long) pceltFetched
Pointer to the number of documents returned from the list; this value can be less than celt if you ask for more documents than exist, or it can be NULL if no more documents exist.
end of pasted text
Private Sub cmdEnum_Click()
Dim f As Long
Dim eList As SldWorks.EnumDocuments2
Dim eItem As SldWorks.ModelDoc2
Dim Celt As Long
Dim rGelt(0 To 0) As SldWorks.ModelDoc2
Dim pCeltFetched As Long
Dim DocList() As String
Dim DocCounter As Long
Celt = 1
DocCounter = -1
Set eList = swApp.EnumDocuments2
eList.Reset
Do
retVal = eList.Next(Celt, rGelt, pCeltFetched)
If pCeltFetched < 1 Then Exit Do
DocCounter = DocCounter + 1
ReDim Preserve DocList(0 To DocCounter)
DocList(DocCounter) = rGelt(LBound(rGelt)).GetPathName
Loop
Files = DocList
lboDocs.Clear
lboDocs.List = Files
End Sub
All this machinery making modern music can still be open-hearted.






RE: API: EnumDocuments2.Next
i changed the 'rgelt' to a SINGLE modeldoc reference, instead of the array stated in the help file.
from:
Dim rGelt(0 To 0) As SldWorks.ModelDoc2
to:
Dim rGelt As SldWorks.ModelDoc2
I then called the ".next" class reference to a subroutine-type call instead of a function-style call:
from:
retVal = eList.Next(Celt, rGelt, pCeltFetched)
to :
eList.Next Celt, rGelt, pCeltFetched
You'll have to check each rgelt for NOTHING, etc, to break out of the loop.
RE: API: EnumDocuments2.Next
Private Sub cmdEnum()
Dim eList As SldWorks.EnumDocuments2
Dim eItem As SldWorks.ModelDoc2
Dim Celt As Long
Dim rGelt As Object
Dim pCeltFetched As Long
Dim sMsg As String
Set swApp = Application.SldWorks
Celt = 1
Set eList = swApp.EnumDocuments2
sMsg = ""
Do
eList.Next Celt, rGelt, pCeltFetched
If pCeltFetched < 1 Then Exit Do
sMsg = sMsg & rGelt.GetPathName & vbCrLf
Loop
MsgBox sMsg
End Sub
This sends me a message with a list of all of the files currently opened.
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: API: EnumDocuments2.Next
Zowee! It works!
Thanks, guys.