Ik weet dat dit onderwerp al vele malen is besproken en dat er zeker kant-en-klare toepassingen zijn.
Ik wil een Excel-stuklijst maken die automatisch wordt bijgewerkt wanneer deze wordt geopend, zonder dat de assemblage wordt geopend, om deze te integreren in een projectbeheertabel.
@Yannick: Het is mogelijk om dit te doen met Solidworks gesloten met "SolidWorks.Interop.swdocumentmgr.dll" (of zelfs met Solidworks niet geïnstalleerd met "swdocumentmgr.dll") Gebruik de functie GetComponents om de stuklijst op te halen.
Aan de andere kant, nu documentmanager alleen in x64 werkt, zouden we een externe module naar Excel moeten maken. En roep het aan vanuit een Excel-macro met het commando "Call Shell()". Of heb een applicatie die de stuklijst rechtstreeks naar een Excel-bestand schrijft.
Hier is een concept dat de stuklijst in dezelfde map zal schrijven als de assembly: (Kopieer de code naar een nieuwe VB.NET console-toepassing of gebruik het bijgevoegde bestand)
Imports System.IO
Imports SwDocumentMgr
'Imports SolidWorks.Interop.swdocumentmgr'
Module Module1
Private swDocMgr As SwDMApplication
Private Bom As New Dictionary(Of String, Integer)
Private TsvPath As String
Sub Main()
Dim LicenseFile As String = Path.Combine(My.Application.Info.DirectoryPath, "LicenseKey.txt")
Dim Lines As List(Of String) = File.ReadAllLines(LicenseFile).ToList
Dim LicenseKey As String = Lines(0)
If LicenseKey.Length < 50 Then
Console.Write("Entrer le numéro de license document manager dans ce fichier TXT")
Process.Start(LicenseFile)
Console.ReadLine()
System.Environment.Exit(-1)
End If
Dim Args As List(Of String) = System.Environment.GetCommandLineArgs.ToList
Dim AssyPath As String
If Args.Count = 2 Then
AssyPath = Args(1)
Else
Console.Write("Entrer le chemin de l'assemblage: ")
AssyPath = Console.ReadLine()
End If
Dim swCf As New SwDMClassFactory()
swDocMgr = swCf.GetApplication(Lines(0))
GetComps(AssyPath)
TsvPath = AssyPath.Replace(".SLDASM", ".TSV")
If File.Exists(TsvPath) Then File.Delete(TsvPath)
WriteLine("PN" & vbTab & "QT.")
For Each item In Bom.Keys
WriteLine(item & vbTab & Bom(item))
Next
End Sub
Private Sub GetComps(ByVal FilePath As String)
Dim DocType As SwDmDocumentType = SwDmDocumentType.swDmDocumentAssembly
Select Case Path.GetExtension(FilePath).ToLower
Case ".sldprt"
DocType = SwDmDocumentType.swDmDocumentPart
Case ".sldasm"
DocType = SwDmDocumentType.swDmDocumentAssembly
Case ".slddrw"
DocType = SwDmDocumentType.swDmDocumentDrawing
End Select
Dim res As Long
Dim swDoc As SwDMDocument13
swDoc = swDocMgr.GetDocument(FilePath, DocType, True, res)
Dim swConfig As SwDMConfiguration12
Dim swConfigMgr As SwDMConfigurationMgr = swDoc.ConfigurationManager
swConfig = swConfigMgr.GetConfigurationByName(swConfigMgr.GetActiveConfigurationName())
Dim comps As Object = swConfig.GetComponents()
Dim arrComps As Array = comps
If arrComps IsNot Nothing AndAlso arrComps.Length > 0 Then
For Each swComp As SwDMComponent9 In arrComps
If swComp.ExcludeFromBOM = swDmExcludeFromBOMResult.swDmExcludeFromBOM_TRUE _
OrElse swComp.IsSuppressed Then
Continue For
End If
If swComp.DocumentType = SwDmDocumentType.swDmDocumentAssembly Then
GetComps(swComp.PathName)
Else
Dim FileName As String = Path.GetFileNameWithoutExtension(swComp.PathName)
If Not Bom.ContainsKey(FileName) Then
Bom.Add(FileName, 1)
Else
Bom(FileName) += 1
End If
End If
Next
End If
swDoc.CloseDoc()
End Sub
Private Sub WriteLine(ByVal line As String)
Dim swt As StreamWriter
If Not File.Exists(TsvPath) Then
swt = File.CreateText(TsvPath)
Else
swt = File.AppendText(TsvPath)
End If
swt.WriteLine(line)
swt.Flush()
swt.Close()
End Sub
End Module
- Op de vraag "Naar uw mening is het mogelijk om een stuklijst te extraheren met Solidworks gesloten.": alles wordt gezegd door JeromeP met als bonus het voorbeeld dat goed gaat.
- Op de vraag "Hoe zou u te werk gaan? Een macro gebruiken op Excel? ": door een onafhankelijk programma dat de nomenclatuur zou ophalen om deze in een nieuw Excel-bestand te schrijven of een bestaand Excel-bestand in te vullen.
Hallo Jonathan, De bovenstaande tool gebruikt alleen SolidWorks. Je kunt het gebruiken in Excel met de functie:
Private Sub CommandButton1_Click()
Dim strProgramName As String
Dim strArgument As String
strProgramName = "C:\MesProgrammes\BomToXls.exe"
strArgument = "C:\MesFichiers\Assem1.SLDASM"
Call Shell("""" & strProgramName & """ """ & strArgument & """", vbNormalFocus)
End Sub