I need help. I'm doing a simple check of where used.doc.whereused returns an object. Now what?? I'm confused as to whatto do with that.
For doc.getexternalreferences I just did
For Each ref in doc.GetAllExternalReferences
debug.print(ref)
Next
That doesn't seem to work here or I am missing something.
Thanks for some help.SolidworksApi macros
For doc.getexternalreferences I just did
For Each ref in doc.GetAllExternalReferences
debug.print(ref)
Next
That doesn't seem to work here or I am missing something.
Thanks for some help.SolidworksApi macros

My question is I want to return STRINGS of the paths to thedocuments that use the document in question.
doc = Part1.sldprt
object = doc.WhereUsed(searchOp)
I want the paths man!!! I am confused.
Oh yes I've read the help. I didn't see the part where it says itreturns an array of strings. I declare return as VariantType and itsomes back as an Object.
I don't really understand the Variant. Isn't it just a reservedspace in memory used for whatever comes it's way? Like integer,string, object, etc?
I'll check it again tomorrow what VS says when I debug.
I got the for each to work on my vwhereused object and this is whatit printed.
E
m
p
t
y
Can someone try this one there own and see what they come up with??I think I'm doing someting wrong. I'm using vb.net.
Here is a complete working VBA macro to perform a "where used"search for a file. Sorry, no VB.net here, but you should be able tofigure it out. Both the filename and search path are hard-coded. Tomake this work, paste it into a new VBA macro and change thehard-coded paths to something valid on your system. Oh, and add areference to the document manager.
Sorry for the crappy formatting. Maybe the new forum format willhave some capability for posting formatted code.
Option Explicit
Dim dmClassFac As SwDocumentMgr.SwDMClassFactory
Dim dmDoc As SwDocumentMgr.SwDMDocument
Dim dmApp As SwDocumentMgr.SwDMApplication
Dim dmSrchOp As SwDocumentMgr.SwDMSearchOption
Dim vWhere As Variant
Dim myFilesList() As String
Dim i As Long
Dim j As Long
Sub main()
Set dmClassFac = New SwDocumentMgr.SwDMClassFactory
Set dmApp = dmClassFac.GetApplication(KEYSTRING)
If dmApp Is Nothing Then
MsgBox "Invalid License Key for Document Manager: " &KEYSTRING
End
End If
ReDim myFilesList(0)
myFilesList(0) = "This is where you put the path for the file youwant to find references for"
Set dmSrchOp = dmApp.GetSearchOptionObject
dmSrchOp.SearchFilters = SwDmSearchSubfolders + _
SwDmSearchForPart + _
SwDmSearchForDrawing + _
SwDmSearchForAssembly + _
SwDmSearchExternalReference + _
SwDmSearchInContextReference
dmSrchOp.ClearAllSearchPaths
dmSrchOp.AddSearchPath "This is where you put the search path. Youcan add as many as you want."
For i = 0 To UBound(myFilesList)
Set dmDoc = dmApp.GetDocument(myFilesList(i), swDmDocumentUnknown,True, Empty)
If Not dmDoc Is Nothing Then
vWhere = dmDoc.WhereUsed(dmSrchOp)
If IsArray(vWhere) Then
For j = 0 To UBound(vWhere)
Debug.Print vWhere(j)
Next j
Else
Debug.Print "No references found for " & myFilesList(i) &"."
End If
Else
Debug.Print "Unable to get document " & myFilesList(i) &"."
End If
Next i
End Sub
Also make sure all of your objects are loaded. Use explicitdefinitions and early binding to ensure you actually have thecorrect objects.
Meanwhile, play with this:
http://www.esoxrepublic.com/freeware/WhereUsed.php
Yes roland I did get a key from SW.
I've actually played with that program a while back.
Question.... Shouldn't the doc.GetAllExternalReferences(searchOp)method return results really fast. Actuall, why does it need tosearch at all? Am I missing something? Is my brain fried??
I could understand the WhereUsed method taking forever, but not thereferences. The part remembers it's references, right??
Wouldn't it be cool if the part just remembered where it was used??Seems like it would be sort of simple to implement down at SWHQ.
...
vWhere = dmDoc.WhereUsed(dmSrchOp)
If TypeOf (vWhere) Is System.Array Then
Dim aWhere As System.Array = CType(vWhere, System.Array)
For Each s As String In aWhere
Debug.Print(s)
Next
Else
Debug.Print("No references found for " & myFilesList(i) &".")
End If
...
Of course you'll have the System namespace imported but I was justmaking the example clearer.
I'm still working on the performance of this searching stuff.Anyone have any ideas?