-
Re: Display part’s custom properties on drawing sheet by using Macro
Marshall Wilson Jul 15, 2017 3:59 PM (in response to Xh Z)I'm not a fancy API guy, but this quick-n-dirty might work.
Create layers on the drawing template with notes on them. The notes could have references to the custom properties you want to show/hide.
By default they could be hidden and there's an easy macro for hiding / revealing layers.
Of course if I weren't so lazy I'm sure there's easy code for inserting a pre-determined note at coordinates (x,y).
Here's my code for a show/hide toogle of a layer that has an alignment grid on it.
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swLayerMgr As SldWorks.LayerMgr
Dim swLayer As SldWorks.Layer
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swLayerMgr = swModel.GetLayerManager
Set swLayer = swLayerMgr.GetLayer("15 - GRID")
If swLayer.Visible = False Then
' Toggle layer on
swLayer.Visible = True
Debug.Assert True = swLayer.Visible
Else
' Toggle layer off
swLayer.Visible = False
Debug.Assert False = swLayer.Visible
End If
End Sub
'-----------------------------------
-
Re: Display part’s custom properties on drawing sheet by using Macro
Xh Z Jul 16, 2017 12:08 PM (in response to Marshall Wilson)Hello Wilson,
thank you for the reply. your macro shows me another way to achieve it.
But i prefer to display the values directly using macro.
-
-
Re: Display part’s custom properties on drawing sheet by using Macro
Deepak Gupta Jul 16, 2017 3:27 AM (in response to Xh Z)You need to display the property as linked OR want just the value?
-
Re: Display part’s custom properties on drawing sheet by using Macro
Xh Z Jul 16, 2017 12:08 PM (in response to Deepak Gupta)Hello Deepak,
i just want to display the value of the custom property.
-
Re: Display part’s custom properties on drawing sheet by using Macro
Deepak Gupta Jul 16, 2017 1:09 PM (in response to Xh Z)Try these codes
Option Explicit Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swDraw As SldWorks.DrawingDoc Dim swView As SldWorks.View Dim swCustProp As CustomPropertyManager Dim Note As SldWorks.Note Dim swAnn As SldWorks.Annotation Dim valOut As String Dim rValOut As String Sub main() Set swApp = Application.SldWorks Set swDraw = swApp.ActiveDoc Set swView = swDraw.GetFirstView Set swView = swView.GetNextView Set swModel = swView.ReferencedDocument Set swCustProp = swModel.Extension.CustomPropertyManager(swView.ReferencedConfiguration) swCustProp.Get2 "DesignedBy", valOut, rValOut 'Change the custom property name here Debug.Print "$PRP:" + Chr(34) + "DesignedBy" + Chr(34) Set Note = swDraw.InsertNote(rValOut) ' Use "$PRPSHEET:" + Chr(34) + "DesignedBy" + Chr(34) in case you want to link to property Set swAnn = Note.GetAnnotation swAnn.SetPosition2 0, 0, 0 'Change note position here End Sub
-
Re: Display part’s custom properties on drawing sheet by using Macro
Xh Z Jul 23, 2017 12:15 AM (in response to Deepak Gupta)Thank you Deepak,
it works well.
for read the custom properties from the default model (we do not have any other configurations in the part), i have changed the line as:
Set swCustProp = swModel.Extension.CustomPropertyManager("")
Thank you.
-
Re: Display part’s custom properties on drawing sheet by using Macro
Deepak Gupta Jul 23, 2017 3:18 AM (in response to Xh Z)Since you said configuration in the first post, I used configuration properties. Glad to know that you got it working
-
Re: Display part’s custom properties on drawing sheet by using Macro
Xh Z Jul 23, 2017 5:51 AM (in response to Deepak Gupta)Thank you again.
is there any method to automatically run this macro when i open a drawing (or upon rebuild, or upon save)?
-
Re: Display part’s custom properties on drawing sheet by using Macro
Deepak Gupta Jul 23, 2017 6:28 AM (in response to Xh Z)Yes it is possible using event. Check this example: Fire Notification When Activating a Sheet Example (VBA)
-
-
-
-
-
-