Hoi allemaal
Ik heb een beetje hulp nodig met een van mijn macro's! Meestal lukt het me wel, maar deze keer niet.
Ik wil graag alle kenmerken van een onderdeel of assemblage bekijken
In vba, met een macro geïntegreerd in SolidWorks, kom ik er met de onderstaande code.
Maar ik zou het graag in Vb.net kunnen doen zonder Solidworks te hoeven openen.
Ik heb een bug op de laatste regel. Ik heb de indruk dat je geen toegang hebt tot swFeat zonder SolidWorks te openen?
Als iemand me kan helpen, zou dat cool zijn!
Bedankt
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)