Hide Table of Contents

Isolate Changed Dimension (C#)

This example shows how to isolate a changed dimension.

//------------------------------------------------------
// Preconditions: The specified drawing and part
// documents exist.
//
// Postconditions:
// 1. Opens the drawing document.
// 2. Sets the system option to display
//    changed dimensions in the color selected
//    for Tools > Options > System Options >
//    Colors > Color scheme settings >
//    Drawings, Changed dimensions.
// 3. Saves and closes the drawing document.
// 4. Opens the part document of the drawing document.
// 5. Changes a dimension.
// 6. Saves and closes the part document.
// 7. Opens the previously saved drawing document.
// 8. Examine the drawing document to verify that
//    the changed dimension is displayed in the
//    
changed-dimension color. Place your cursor over
//    
the dimension to see its previous value.
//-------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;

namespace IsolateChangedDimensionsDrawingDocCSharp.csproj
{
    
partial class SolidWorksMacro
    {
        
public void Main()
        {
            ModelDoc2 swModel =
default(ModelDoc2);
            ModelDocExtension swModelDocExt =
default(ModelDocExtension);
            DrawingDoc swDrawing =
default(DrawingDoc);
            
string fileName = null;
            
string saveFileName = null;
            
int errors = 0;
            
int warnings = 0;
            
bool status = false;

            
// Open drawing document
            fileName = "install_dir\\samples\\tutorial\\api\\box.slddrw";
            swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (
int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);

            
// Isolate changed dimensions
            // Equivalent to selecting Tools > Options > System Options > Colors >
            // Use specified color for changed drawing dimensions on open
            swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swUseChangedDimensions, true);
            swDrawing = (DrawingDoc)swModel;
            swDrawing.IsolateChangedDimensions();

            
// Save drawing document to another name
            saveFileName = "install_dir\\samples\\tutorial\\api\\box_changed.slddrw";
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            status = swModelDocExt.SaveAs(saveFileName, (
int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
            swApp.CloseDoc(saveFileName);

            
// Open the part document referenced by the drawing document,
            // change a dimension, and save the document
            fileName = "install_dir\\samples\\tutorial\\api\\box.sldprt";
            swModel = (ModelDoc2)swApp.OpenDoc6(fileName, (
int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            status = swModelDocExt.SelectByID2(
"Sketch1", "SKETCH", 0, 0, 0, true, 0, null, 0);
            status = swModelDocExt.SelectByID2(
"D2@Sketch1@box.SLDPRT", "DIMENSION", -0.03613329319351, -0.02215939491444, 0.02938582119709, true, 0, null, 0);
            Dimension swDimension =
default(Dimension);
            swDimension = (Dimension)swModel.Parameter(
"D2@Sketch1");
            swDimension.SystemValue = 0.185;
            swModel.ClearSelection2(
true);
            status = swModel.EditRebuild3();
            status = swModel.Save3((
int)swSaveAsOptions_e.swSaveAsOptions_Silent, ref errors, ref warnings);
            swApp.CloseDoc(fileName);

            
// Open the previously saved drawing document
            // and place your cursor on the changed dimension,
            // which displays in the color specified for
            // changed dimensions, to see its previous value
            swModel = (ModelDoc2)swApp.OpenDoc6(saveFileName, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
        }


        
/// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>

        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:   Isolate Changed Dimension (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) 2015 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.