macro is in english
'*******************************************************
'SLOWorks.fi, 2014
'*******************************************
'variables and constants
Dim SwApp As SldWorks.SldWorks
Dim Model As SldWorks.ModelDoc2
Dim spec As SldWorks.DocumentSpecification
Dim retval As Boolean
Dim File, Path, Title As String
Dim Attrkpl, Attrkplm As String
Dim AttrNimiSolu As Range
Dim Config As Variant
'Const swDocPart = 1
Const swCustomInfoText = 30
Private Sub CommandButton1_Click()
'how many attributes are read
Attrkpl = Taul1.Range("D3").Value
Attrkplm = "-" & Attrkpl
'' gripped 'to the SW
Set SwApp = CreateObject("SldWorks.Application")
SwApp.Visible = True
'Activate the sheeting for security
Worksheets("Parts").Activate
'read the directory
File = Dir(Taul1.Range("D4").Value & "\ *. Sldprt")
'read the given workbook
Path = Taul1.Range("D4").Value & "\"
'clears the old values ??and moves to the starting point
Sheet1.Range("A8:Z500").Select
Selection.ClearContents
Taul1.Range("A8").Select
'open files one after the other
Do While File <> ""
Set spec = SwApp.GetOpenDocSpec(Path & File)
spec.Silent = True
Dim err, war As Long
Set Model = SwApp.OpenDoc6(Path & File, SwConst.swDocumentTypes_e.swDocPart, SwConst.swOpenDocOptions_e.swOpenDocOptions_Silent, "", SwConst.swFileLoadError_e.swGenericError, SwConst.swFileLoadWarning_e.swFileLoadWarning_BasePartNotLoaded)
'LISTENED DATA NAME
ActiveCell.Value = File
ActiveCell.Offset(0, 1).Activate
'enter the custom cell text
ActiveCell.Value = "* Custom *"
'will move to the ekr attr value
ActiveCell.Offset(0, 1).Activate
'CUSTOM ATTRIBUTE
Set AttrNimiSolu = Taul1.Range("C6")
For i = 1 To Attrkpl
ActiveCell.Value = Model.GetCustomInfoValue("", AttrNimiSolu)
ActiveCell.Offset(0, 1).Activate
Set AttrNimiSolu = AttrNimiSolu.Offset(0, 1)
Next i
'NEXT. RIVI, CONFIGURATIONS
'will go to the ekan config name
ActiveCell.Offset(1, Attrkplm - 1).Activate
'read the template names
Config = Model.GetConfigurationNames
'for every car you make ...
For i = 0 To UBound(Config)
Set AttrNimiSolu = Taul1.Range("C6")
'enter the name into the cell
ActiveCell.Value = Config(i)
ActiveCell.Offset(0, 1).Activate
'read the data
For j = 1 To Attrkpl
ActiveCell.Value = Model.GetCustomInfoValue(Config(i), AttrNimiSolu)
ActiveCell.Offset(0, 1).Activate
Set AttrNimiSolu = AttrNimiSolu.Offset(0, 1)
Next j
ActiveCell.Offset(1, Attrkplm - 1).Activate
Next i
'transfer to the next file
ActiveCell.Offset(1, -1).Activate
'FOLDING FILE
Title = Model.GetTitle
SwApp.CloseDoc Title
'the next file
File = Dir()
Set SwApp = CreateObject("SldWorks.Application")
'looped until all folder filet passed through
Loop
MsgBox "Done!"
End Sub
Private Sub CommandButton2_Click()
'how many attributes are read
Attrkpl = Taul1.Range("D3").Value
Attrkplm = "-" & Attrkpl
'' gripped 'to the SW
Set SwApp = CreateObject("SldWorks.Application")
'Activate the sheeting for security
Worksheets("Parts").Activate
'read a work folder
Path = Taul1.Range("D4").Value & "\"
'to the start point
Taul1.Range("A8").Activate
'until the filename is empty, ie the templates are over ...
Do While ActiveCell.Value <> ""
'open the file
File = ActiveCell.Value
Set Model = SwApp.OpenDoc(Path & File, swDocPart)
ActiveCell.Offset(0, 2).Activate
'delete custom information and type new
Set AttrNimiSolu = Taul1.Range("C6")
For i = 1 To Attrkpl
retval = Model.DeleteCustomInfo2("", AttrNimiSolu)
retval = Model.AddCustomInfo3("", AttrNimiSolu, swCustomInfoText, ActiveCell.Value)
ActiveCell.Offset(0, 1).Activate
Set AttrNimiSolu = AttrNimiSolu.Offset(0, 1)
Next i
'Configuration information the same thing, first transfer
ActiveCell.Offset(1, Attrkplm - 1).Activate
Config = Model.GetConfigurationNames
For j = 0 To UBound(Config)
Set AttrNimiSolu = Taul1.Range("C6")
Configuration = ActiveCell.Value
For k = 1 To Attrkpl
ActiveCell.Offset(0, 1).Activate
If ActiveCell.Value <> "" Then
retval = Model.DeleteCustomInfo2(Configuration, AttrNimiSolu)
retval = Model.AddCustomInfo3(Configuration, AttrNimiSolu, swCustomInfoText, ActiveCell.Value)
Else
retval = Model.DeleteCustomInfo2(Configuration, AttrNimiSolu)
End If
Set AttrNimiSolu = AttrNimiSolu.Offset(0, 1)
Next k
ActiveCell.Offset(1, Attrkplm).Activate
Next j
'go next to the title
ActiveCell.Offset(1, -1).Activate
'save and close the already processed template
Model.Save
Title = Model.GetTitle
SwApp.CloseDoc Title
Set SwApp = CreateObject("SldWorks.Application")
Loop
MsgBox "Done!"
End Sub