CutList Macro

Library for macros
wdoguin4
Posts: 2
Joined: Wed Mar 16, 2022 12:33 pm
Answers: 0

CutList Macro

Unread post by wdoguin4 »

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
Attachments
FileProperties.JPG
WeldmentProperties.JPG
User avatar
zwei
Posts: 701
Joined: Mon Mar 15, 2021 9:17 pm
Answers: 18
Location: Malaysia
x 185
x 600

Re: CutList Macro

Unread post by zwei »

The MK# is assigned with name value is because of the following code:

Code: Select all

If z < 10 Then

swCustPropMgr.Add3 "Mk#", 30, Name & "" & z, 1

ElseIf z >= 10 Then

swCustPropMgr.Add3 "Mk#", 30, Name & z, 1
http://help.solidworks.com/2014/english ... ~add3.html


You could use CustomInfo or Get5 to get the Part MK# in your custom properties and assign it to your MK#
EG:

Code: Select all

Dim PartMKNo As String
PartMKNo = swModel.CustomInfo("Part Mk#")

If z < 10 Then

swCustPropMgr.Add3 "Mk#", 30, PartMKNo & "" & z, 1

ElseIf z >= 10 Then

swCustPropMgr.Add3 "Mk#", 30, PartMKNo & z, 1

Far too many items in the world are designed, constructed and foisted upon us with no understanding-or even care-for how we will use them.
wdoguin4
Posts: 2
Joined: Wed Mar 16, 2022 12:33 pm
Answers: 0

Re: CutList Macro

Unread post by wdoguin4 »

Zhen, thank you!
I'm having a difficult time trying to determine where to put the "PartMKNo = swModel.CustomInfo("Part Mk#")" line. When I add it under the "Dim PartMKNo As String" I get an Invalid outside procedure error.
image.png
When I add it anywhere else I get a Name not defined error.

Sorry to be a bother, but thank you for your help!
Post Reply