This website uses cookies to ensure you get the best experience on our website. By using our website you agree on the following Cookie Policy, Privacy Policy, and Terms Of Use
All sheets are renamed based on the value of this property. Macro will get the value from the model view specified in the Sheet Properties.
The 'Same as sheet specified in Document Properties' option is not supported.
If this option is selected then the property from the first view will be used.
Macro will try to read the configuration specific property and if the property is not specified then model level property is read.
Dim swApp As SldWorks.SldWorks
Dim swDraw As SldWorks.DrawingDoc
Sub main()
Set swApp = Application.SldWorks
Set swDraw = swApp.ActiveDoc
If swDraw IsNothingThen
MsgBox "Please open the drawing"EndEndIfDim prpName AsString
prpName = InputBox("Please specify the custom property name to get the value from")
Dim vSheetNames AsVariant
vSheetNames = swDraw.GetSheetNames
Dim i AsIntegerFor i = 0 To UBound(vSheetNames)
Dim swSheet As SldWorks.Sheet
Set swSheet = swDraw.Sheet(vSheetNames(i))
Dim custPrpViewName AsString
custPrpViewName = swSheet.CustomPropertyView
Dim vViews AsVariant
vViews = swSheet.GetViews()
Dim swCustPrpView As SldWorks.View
Set swCustPrpView = NothingDim j AsIntegerFor j = 0 To UBound(vViews)
Dim swView As SldWorks.View
Set swView = vViews(j)
If LCase(swView.Name) = LCase(custPrpViewName) ThenSet swCustPrpView = swView
ExitForEndIfNextIf swCustPrpView IsNothingThenSet swCustPrpView = vViews(0)
EndIfIfNot swCustPrpView IsNothingThenDim swRefConfName AsStringDim swRefDoc As SldWorks.ModelDoc2
swRefConfName = swCustPrpView.ReferencedConfiguration
Set swRefDoc = swCustPrpView.ReferencedDocument
IfNot swRefDoc IsNothingThenDim prpValue AsString
prpValue = GetCustomPropertyValue(swRefDoc, swRefConfName, prpName)
If prpValue <> ""Then
swSheet.SetName (prpValue)
EndIfElse
MsgBox "Failed to get the model from drawing view. Make sure that the drawing is not lightweight"EndIfElse
MsgBox "Failed to get the view to get property from"EndIfNextEndSubFunction GetCustomPropertyValue(model as SldWorks.ModelDoc2, confName asString, prpName AsString) AsStringDim prpValue AsString
model.Extension.CustomPropertyManager(confName).Get3 prpName, False, "", prpValue
If prpValue = ""Then
model.Extension.CustomPropertyManager("").Get3 prpName, False, "", prpValue
EndIf
GetCustomPropertyValue = prpValue
EndFunction
Notifications
Join session by SOLIDWORKS and PDM API expret Artem Taturevych at 3DEXPERIENCE World 2025 on Feb 26 at 08:30 AM CST to explore 10 essential macros for automating drawings, assemblies, custom properties, and more