Link Configuration Specific Properties in General Table

Hi Everyone,

Hope everyone in the community is doing well

I need some help been struggling to find a solution on Linking Specific Properties from multiple configurations.

My company still uses Excel based tables in the drawing templates.

So been trying to write a Script that will get Part Numbers & Description from parts or assemblies with multiple configurations.

Our current table you have to manual type in the part numbers. The Excel table is linked to our DBWorks Vault.

So when you type the part number the description automatically fill.

This method is horrible, slow & sometimes the Excel Table get corrupted & corrupts the entire drawing file.

Its painful to use this table when you have 10+ configurations you have to fill in.

So I figure write a script that will generate a SolidWorks General Table with all the configurations.

The process I wrote is:

-Select a detail view (Part or Assembly)

-Runs the macro that runs my C# Script

-The script will then get each Part number & Description from the selected Drawing View

-Then fill in the table with all the information.

-Then it will re arrange it.

Done

When I got this to work I was so happy. But where I'm stuck is trying to link the custom properties.

So when I go back to the part or assembly & do any changes. Then come back to the drawings the Part Number or Description dose not update.

My script only gets the information. Using .Get6

Im trying to find other ways on how to link the Custom Properties.

Been experimenting with Syntax from SolidWorks. But I don't fully understand how its working.

I can see the Link To Property works perfect.

Variable Link shows:

\$PRPSMODEL:"PART_NUMBER" \$COMP:"298810_Link_Properties-2@Drawing View1"

From what I under stand of this variable.

\$PRPSMODEL:"PART_NUMBER" <---Model Custom Property "PART_NUMBER"

\$COMP:"298810_Link_Properties-2 <---Assembly File Name

@Drawing View1 <--- The active configuration

If anyone has suggestions please feel free. I'm still digging trying to find whats the best solution

Another quick fix I was thinking of was just delete the table & insert a new one if I do any changes.

But dose not seem ideal.

Trying to automate everything as much as possible & trying to reduce errors.

Thank You

I attached a quick RX clip generating the table.

Here is the C# Script

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System.Diagnostics;

namespace InsertPartsTable

{

class Program

{

static void Main(string[] args)

{

//Console.SetWindowSize(25, 2);

//Console.WriteLine("Inserting Parts Table");

ModelDoc2 swModel = default(ModelDoc2);

ModelDoc2 swViewModel = default(ModelDoc2);

DrawingDoc swDrawing = default(DrawingDoc);

SelectionMgr swSelMgr = default(SelectionMgr);

FeatureManager swFeatMgr = default(FeatureManager);

View swView = default(View);

TableAnnotation swTable = default(TableAnnotation);

ConfigurationManager swConfigMgr;

TableAnnotation swTableAnnotation = default(TableAnnotation);

Configuration swConfig;

CustomPropertyManager swCustPropMgr;

string ResolvedOutPartNumber;

string ResolvedOutTitle;

string ResolvedOutWeight;

string ValOut;

bool wasResolved;

bool boolstatus;

bool UseCached = false;

bool LinkToProperty;

int value;

//bool Value2 = true;

// string FieldValue = null;

//string FieldName = "PART_NUMBER";

string[] ConfigNames = null;

int ConfigCount;

int i;

// General Table Option Settings //

int AnchorType = 4;

string TableTemplate;

// Gets Active SolidWorks Appplication //

SldWorks swApp = (SldWorks)System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application");

//Check for any other Solidworks App running in the background"//

swModel = (ModelDoc2)swApp.ActiveDoc;

if (swModel == null)

{

swApp.SendMsgToUser2("More than one SolidWorks application running" + "\n" + "Close extra Soldiworks Application", (int)swMessageBoxIcon_e.swMbWarning, (int)swMessageBoxBtn_e.swMbOk);

return;

}

// Check for Active Drawing Document Open before running Macro //

if (swModel.GetType() != (int)swDocumentTypes_e.swDocDRAWING)

{

swApp.SendMsgToUser2("Drawing document must be open", (int)swMessageBoxIcon_e.swMbWarning, (int)swMessageBoxBtn_e.swMbOk);

return;

}

swSelMgr = (SelectionMgr)swModel.SelectionManager;

swFeatMgr = (FeatureManager)swModel.FeatureManager;

// Get selected drawing view //

swView = (View)swSelMgr.GetSelectedObject6(1, 0);

if (swView == null)

{

swApp.SendMsgToUser2("Select View to Insert Parts Table", (int)swMessageBoxIcon_e.swMbWarning, (int)swMessageBoxBtn_e.swMbOk);

return;

}

// Configuration Matching Drawing View & Model Configuration //

swViewModel = swView.ReferencedDocument;

swConfigMgr = swViewModel.ConfigurationManager;

boolstatus = swViewModel.ShowConfiguration2(swView.ReferencedConfiguration);

ConfigNames = swViewModel.GetConfigurationNames();

ConfigCount = swViewModel.GetConfigurationCount();

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Delete General Table //

// Insert Table Annotation //

TableTemplate = @"C:\Users\User\Desktop\Parts_Table.sldtbt";

swDrawing = (DrawingDoc)swModel;

swTableAnnotation = swDrawing.InsertTableAnnotation2(true, 0, 0, AnchorType, TableTemplate, ConfigCount, 0);

if ((swTableAnnotation != null))

{

swTableAnnotation.BorderLineWeight = 0;

swTableAnnotation.GridLineWeight = 0;

}

swTable = (TableAnnotation)swTableAnnotation;

Console.WriteLine(ConfigCount);

// Loops though each Configuration Name & gets Part / Assembly Custom Properties Values

for (i = 0; i <= ConfigCount - 1; i++)

{

swConfig = swViewModel.GetConfigurationByName(ConfigNames[i]);

swCustPropMgr = swConfig.CustomPropertyManager;

value = swCustPropMgr.Get6("PART_NUMBER", UseCached, out ValOut, out ResolvedOutPartNumber, out wasResolved, out LinkToProperty);

value = swCustPropMgr.Get6("TITLE", UseCached, out ValOut, out ResolvedOutTitle, out wasResolved, out LinkToProperty);

value = swCustPropMgr.Get6("WEIGHT", UseCached, out ValOut, out ResolvedOutWeight, out wasResolved, out LinkToProperty);

Console.WriteLine("Configuration Name" + " : " + ConfigNames[i] + " : PN: " + ResolvedOutPartNumber + " DESCRIPTION: " + ResolvedOutTitle + ResolvedOutWeight);

swTable.Text[i, 1] = ResolvedOutPartNumber;

swTable.Text[i, 2] = ResolvedOutTitle;

swTable.Text[i, 3] = ResolvedOutWeight + "lbs";

}

// Sorts Part number Column in Table //

GeneralTableAnnotation swSpecTable = (GeneralTableAnnotation)swTable;

swSpecTable.Sort(1, false);

// Clears Any Selections //

swModel.ClearSelection2(true);

// Update FeatureManager design tree //

swFeatMgr.UpdateFeatureTree();

}

}

}

SolidworksApi/macros