Hello,
I am currently working on a macro which updates an bill of material in a drawing according to the config used and sorts the lines.
Now I'm still looking for the appropriate command, which gives me the columns on the automatic max. Column width sets, but I can not find a matching snippet.
So according to the double-click on the dividing line of two columns.
Currently I can set a fixed (40 mm) column width with this code:
Dim swBomFeat As SldWorks.BomFeature
Dim vTables As Variant
Dim swBomTable As SldWorks.BomTableAnnotation
Dim boolstatus As Boolean
swBomFeat.SetConfigurations False, vConfVis, vConfNames
vTables = swBomFeat.GetTableAnnotations
Set swBomTable = vTables(0)
boolstatus = swBomTable.SetColumnWidth(-2, 0.04, 0)
For Excel I know the corresponding function.
xlWs.UsedRange.EntireColumn.AutoFit
Does anyone have an idea, if this works at all by macro?
Greetings, Andi
SolidworksApi macros
Hello Andi,
the "AutoFit" function in the API should not be a problem for SolidWorks, in the user interface, it already works by mouse click.
SolidWorks may implement the function sometime...
I have attached an example macro to you.
Hope it helps you.
Many greetings
Dimitrie
Helo guys!
I have one solution, but in C#!
I use the MeasureString than Graphics.FromImage!
See the below code
using System.Drawing;
String biggestText = "biggest text in rows the column";
intColumnIndex = 1;
SizeF result;
using (var image = new Bitmap(1, 1))
{
using (var g = Graphics.FromImage(image))
{
g.PageScale = 1;
g.PageUnit = GraphicsUnit.Millimeter;
result = g.MeasureString(biggestText , new Font("Arial", 11, FontStyle.Regular));
}
}
double calc = result.Width;
table.SetColumnWidth(ColumnIndex, calc/1000, (int)swTableRowColSizeChangeBehavior_e.swTableRowColChange_TableSizeCanChange);
Waring, you need change the solidWorks table option as per below image.
Hello Fernado,
Thank you for your example, which I can not use because I do not program in C #.
In the meantime I have written an extensive macro in which this problem was solved satisfactorily with an approximation. Unfortunately I can not publish this macro here.
I have not found a suitable macro command yet.
This topic was further discussed in the German forum.
If you are interested, here it is.
http://ww3.cad.de/foren/ubb/Forum2/HTML/031311.shtml
Greetings, Andi