Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
<html>
<head>
<title>Activate Sheets Example (VB.NET)</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="VB.NET examples">
<meta name=MS-HKWD content="VB.NET examples,Sheets">
</head>
<body>
<h1>Activate Sheets Example (VB.NET)</h1>
<p>This example shows how to activate each Sheet in a drawing.</p>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white"><span style="color: green">'--------------------------------------------------------------</span>
<span style="color: green">'Preconditions:</span>
<span style="color: green">' 1. Create a VB.NET Windows console project.</span>
<span style="color: green">' 2. Copy and paste this example into the VB.NET IDE.</span>
<span style="color: green">' 3. Add a reference to:</span>
<span style="color: green">' <i>install_dir</i><b>\APISDK\tlb\DraftSight.Interop.dsAutomation.dll</b>.</span>
<span style="color: green">' 4. Start DraftSight and open a document with multiple Sheets.</span>
<span style="color: green">' 5. Start debugging the project.</span>
<span style="color: green">'</span>
<span style="color: green">'Postconditions: </span>
<span style="color: green">' 1. Pops up a message box when a Sheet is activated. </span>
<span style="color: green">' 2. Click <b>OK</b> to close each message box.</span>
<span style="color: green">'----------------------------------------------------------------</span>
<span style="color: blue">Imports</span> DraftSight.Interop.dsAutomation
<span style="color: blue">Module</span> <span style="color: #2b91af">Module1</span>
<span style="color: blue">Sub</span> Main()
<span style="color: blue">Dim</span> dsApp <span style="color: blue">As</span> <span style="color: #2b91af">Application</span>
<span style="color: blue">Dim</span> dsDoc <span style="color: blue">As</span> <span style="color: #2b91af">Document</span>
<span style="color: green">'Connect to DraftSight</span>
dsApp = GetObject(, <span style="color: #a31515">"DraftSight.Application"</span>)
<span style="color: green">'Abort any command currently running in
'DraftSight to avoid nested commands</span>
dsApp.<b>AbortRunningCommand</b>()
<span style="color: green">'Get active document</span>
dsDoc = dsApp.<b>GetActiveDocument</b>()
<span style="color: blue">If</span> <span style="color: blue">Not</span> dsDoc <span style="color: blue">Is</span> <span style="color: blue">Nothing</span> <span style="color: blue">Then</span>
<span style="color: green">'Activate each Sheet, one by one</span>
SwitchSheets(dsDoc)
<span style="color: blue">Else</span>
MsgBox(<span style="color: #a31515">"There are no open documents in DraftSight."</span>)
<span style="color: blue">End</span> <span style="color: blue">If</span>
<span style="color: blue">End</span> <span style="color: blue">Sub</span>
<span style="color: blue">Sub</span> SwitchSheets(<span style="color: blue">ByVal</span> dsDoc <span style="color: blue">As</span> <span style="color: #2b91af">Document</span>)
<span style="color: blue">Dim</span> dsSheet <span style="color: blue">As</span> <span style="color: #2b91af">Sheet</span>
<span style="color: blue">Dim</span> dsVarSheets <span style="color: blue">As</span> <span style="color: blue">Object</span>
<span style="color: blue">Dim</span> index <span style="color: blue">As</span> <span style="color: blue">Integer</span>
<span style="color: blue">Dim</span> sheetName <span style="color: blue">As</span> <span style="color: blue">String</span>
<span style="color: green">'Get all Sheets</span>
dsVarSheets = dsDoc.<b>GetSheets2</b>
<span style="color: blue">If</span> IsArray(dsVarSheets) <span style="color: blue">Then</span>
<span style="color: blue">For</span> index = LBound(dsVarSheets) <span style="color: blue">To</span> UBound(dsVarSheets)
dsSheet = dsVarSheets(index)
<span style="color: green">'Get Sheet name</span>
sheetName = dsSheet.<b>Name</b>
<span style="color: green">'Activate Sheet</span>
dsSheet.<b>Activate</b>()
<span style="color: green">'Verify if the Sheet was activated</span>
<span style="color: blue">If</span> dsSheet.<b>IsActive</b> <span style="color: blue">Then</span>
MsgBox(sheetName & <span style="color: #a31515">" was activated."</span>)
<span style="color: blue">End</span> <span style="color: blue">If</span>
<span style="color: blue">Next</span>
<span style="color: blue">End</span> <span style="color: blue">If</span>
<span style="color: blue">End</span> <span style="color: blue">Sub</span>
<span style="color: blue">End</span> <span style="color: blue">Module</span>
</pre>
</body>
</html>