shawn76o
Nuclear
- Nov 14, 2006
- 31
Hi all,
Bear with me here, I'm trying to learn how to use the SldWorks.CustomPropertyManager object, but the examples I've see in SW API help require the user to select a "weldment feature", and the API code uses a "SldWorks.SelectionMgr" object to set the "SldWorks.Feature" object, which finally sets the "SldWorks.CustomPropertyManager" object. (I hope that made sense...)
First part of question - am I understanding the SelectionManager object correctly? I understand it's "GetSelectedObject" method to mean "Get the object that the user has selected". Or does it mean "Get the programatically selected object"? If it means "user has selected", then I don't understand how this type of macro would be useful for custom properties. If the user has to manually select a feature, then open and run a macro to add a custom property, as shown in the example below, it seems it would be just as easy just to select a feature then click File/Properties, wouldn't it? Or did I miss the point?
Second part of question - Is there a way to load the CustomPropertyManager object without first "consulting" the SelectionManager object? Please see the code below to see what I'm referring to. I'm hoping there is a way to load the CustomPropertyManager with information from a Component2 object that's currently in memory..
See what I mean? Is there a way to set the CustomPropertyManager object WITHOUT first using the SelectionManager?
OR... can the SelectionManager's method "GetSelectedObject5" call an object that was PROGRAMATICALLY selected, as opposed to MANUAL selection by the user?![[ponder] [ponder] [ponder]](/data/assets/smilies/ponder.gif)
Shawn Oelschlager
Production Control Ass't
Transco Products Inc.
SolidWorks Office Premium 2006 - SP4.1
Pentium 4 (2.8 GHz) - 2GB RAM
Bear with me here, I'm trying to learn how to use the SldWorks.CustomPropertyManager object, but the examples I've see in SW API help require the user to select a "weldment feature", and the API code uses a "SldWorks.SelectionMgr" object to set the "SldWorks.Feature" object, which finally sets the "SldWorks.CustomPropertyManager" object. (I hope that made sense...)
First part of question - am I understanding the SelectionManager object correctly? I understand it's "GetSelectedObject" method to mean "Get the object that the user has selected". Or does it mean "Get the programatically selected object"? If it means "user has selected", then I don't understand how this type of macro would be useful for custom properties. If the user has to manually select a feature, then open and run a macro to add a custom property, as shown in the example below, it seems it would be just as easy just to select a feature then click File/Properties, wouldn't it? Or did I miss the point?
Second part of question - Is there a way to load the CustomPropertyManager object without first "consulting" the SelectionManager object? Please see the code below to see what I'm referring to. I'm hoping there is a way to load the CustomPropertyManager with information from a Component2 object that's currently in memory..
Code:
This example shows how to add a custom property to and gets the custom properties assigned to a weldment feature.
[green]'------------------------------------------[/green]
[green]'[/green]
[green]' Preconditions:[/green]
[green]' (1) Model document is open.[/green]
[green]' (2) Weldment feature is selected.[/green]
[green]'[/green]
[green]' Postconditions: Custom property named Date added is added to the selected weldment feature.[/green]
[green]'----------------------------------------[/green]
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.feature
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim nRetVal As Long
Dim vNameArr As Variant
Dim vName As Variant
Dim bRet As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFeat = swSelMgr.GetSelectedObject5(1)
Set swCustPropMgr = swFeat.CustomPropertyManager
[green]' Feature::GetTypeName[/green]
[green]' "SubWeldFolder"[/green]
[green]' "WeldmentFeature"[/green]
[green]' CustomPropertyManager::Add/GetType[/green]
[green]' FieldType[/green]
[green]' "Text"[/green]
[green]' "Date"[/green]
[green]' "Number"[/green]
[green]' "Yes or no"[/green]
Debug.Print "File = " & swModel.GetPathName
Debug.Print " " & swFeat.Name & " [" & swFeat.GetTypeName & "]"
[green]' Add custom property[/green]
bRet = swCustPropMgr.Add("Date added", "Date", "27-apr-2004")
[green]' Get all custom properties; Date added is the last one in the list
[/green]
vNameArr = swCustPropMgr.GetNames: If IsEmpty(vNameArr) Then Exit Sub
For Each vName In vNameArr
Debug.Print " " & vName & " [" & swCustPropMgr.GetType(vName) & "] = " & swCustPropMgr.Get(vName)
Next vName
End Sub
[green]'------------------------------------------[/green]
See what I mean? Is there a way to set the CustomPropertyManager object WITHOUT first using the SelectionManager?
OR... can the SelectionManager's method "GetSelectedObject5" call an object that was PROGRAMATICALLY selected, as opposed to MANUAL selection by the user?
![[ponder] [ponder] [ponder]](/data/assets/smilies/ponder.gif)
Shawn Oelschlager
Production Control Ass't
Transco Products Inc.
SolidWorks Office Premium 2006 - SP4.1
Pentium 4 (2.8 GHz) - 2GB RAM