Automatic update of the browser, for example with the name of the Windows session. (Environ("USERNAME"))
Automatic creation of a configuration-specific parameter of the name 'Product Code'
And 3rd thing, in some cases where we take an existing part as an existing base, I would like to replace the date in the cartouche that caller on the parameter of the date of creation of the file, by the current date.
As for the current date, I put as a property link to the annotation "SW-Date Courte(ShortDate)" i.e. the current date when you open it. But there is also a long date etc...
You have to edit the latter, add a note that will be in the place of the author's name in the title block, apply a property to this note. Create a property for the file, assign a name to this property, in the following example it is "Session", put type "text" and set the value $PRP: "Last saved by", click on ok.
In the Link to Property list, just take the Session property and the note will change to the name of the PC user.
I set up a custom properties form, the date is selected in a small calendar very practical, the names of the desinnators / verifiers / approver are selected in drop-down lists, all up to the C index to be able to quickly evolve old plans. The rest is completed automatically, plan names = file names, ....
This method allows you to quickly complete all the cartridges of all the sheets in the same way, and so to have different sheets I had to make a 3D cartridge and you have to juggle with the layers to hide some custom properties. But we don't need to work on multiple folios in-house, so this method is really handy, as we regularly edit old plans.
Automatic update of the browser, for example with the name of the Windows session. (Environ("USERNAME")). - The 'last user' version is good but doesn't suit me. - I would like to be able to update the field in 1 click
Automatic creation of a configuration-specific parameter of the name 'Product Code' especially if I use historical pieces.
For the update of the date, the 'print date' setting is not bad but does not work historically. A.Leblanc : If you have an example that I could adapt, it would be cool.
Hello Like a.leblanc, I set up a custom properties form in the form of an external program called via a macro, this form can also be the macro directly depending on the complexity of it. This form allows you to create all the custom properties on a new 3D but also to retrieve all those of the existing 3D and modify them if necessary. I created several custom properties (about thirty in my case) and in particular the author, the creator of the revision (he is not necessarily the initial author), the creation date, the revision date, the revision designation, the designation, etc... I also get the material, the file name (identical to the article code in my case), the mass, etc... and of course I fill my 2D cartridge with these properties. The Author and ReviewCreator properties are of course equal to the UserName of the PC, the creation and revision dates are those of the day (only if empty at the time of loading the macro for the creation date) and editable via a small calendar (for history management or part copies). To manage custom properties by API you have to go to http://help.solidworks.com/2016/English/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IConfiguration~CustomPropertyManager.html , everything else is just programming and testing depending on what you want to do.
To follow up on my previous post, here are 3 examples of functions (in C#) to create, retrieve and delete custom properties, be careful these are only examples with links on textBoxes from a UserForm:
// Exemple de fonction pour créer les propriétés personnalisées
private void CreerProprietes()
{
try
{
ModelDoc2 swModel = null;
swModel = ((ModelDoc2)(Program.swapp.ActiveDoc));
CustomPropertyManager PropMgr = null;
CustomPropertyManager PropMgr0 = null;
ConfigurationManager swConfigMgr;
Configuration swConfig;
swConfigMgr = swModel.ConfigurationManager;
swConfig = swConfigMgr.ActiveConfiguration;
int nb = 3;
string[] PropName = new string[nb];
string[] PropVal = new string[nb];
int i = 0;
PropName[i] = CodeArticle;
PropVal[i] = textBox1.Text.Trim();
i++;
PropName[i] = CreateDate;
if (textBox9.Text == "")
{
PropVal[i] = System.DateTime.Today.ToShortDateString();
}
else
{
PropVal[i] = textBox9.Text.Trim();
}
i++;
PropName[i] = Dessinateur;
if (textBox19.Text == "")
{
PropVal[i] = System.Environment.UserName.ToUpperInvariant();
}
else
{
PropVal[i] = textBox19.Text;
}
i++;
PropMgr0 = swModel.Extension.get_CustomPropertyManager("");
int value = 0;
for (int m = 0; m <= (nb - 1); m++)
{
value = PropMgr0.Add2(PropName[m], (int)swCustomInfoType_e.swCustomInfoText, PropVal[m]);
}
}
catch (Exception)
{
MessageBox.Show("Erreur lors de la création des propriétés personnalisées, Contactez l'administrateur.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
// Exemple de fonction pour récupérer les propriétés personnalisées
private void ObtenirProprietes()
{
try
{
ModelDoc2 swModel = null;
swModel = ((ModelDoc2)(Program.swapp.ActiveDoc));
CustomPropertyManager PropMgr = null;
ConfigurationManager swConfigMgr;
Configuration swConfig;
swConfigMgr = swModel.ConfigurationManager;
swConfig = swConfigMgr.ActiveConfiguration;
int nNbrProps;
int j;
object[] vPropNames;
string valOut;
string resolvedValOut;
int custPropType;
PropMgr = swConfig.CustomPropertyManager;
nNbrProps = PropMgr.Count;
vPropNames = (object[])PropMgr.GetNames();
for (j = 0; j <= nNbrProps - 1; j++)
{
PropMgr.Get2(vPropNames[j].ToString(), out valOut, out resolvedValOut);
custPropType = PropMgr.GetType2(vPropNames[j].ToString());
if (vPropNames[j].ToString() == CodeArticle)
{
textBox1.Text = resolvedValOut.ToString();
}
if (vPropNames[j].ToString() == CreateDate)
{
textBox9.Text = resolvedValOut.ToString();
}
if (vPropNames[j].ToString() == Dessinateur)
{
textBox19.Text = resolvedValOut.ToString();
}
}
}
catch (Exception)
{
MessageBox.Show("Erreur lors de l'obtention des propriétés personnalisées, Contactez l'administrateur.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
// Exemple de fonction pour effacer toutes les propriétés personnalisées
private void EffacerProprietes()
{
try
{
ModelDoc2 swModel;
swModel = ((ModelDoc2)(Program.swapp.ActiveDoc));
CustomPropertyManager PropMgr;
ConfigurationManager swConfigMgr;
Configuration swConfig;
swConfigMgr = swModel.ConfigurationManager;
swConfig = swConfigMgr.ActiveConfiguration;
PropMgr = swConfig.CustomPropertyManager;
int nNbrProps;
object[] vPropNames;
nNbrProps = PropMgr.Count;
vPropNames = (object[])PropMgr.GetNames();
int h;
for (h = 0; h <= nNbrProps - 1; h++)
{
object[] configNameArr = null;
string configName = null;
int j = 0;
configNameArr = (object[])swModel.GetConfigurationNames();
for (j = 0; j <= configNameArr.GetUpperBound(0); j++)
{
configName = (string)configNameArr[j];
swConfig = (Configuration)swModel.GetConfigurationByName(configName);
PropMgr = swModel.Extension.get_CustomPropertyManager(configName);
PropMgr.Delete(vPropNames[h].ToString());
}
PropMgr = swModel.Extension.get_CustomPropertyManager("");
PropMgr.Delete(vPropNames[h].ToString());
}
return;
}
catch (Exception)
{
MessageBox.Show("Erreur lors de l'effacement des propriétés personnalisées, Contactez l'administrateur.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
SmartPropeties could be the beginning of a solution. You will also be able to manage the properties according to the configuration of your part/assembly as you requested.