Hide Table of Contents

Auto Dimension Scheme Example (C#)

This example shows how to create a DimXpert Auto Dimension Scheme, turn tolerance status on and off,
and delete tolerances.

//---------------------------------------------------------------------------
//
// Preconditions:
// 1. Open:

//<SolidWorks_install_dir>\samples\tutorial\dimxpert\bracket_auto_plusminus.sldprt
// 2. (Optional) Multi-select three faces to specify primary, secondary,

//    and tertiary datum.
// 3. Modify the namespace of this macro to match your project name.
// 4. Open an Immediate Window in the IDE.
// 5. Ensure that the latest SolidWorks DimXpert interop assembly is referenced:
//    a. Right-click on the project in Project Explorer.
//    b. Select Add Reference.
//    c. Click the Browse tab.
//    d. Find and select <SolidWorks_install_dir>\api\redist\CLR2\swdimxpert.dll.
// 6. Set two breakpoints:
//    * swDXPart.ShowToleranceStatus = false;
//    * retval = swDXPart.DeleteAllTolerances();
// 7. Click F5.
// 8. Observe on the DimXpertManager tab: Hole Pattern1, Hole Pattern2, Fillet1,

//    Fillet Pattern1.
//    Also observe that tolerance status is turned on in the SolidWorks viewer.
// 9. Click F5.
//    Observe that tolerance status is turned off.
//10. Compare the output in the Immediate Window with the features displayed

//    on the DimXpertManager tab.
//11. Click F5.
//    Observe that all tolerance annotations have been removed from the part.

// Postconditions: none
// NOTE: Because this part is used in a SolidWorks online tutorial,
//       do not save any changes when you close it.
//--------------------------------------------------------------------------


using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using SolidWorks.Interop.swdimxpert;
using System;
using System.Diagnostics;
namespace AutoDimScheme_CSharp.csproj
{
    
partial class SolidWorksMacro
    {

        
ModelDoc2 swModel;
        
ModelDocExtension swModelDocExt;
        
SelectionMgr swSelMgr;
        
Feature swFeature;
        
DimXpertManager swSchema;
        
DimXpertPart swDXPart;
        
DimXpertAutoDimSchemeOption schemeOption;
        
swDimXpertFeatureType_e featureType;
        
object[] features;
        
object[] appliedFeatures;
        
object[] appliedAnnotations;
        
DimXpertAnnotation appliedAnnotation;
        
DimXpertFeature feature;
        
DimXpertFeature appliedFeature;
        
string msgStr;
        
string msgStr2;
        
string msgStr3;
        
string msgStr4;
        
int n;
        
int o;
        
int p;

        
public void Main()
        {

            swModel = (
ModelDoc2)swApp.ActiveDoc;
            swModelDocExt = swModel.Extension;
            swSelMgr = (
SelectionMgr)swModel.SelectionManager;

            
// Get the default DimXpert schema using IModelDocExtension.DimXpertManager()
            swSchema = swModelDocExt.get_DimXpertManager("Default", true);

            
// Get IDimXpertPart from the IDimXpertManager
            swDXPart = (DimXpertPart)swSchema.DimXpertPart;

            
// Set Auto Dimension Scheme using default options
            schemeOption = swDXPart.GetAutoDimSchemeOption();
            
Debug.Print("Default for ScopeAllFeature is: ");
            
Debug.Print(schemeOption.ScopeAllFeature.ToString());
            
Debug.Print("Default for FeatureFilters is: ");
            
Debug.Print(schemeOption.FeatureFilters.ToString());
            
Debug.Print("Default for PartType is: ");
            
Debug.Print(schemeOption.PartType.ToString());
            
Debug.Print("Default for PatternType is: ");
            
Debug.Print(schemeOption.PatternType.ToString());
            
Debug.Print("Default for PolarPatternHoleCount is: ");
            
Debug.Print(schemeOption.PolarPatternHoleCount.ToString());
            
Debug.Print("Default for ToleranceType is: ");
            
Debug.Print(schemeOption.ToleranceType.ToString());

            
bool retval = false;
            retval = swDXPart.AutoDimensionScheme(schemeOption);

            
// Turn tolerance status off
            swDXPart.ShowToleranceStatus = false;

            
long featCount = 0;
            featCount = swDXPart.GetFeatureCount();

            msgStr =
"Total of ";
            msgStr2 = featCount.ToString();
            msgStr = msgStr + msgStr2 +
" features in " + (swSchema.SchemaName);

            
Debug.Print("");
            
Debug.Print(msgStr);

            
// Get IDimXpert features through IDimXpertPart
            features = (object[])swDXPart.GetFeatures();
            msgStr = (swSchema.SchemaName) +
" has the following features: ";

            
Debug.Print("");
            
Debug.Print(msgStr);

            
for (n = 0; n <= features.GetUpperBound(0); n++)
            {
                
//Use IDimXpertFeature to get feature data
                feature = (DimXpertFeature)features[n];

                
Debug.Print(" " + "Feature name: " + (feature.Name));

                featureType = feature.Type;
                GetPatternType(
ref featureType, ref msgStr2);

                msgStr =
" Feature type ";
                msgStr3 =
" is suppressed on the DimXpertManager tab? ";
                msgStr4 = feature.IsSuppressed().ToString();

                
Debug.Print(msgStr + msgStr2 + msgStr3 + msgStr4);

                msgStr =
" " + "Swift model: ";

                
//Use IFeature to get the Swift model corresponding to this geometric dimensioning and tolerancing data
                swFeature = (Feature)feature.GetModelFeature();

                
if ((swFeature != null))
                {
                    msgStr2 = swFeature.GetTypeName2();
                    
Debug.Print(msgStr + msgStr2);
                }

                msgStr =
" " + "Number of SolidWorks face entities in this feature: ";
                msgStr2 = feature.GetFaceCount().ToString();

                
Debug.Print(msgStr + msgStr2);

                msgStr =
" " + "Number of applied features: ";
                msgStr2 = feature.GetAppliedFeatureCount().ToString();

                
Debug.Print(msgStr + msgStr2);

                appliedFeatures = (
object[])feature.GetAppliedFeatures();

                
if (!((appliedFeatures == null)))
                {
                    
for (o = 0; o <= appliedFeatures.GetUpperBound(0); o++)
                    {
                        appliedFeature = (
DimXpertFeature)appliedFeatures[o];
                        
Debug.Print(" " + "Applied feature name: " + (appliedFeature.Name));
                    }
                }

                msgStr =
" " + "Number of applied annotations: ";
                msgStr2 = feature.GetAppliedAnnotationCount().ToString();
                
Debug.Print(msgStr + msgStr2);

                appliedAnnotations = (
object[])feature.GetAppliedAnnotations();

                
if (!((appliedAnnotations == null)))
                {
                    
for (p = 0; p <= appliedAnnotations.GetUpperBound(0); p++)
                    {
                        appliedAnnotation = (
DimXpertAnnotation)appliedAnnotations[p];
                        
Debug.Print(" " + "Applied annotation name: " + (appliedAnnotation.Name));
                    }
                }
                
Debug.Print(" ");
            }

            
// Delete all tolerances
            retval = swDXPart.DeleteAllTolerances();
        }

        
public void GetPatternType(ref swDimXpertFeatureType_e featureType, ref String msgStr2)
        {
            
if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_Plane))
            {
                msgStr2 =
"Plane";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_Cylinder))
            {
                msgStr2 =
"Cylinder";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_Cone))
            {
                msgStr2 =
"Cone";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_Extrude))
            {
                msgStr2 =
"Extrude";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_Fillet))
            {
                msgStr2 =
"Fillet";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_Chamfer))
            {
                msgStr2 =
"Chamfer";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_CompoundHole))
            {
                msgStr2 =
"CompoundHole";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_CompoundWidth))
            {
                msgStr2 =
"CompoundWidth";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_CompoundNotch))
            {
                msgStr2 =
"CompoundNotch";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_CompoundClosedSlot3D))
            {
                msgStr2 =
"CompoundClosedSlot3D";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_IntersectPoint))
            {
                msgStr2 =
"IntersectPoint";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_IntersectLine))
            {
                msgStr2 =
"IntersectLine";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_IntersectCircle))
            {
                msgStr2 =
"IntersectCircle";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_IntersectPlane))
            {
                msgStr2 =
"IntersectPlane";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_Pattern))
            {
                msgStr2 =
"Pattern";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_Sphere))
            {
                msgStr2 =
"Sphere";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_BestfitPlane))
            {
                msgStr2 =
"Bestfit plane";
            }
            
else if ((featureType == swDimXpertFeatureType_e.swDimXpertFeature_Surface))
            {
                msgStr2 =
"Surface";
            }
        }

        
public SldWorks swApp;
    }
}



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Auto Dimension Scheme Example (C#)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2014 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.