Hello All,
I'm having an issue with a custom Addin, in which I cannot operate the SolidWorks Document Manager functions I need (I believe) due to files still being open in SolidWorks. I know that this is an issue, and have taken steps to get out of the files in SolidWorks before starting any of the DM functions. Unfortunately, the CloseDoc() function seems to not be working. Stepping through my code, the handlers detach and it looks like it closed in the code, but the part document remains on my screen in SWX as I step through the debug. Anybody have any thoughts on what's going on, or what I'm doing wrong? There is no way that CloseDoc() can be broken. Is this just a lingering graphic?
I'm trying to get a "where used" function so I can find a drawing that references a part.
Some code is attached below. I'd expect my brief description above is likely more helpful than the code, so please have a look.
I am not very familliar with the DM API, as this is my first run at it.
Thanks in advance.
Tom
Function GetWhereUsed(swPart As ModelDoc2) As String
Dim swDM As SolidWorks.Interop.swdocumentmgr.ISwDMApplication
Dim swDMclassFactory As SolidWorks.Interop.swdocumentmgr.ISwDMClassFactory
Dim drawingString As String = ""
Dim LicKey As String = "#################"
Dim FilePath As String
Dim FileDir As String
Dim swDMdocument As SolidWorks.Interop.swdocumentmgr.ISwDMDocument
Dim searchOption As SolidWorks.Interop.swdocumentmgr.ISwDMSearchOption
Dim whereUsedObj As Object
Dim swSameNameDrawing As SolidWorks.Interop.swdocumentmgr.ISwDMDocument5
Dim sameNameDrawingLocation As String
Dim extRef As Object
FilePath = swPart.GetPathName
iSwApp.CloseDoc(swPart.GetTitle) 'appearance of failure here. Unsure of actual issue.
swDMclassFactory = New SolidWorks.Interop.swdocumentmgr.SwDMClassFactory
swDM = swDMclassFactory.GetApplication(LicKey)
searchOption = swDM.GetSearchOptionObject
FileDir = Left(FilePath, (InStrRev(FilePath, "\\") - 1))
searchOption.SearchFilters = 127
searchOption.ClearAllSearchPaths()
searchOption.AddSearchPath(FileDir)
swDMdocument = swDM.GetDocument(FilePath, SolidWorks.Interop.swdocumentmgr.SwDmDocumentType.swDmDocumentUnknown, False, Nothing)
sameNameDrawingLocation = Left(FilePath, InStr(FilePath, ".") - 1) & ".slddrw"
swSameNameDrawing = swDM.GetDocument(sameNameDrawingLocation, SolidWorks.Interop.swdocumentmgr.SwDmDocumentType.swDmDocumentDrawing, False, Nothing)
extRef = swSameNameDrawing.GetAllExternalReferences2(searchOption, 0)
If Not extRef = Nothing Then
For i = 0 To UBound(extRef)
If UCase(extRef(i).ToString) = UCase(FilePath) Then
Return sameNameDrawingLocation
End If
Next
End If
whereUsedObj = swDMdocument.WhereUsed(searchOption) 'this always returns nothing every time. It used to work correctly.
End Function
SolidworksApi macros