Get Custom Properties for Configuration Example (C#)
This example shows how to get the names, types, values, and resolved
values of the active configuration's custom properties. It also shows
how to add a custom property to the configuration.
//---------------------------------------------------------------------------
// Preconditions: Open a part document.
//
// Postconditions:
// 1. Inspect the Immediate window.
// 2. A date custom property is added to the part's configuration.
// 3. The custom property is deleted from the configuration.
//---------------------------------------------------------------------------
using
SolidWorks.Interop.sldworks;
using
SolidWorks.Interop.swconst;
using
System.Runtime.InteropServices;
using
System;
using
System.Diagnostics;
namespace
GetCustProperties_CSharp.csproj
{
partial
class
SolidWorksMacro
{
ModelDoc2
swModel;
Configuration
config;
CustomPropertyManager
cusPropMgr;
int
lRetVal;
object[]
vPropNames;
object
vPropNamesObject;
object
vPropTypes;
object
vPropValues;
string
ValOut;
string
ResolvedValOut;
bool
wasResolved;
object
resolved;
int
nNbrProps;
int
j;
int
custPropType;
public
void
Main()
{
swModel = (ModelDoc2)swApp.ActiveDoc;
config = (Configuration)swModel.GetActiveConfiguration();
cusPropMgr = config.CustomPropertyManager;
lRetVal = cusPropMgr.Add3("ADATE",
swCustomInfoType_e.swCustomInfoDate, "4-13-59",
swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd);
lRetVal = cusPropMgr.Get5("ADATE",
false,
out
ValOut, out
ResolvedValOut, out
wasResolved);
lRetVal = cusPropMgr.Set2("ADATE",
"4-13-89");
// Get the number of custom
properties for this configuration
nNbrProps = cusPropMgr.Count;
Debug.Print("Number
of properties for this configuration: "
+ nNbrProps);
// Get the names of the
custom properties
vPropNames = (object[])cusPropMgr.GetNames();
// For each custom
property, print its type, value, and resolved value
for
(j = 0; j <= nNbrProps - 1; j++)
{
lRetVal = cusPropMgr.GetAll2(ref
vPropNamesObject, ref
vPropTypes, ref
vPropValues, ref
resolved);
custPropType = cusPropMgr.GetType2((string)vPropNames[j]);
Debug.Print(" Name,
swCustomInfoType_e value, and resolved value: "
+ vPropNames[j] + ", "
+ custPropType + ", "
+ ResolvedValOut);
}
lRetVal = cusPropMgr.Delete2("ADATE");
// Get the number of custom
properties for this configuration
nNbrProps = cusPropMgr.Count;
Debug.Print("Number
of properties for this configuration: "
+ nNbrProps);
}
public
SldWorks
swApp;
}
}