Cze wszystkim
Potrzebuję małej pomocy z jednym z moich makr! Zazwyczaj mi się udaje, ale nie tym razem.
Chcę przejrzeć wszystkie cechy części lub złożenia
W vba, z makrem zintegrowanym z SolidWorks, docieram tam za pomocą poniższego kodu.
Ale chciałbym móc to zrobić w Vb.net bez konieczności otwierania Solidworks.
Mam błąd w ostatnim wierszu. Mam wrażenie, że nie można uzyskać dostępu do swFeat bez otwarcia SolidWorks?
Jeśli ktoś może mi pomóc, to byłoby fajnie!
Dziękuję
Kod VBA:
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
Kod Vb.net:
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)