Document Manager Where Used

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
Answers 15
SF
SF 2009-06-23 Best Answer
I'm summoning the programming experts..... anyone able to getthis one??
SF
SF 2009-06-23
I re-read my post. I must have been on too much coffee orsomething when I wrote it.

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.
JB
JB 2009-06-23
Have you read the help? According to the documentation,WhereUsed returns a variant array of strings.
SF
SF 2009-06-24
Hey thanks for the reply Josh.

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.

JB
JB 2009-06-24
Do you have access to the 2008 API help file? It's much morehelpful than the 2009 help. 2009 help is "standardized" orsomething to M$'s preference. 2008 API help says it's a variant oftype SafeArray.
SF
SF 2009-06-24
Try casting your variant into a string[] and then use foreach?
SF
SF 2009-06-24
Thanks for the help guys. I'm still not getting it. I have ahuge headache and I don't think today is the day I'm going to beable to figure it out on my own.

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.
JB
JB 2009-06-24
If you got "Empty", it sounds like your document is not usedanywhere in the search path.

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
SF
SF 2009-06-24
Use object.ToString
RS
RS 2009-06-24
Learn to use the Locals window in your VBA editor to checkvariables. Use a Stop statement to pause your program whenchecking.

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
RS
RS 2009-06-24
p.s. did you get a key code from SW API support?
SF
SF 2009-06-24
Thank you Josh it worked great. I'll study the syntax more soI understand what I'm doing.

Yes roland I did get a key from SW.

I've actually played with that program a while back.
SF
SF 2009-06-24
I'm hi-jacing my own thread here.

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.
SF
SF 2009-06-25
Regarding casting the VB6 variant to .Net System.Array. Belowis an example of one way you could port Josh's example to VB.NetThis is just showing the snippet that deals w/COM variant return.Variants are just objects in .Net

...
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.
SF
SF 2009-06-25
Thanks for the input Brendan. This is very helpful.

I'm still working on the performance of this searching stuff.Anyone have any ideas?