Insert ViewTiles in Model Example (C#)

This example shows how to:

//--------------------------------------------------------------
// Preconditions:
// 1. Create a C# console project in Microsoft Visual Studio 2012.
// 2. Copy and paste this example into the C# IDE.
// 3. Add a reference to:
//    install_dir\APISDK\tlb\DraftSight.Interop.dsAutomation.dll.
// 4. Add References to System and System.Windows.Forms.
// 5. Start DraftSight.
// 6. Ensure that the file specified to open exits.
// 7. Press F11 to step into the code.
// 8. Press F10 repeatedly to step through the code. Observe 
//    the changes in the model document and ViewTiles while
//    stepping through the code.
//
// Postconditions:
// 1. Opens the specified file.
// 2. Inserts four ViewTiles.
// 3. Iterates through the four ViewTiles. For each ViewTile:
//    a. Turns off displaying the coordinate system at the
//       the origin.
//    b. Specifies to display the coordinate system at the origin.
//    c. Turns on displaying the coordinate system at the
//       origin.
// 4. Close the model document without saving any changes.
//----------------------------------------------------------------
using System;
using DraftSight.Interop.dsAutomation;
using System.Runtime.InteropServices;
using System.Windows.Forms;
 
static class Module1
{
        public static void Main()
        {
            DraftSight.Interop.dsAutomation.Application dsApp;
		    Document dsDoc = null;
		    Model dsModel = null;

		    //Connect to DraftSight
		    dsApp = (DraftSight.Interop.dsAutomation.Application)Marshal.GetActiveObject("DraftSight.Application");

		    //Abort any command currently running 
		    //in DraftSight to avoid nested commands
		    dsApp.AbortRunningCommand();

		    //Open document
		    string docName = "C:\\ProgramData\\Dassault Systemes\\DraftSight\\Examples\\A-54643.DWG";
		    dsDoc = dsApp.OpenDocument2(docName, dsDocumentOpenOption_e.dsDocumentOpen_Default, dsEncoding_e.dsEncoding_Default);

		    //Get active document
		    dsDoc = dsApp.GetActiveDocument();
		    if ((dsDoc != null)) {
			    //Get model space
			    dsModel = dsDoc.GetModel();
		    } else {
			    MessageBox.Show("There are no open documents in DraftSight.");
			    return;
		    }

		    //Insert ViewTiles
		    object[] viewTiles = new object[4];
		    long index = 0;
		    ViewTile dsViewTile = default(ViewTile);
		    viewTiles = (object[])dsModel.InsertViewTiles(dsViewTilesMode_e.dsViewTilesMode_4_Left, dsViewTilesApplyTo_e.dsViewTilesApplyTo_ActiveViewTile);
		    if (viewTiles != null) {
			    for (index = viewTiles.GetLowerBound(0); index <= viewTiles.GetUpperBound(0); index++) {
				    dsViewTile = (ViewTile)viewTiles[index];
				    //Turn off displaying coordinate system icon at origin
				    dsViewTile.CSIconIsOn = false;
				    if (!(dsViewTile.CSIconIsOn)) {
					    //Display coordinate system at origin 
					    dsViewTile.CSIconAtOrigin = true;
					    //Turn on displaying coordinate system icon at origin
					    dsViewTile.CSIconIsOn = true;
				    }
			    }
                      }
        }
}