Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
<html>
<head>
<title>Switch Layouts Example (C#)</title>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel="stylesheet" type="text/css" href="ApiHelp.css">
<meta name=MS-HKWD content="C# examples">
<meta name=MS-HKWD content="C# examples,Sheets">
<meta name=MS-HKWD content="C# examples,layouts">
<meta name=MS-HKWD content="C# examples,models">
</head>
<body>
<h1>Switch Layouts Example (C#)</h1>
<p>This example shows how to switch layouts.</p>
<pre>//--------------------------------------------------------------
//Preconditions:
// 1. Create a C# Windows console project.
// 2. Copy and paste this example into the C# IDE.
// 3. Add a reference to:
// <i>install_dir</i>\<b>APISDK\tlb\DraftSight.Interop.dsAutomation.dll</b>.
// 4. Add references to <b>System </b>and<b> System.Windows.Forms</b>.
// 5. Start DraftSight and open a document.
// 6. Start debugging the project.
//
//Postconditions: Message boxes pop up when a model or sheet
//is activated. Read the text in each message box before clicking
//OK to close it.
//----------------------------------------------------------------
using DraftSight.Interop.dsAutomation;
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;</pre>
<pre>static class Module1
{
</pre>
<pre> public static void Main()
{</pre>
<pre> DraftSight.Interop.dsAutomation.Application dsApp;
Document dsDoc = default(Document);</pre>
<pre> //Connect to DraftSight</pre>
<blockquote>
<blockquote>
<pre> dsApp = (DraftSight.Interop.dsAutomation.Application)Marshal.GetActiveObject("DraftSight.Application");
dsApp.<b>AbortRunningCommand</b>(); // abort any command currently running in DraftSight to avoid nested commands</pre>
</blockquote>
</blockquote>
<pre> //Get active document
dsDoc = dsApp.GetActiveDocument();</pre>
<pre> if (dsDoc != null)
{
//Activate each layout, one by one
SwitchLayouts(dsDoc);</pre>
<pre> }
else
{
MessageBox.Show("There are no open documents in DraftSight.");
}
}
public static void SwitchLayouts(Document dsDoc)
{
Sheet dsSheet = default(Sheet);
Model dsModel = default(Model);
object[] dsVarSheets = null;
int index = 0;
string sheetName = null;</pre>
<pre> //Get all sheets
dsVarSheets = (object[])dsDoc.GetSheets();
</pre>
<pre> if (dsVarSheets != null)
{</pre>
<pre> for (index = dsVarSheets.GetLowerBound(0); index <= dsVarSheets.GetUpperBound(0); index++)
{
dsSheet = (Sheet)dsVarSheets[index];</pre>
<pre> //Get sheet name
sheetName = dsSheet.Name;</pre>
<pre> //Change sheet name, if it is not a model</pre>
<pre> if (sheetName != "Model")
{
//Activate sheet
dsSheet.Activate();</pre>
<pre> //Verify if the sheet was activated
if (dsSheet.IsActive())
{
MessageBox.Show("The sheet " + sheetName + " was activated.");
}
</pre>
<pre> }
else
{
//Activate model sheet
dsModel = (Model)dsDoc.GetModel();
</pre>
<pre> if (dsModel != null)
{
//Activate model sheet
dsModel.Activate();</pre>
<pre> //Verify if the sheet was activated
if (dsModel.IsActive())
{
MessageBox.Show("The model sheet was activated.");
}</pre>
<pre> }</pre>
<pre> }</pre>
<pre> }</pre>
<pre> }
</pre>
<pre> }
</pre>
<pre>}
</pre>
<p> </p>
</body>
</html>