Please help,
I'm trying to read all dimensions on a drawing for solving problems. For that, I want to use a macro/api. I looked for how to solve my problem and found severals references:
- Macro to read a basic dimension | MySolidWorks
-2015 SOLIDWORKS API Help - Get Dimension Tolerance Example (VB.NET)
-2019 SOLIDWORKS API Help - Get Dimension Values in Drawing Example (VBA)
I don't have problem selecting all dimension, but I can't read it correctly. In next picture, I show you my problem:
As you can see, I can't read the tolerance. For mare help, the tolerance was defining in the part of de drawing.
The code I used, is the folow:
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 SolidWorks.Interop.swdocumentmgr;
namespace ReadDrawing
{
class Program
{
static void Main(string[] args)
{
//read a path of drawing
string Ruta = Console.ReadLine();
SldWorks swApp = new SldWorks();
ModelDoc2 swMod;
DrawingDoc swDraw;
View swView;
DisplayDimension swDispDim;
Dimension swDim;
Annotation swAnn;
DimensionTolerance swTol;
int Error=0;
int Warning=0;
swApp.OpenDoc6(Ruta, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_LoadModel, "", ref Error, ref Warning);
swMod=(ModelDoc2)swApp.ActivateDoc3(Ruta, false, (int)swRebuildOnActivation_e.swUserDecision,ref Error);
swDraw = (DrawingDoc)swMod;
swView = swDraw.GetFirstView();
while (swView != null)
{
Console.WriteLine("********************************************************************************");
Console.WriteLine("View=" + swView.Name);
swDispDim = swView.GetFirstDisplayDimension5();
while (swDispDim != null)
{
swAnn = swDispDim.GetAnnotation();
swDim = swDispDim.GetDimension2(0);
swMod.Extension.SelectByID2(swDim.FullName, "DIMENSION", 0, 0, 0, false, 0, null, 0);
swTol = swDim.Tolerance;
Console.WriteLine("------------------------------------------------------");
Console.WriteLine(" AnnName =" + swAnn.GetName());
Console.WriteLine(" DimFullName =" + swDim.FullName);
Console.WriteLine(" DimName =" + swDim.Name);
Console.WriteLine(" swDimensionParamType_e =" + ((swDimensionType_e)swDim.GetType()).ToString());
Console.WriteLine(" DrivenState =" + swDim.DrivenState.ToString());
Console.WriteLine(" Value =" + swDim.Value.ToString());
Console.WriteLine();
Console.WriteLine(" Arrowside =" + swDispDim.ArrowSide);
Console.WriteLine(" TextAll =" + swDispDim.GetText((int)swDimensionTextParts_e.swDimensionTextAll));
Console.WriteLine(" TextPrefix =" + swDispDim.GetText((int)swDimensionTextParts_e.swDimensionTextPrefix));
Console.WriteLine(" TextSuffix =" + swDispDim.GetText((int)swDimensionTextParts_e.swDimensionTextSuffix));
Console.WriteLine(" CalloutAbove =" + swDispDim.GetText((int)swDimensionTextParts_e.swDimensionTextCalloutAbove));
Console.WriteLine(" CalloutBelow =" + swDispDim.GetText((int)swDimensionTextParts_e.swDimensionTextCalloutBelow));
Console.WriteLine();
double MaxTol;
double MinTol;
var MaxValueValid = swTol.GetMaxValue2(out MaxTol);
var MinValueValid = swTol.GetMinValue2(out MinTol);
Console.WriteLine(" Hole =" + swTol.GetHoleFitValue());
Console.WriteLine(" Shaft =" + swTol.GetShaftFitValue());
Console.WriteLine(" MaxTol =" + MaxTol.ToString());
Console.WriteLine(" MinTol =" + MinTol.ToString());
swDispDim = swDispDim.GetNext3();
}
swView = swView.GetNextView();
}
}
}
}
Thanks in advance,
Alejandro
SolidworksApi/macros