×
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: EnumDocuments2.Next
2

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

All this machinery making modern music can still be open-hearted.

RE: API: EnumDocuments2.Next

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 ".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

Yeah, it does seem to have difficulty as advertized. Since you are only fetching one modeldoc at a time, I just lost the array.

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

(OP)

Zowee!  It works!
Thanks, guys.

All this machinery making modern music can still be open-hearted.

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