Hide Table of Contents

Create Relative Drawing View Example (C#)

This example shows how to create a relative drawing view.

// ******************************************************************************
// Preconditions:
// 1. Open install_dir\samples\tutorial\api\maingrip.sldprt.
// 2. Select File > Make Drawing from Part.
// 3. Run the macro.
//
// Postconditions:
// 1. Iterates through the drawing views
//    in the View Palette and drops
//    *Current drawing view in the drawing.
// 2. Activates the part.
// 3. Selects two faces for the relative drawing view.
// 4. Activates the drawing.
// 5. Creates and inserts a relative drawing
//    view using the selected faces.
//
// NOTE: Because the part document is used elsewhere, do not
// save any changes when closing it.
// ******************************************************************************
 
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
 
namespace CreateRelativeViewCSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        ModelDoc2 swModel;
        DrawingDoc swDrawing;
        View swView;
        ModelDocExtension swModelDocExt;
        string fileName;
        bool status;
        int errors;
        int warnings;
        int numViews;
        object[] viewNames;
        string viewName;
        string viewPaletteName;
        int i;
 
 
        public void Main()
        {
            swDrawing = (DrawingDoc)swApp.ActiveDoc;
 
            // Get number of views on View Palette
            numViews = 0;
            viewNames = (object[])swDrawing.GetDrawingPaletteViewNames();
 
            // Iterate through views on View Palette
            // When view name equals *Current, drop
            // that view in drawing
            if (!((viewNames == null)))
            {
                numViews = (viewNames.GetUpperBound(0) - viewNames.GetLowerBound(0));
                for (i = 0; i <= numViews; i++)
                {
                    viewPaletteName = (string)viewNames[i];
                    if ((viewPaletteName == "*Current"))
                    {
                        swView = (View)swDrawing.DropDrawingViewFromPalette2(viewPaletteName, 0.0, 0.0, 0.0);
                    }
                }
            }
 
            // Activate the part document and
            // select two faces for the relative drawing view
            swApp.ActivateDoc3("maingrip.sldprt"false, (int)swRebuildOnActivation_e.swUserDecision, ref errors);
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swModelDocExt = (ModelDocExtension)swModel.Extension;
            swModel.ClearSelection2(true);
            status = swModelDocExt.SelectByID2("""FACE", 0.0466263268498324, 0.00558799999987514, -0.00617351393179888, false, 1, null, 0);
            status = swModelDocExt.SelectByID2("""FACE", 0.0504738910727269, 0.00167315253537481, -0.00496149996774875, true, 2, null, 0);
 
            // Activate the drawing document
            // Create and insert the relative drawing view using
            // the selected faces
            // Activate the relative drawing view
            swApp.ActivateDoc3("maingrip - Sheet1"false, (int)swRebuildOnActivation_e.swUserDecision, ref errors);
            swDrawing = (DrawingDoc)swApp.ActiveDoc;
            fileName = "C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\samples\\tutorial\\api\\maingrip.sldprt";
            swView = (View)swDrawing.CreateRelativeView(fileName, 0.203608914116486, 0.493530187561698, (int)swRelativeViewCreationDirection_e.swRelativeViewCreationDirection_FRONT, (int)swRelativeViewCreationDirection_e.swRelativeViewCreationDirection_RIGHT);
            status = swDrawing.ActivateView("Drawing View2");
 
        }
 
        /// <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:   Create Relative Drawing View 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) 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.