Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

API: EnumDocuments2.Next 2

Status
Not open for further replies.

TheTick

Mechanical
Mar 5, 2003
10,194
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

[bat]All this machinery making modern music can still be open-hearted.[bat]
 
Replies continue below

Recommended for you

I was about to post how I already failed at this one, but decided to revisit it. It seems we both made the same mistake - believing the help file (haa haa)

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 &quot;.next&quot; 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.


 
Yeah, it does seem to have difficulty as advertized. Since you are only fetching one modeldoc at a time, I just lost the array.
Code:
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 = &quot;&quot;
    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.
 
[flowerface]
Zowee! It works!
Thanks, guys.

[bat]All this machinery making modern music can still be open-hearted.[bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor