Hi all
I need a little help with one of my macros! I usually manage to manage but not this time.
I would like to browse all the features of a part or assembly
In vba, with a macro integrated into SolidWorks, I get there with the code below.
But I would like to be able to do it in Vb.net without having to open Solidworks.
I have a bug on the last line. I have the impression that you can't access swFeat without opening SolidWorks?
If someone can help me, that would be cool!
Thank you
VBA Code:
Dim swApp As SldWorks.SldWorks
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
Dim swFeat As SldWorks.Feature
Set swFeat = swModel.FirstFeature
While Not swFeat Is Nothing
Debug.Print " " & swFeat.Name & " [" & swFeat.GetTypeName & "]"
Set swFeat = swFeat.GetNextFeature
Wend
End If
Vb.net Code:
Dim sDocFileName = "W:\...."
Dim swClassFact As SwDMClassFactory
Dim swDocMgr As SwDMApplication
Dim swDoc As SwDMDocument17
Dim nDocType As Integer
Dim nRetVal As Integer
Dim swCfgMgr As SwDMConfigurationMgr
If InStr(LCase(sDocFileName), "sldasm") > 0 Then
nDocType = SwDmDocumentType.swDmDocumentAssembly
Else
nDocType = SwDmDocumentType.swDmDocumentUnknown
Exit Sub
End If
If (nDocType = SwDmDocumentType.swDmDocumentAssembly) Then
swClassFact = CreateObject("SwDocumentMgr.SwDMClassFactory") 'si bug :Frameworks cible = .NET Framework 4
swDocMgr = swClassFact.GetApplication(sLicenseKey)
swDoc = swDocMgr.GetDocument(sDocFileName, nDocType, True, nRetVal)
swCfgMgr = swDoc.ConfigurationManager
Select Case nRetVal
Case 0
Debug.Print("File successfully opened : ")
End Select
End If
Debug.Print("File = " & swDoc.FullName)
Debug.Print("Active Configuration Name = " & swCfgMgr.GetActiveConfigurationName)
Dim swSelMgr As SelectionMgr
Dim swFeat As Feature
swSelMgr = swDoc.SelectionManager
swFeat = swCfgMgr.GetSelectedObject6(1, -1)