CutList Macro
Posted: Wed Mar 16, 2022 1:37 pm
Hello all,
I've got a macro I'm trying to modify to pull exactly what I need. What I'm looking for is when I run the macro, for my weldment Mk# to come from "Part Mk#" in File Properties and then be ordered sequentially. Right now when I run the macro the Mk# is coming from the file name.
This is the macro I'm using. I'm thinking the - Name = swModel.GetPathName is what I need to change, but I'm not sure what I need to insert to pull from file properties and not file name.
Thanks for any help. I've got just enough knowledge on this stuff to mess things up!
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim strValue0 As String
Dim strValue1 As String
Dim strValue2 As String
Dim bool As Boolean
Dim Name As String
Dim z, x As Integer
Dim boolstatus As Boolean
Sub main()
On Error Resume Next
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Name = swModel.GetPathName
Name = Dir(Name)
Name = Left(Name, Len(Name) - 7)
If Right(Name, 2) = "00" Then
Name = Left(Name, Len(Name) - 2)
Else: Name = Name & ""
End If
Set swFeat = swModel.FirstFeature
z = 1
x = 0
Do While Not swFeat Is Nothing
If swFeat.GetTypeName() = "CutListFolder" Then
x = x + 1
End If
Set swFeat = swFeat.GetNextFeature
Loop
Set swFeat = swModel.FirstFeature
If x > 1 Then
Do While Not swFeat Is Nothing
If swFeat.GetTypeName() = "CutListFolder" Then
Set swCustPropMgr = swFeat.CustomPropertyManager
If z < 10 Then
swCustPropMgr.Add3 "Mk#", 30, Name & "" & z, 1
ElseIf z >= 10 Then
swCustPropMgr.Add3 "Mk#", 30, Name & z, 1
End If
'for metalsheet
If UCase(swFeat.Name) Like "*SHEET*" Then
swCustPropMgr.Add3 "Mk#", 30, "Plate", 1
End If
z = z + 1
End If
Set swFeat = swFeat.GetNextFeature
Loop
End If
boolstatus = swModel.ForceRebuild3(True)
End Sub
I've got a macro I'm trying to modify to pull exactly what I need. What I'm looking for is when I run the macro, for my weldment Mk# to come from "Part Mk#" in File Properties and then be ordered sequentially. Right now when I run the macro the Mk# is coming from the file name.
This is the macro I'm using. I'm thinking the - Name = swModel.GetPathName is what I need to change, but I'm not sure what I need to insert to pull from file properties and not file name.
Thanks for any help. I've got just enough knowledge on this stuff to mess things up!
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim strValue0 As String
Dim strValue1 As String
Dim strValue2 As String
Dim bool As Boolean
Dim Name As String
Dim z, x As Integer
Dim boolstatus As Boolean
Sub main()
On Error Resume Next
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Name = swModel.GetPathName
Name = Dir(Name)
Name = Left(Name, Len(Name) - 7)
If Right(Name, 2) = "00" Then
Name = Left(Name, Len(Name) - 2)
Else: Name = Name & ""
End If
Set swFeat = swModel.FirstFeature
z = 1
x = 0
Do While Not swFeat Is Nothing
If swFeat.GetTypeName() = "CutListFolder" Then
x = x + 1
End If
Set swFeat = swFeat.GetNextFeature
Loop
Set swFeat = swModel.FirstFeature
If x > 1 Then
Do While Not swFeat Is Nothing
If swFeat.GetTypeName() = "CutListFolder" Then
Set swCustPropMgr = swFeat.CustomPropertyManager
If z < 10 Then
swCustPropMgr.Add3 "Mk#", 30, Name & "" & z, 1
ElseIf z >= 10 Then
swCustPropMgr.Add3 "Mk#", 30, Name & z, 1
End If
'for metalsheet
If UCase(swFeat.Name) Like "*SHEET*" Then
swCustPropMgr.Add3 "Mk#", 30, "Plate", 1
End If
z = z + 1
End If
Set swFeat = swFeat.GetNextFeature
Loop
End If
boolstatus = swModel.ForceRebuild3(True)
End Sub