Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
<html>
<head>
<title> Create Table 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,Tables">
<meta name=MS-HKWD content="VB.NET examples,TableStyles">
<meta name=MS-HKWD content="VB.NET examples,TableStyleManager">
<meta name=MS-HKWD content="VB.NET examples,transparency">
<meta name=MS-HKWD content="VB.NET examples,Colors">
<meta name=MS-HKWD content="VB.NET examples,Layers">
</head>
<body>
<h1> Create Table Example (VB.NET)</h1>
<p>This example shows how to change the transparency of the active Layer, create
a TableStyle and Table, and change the background colors of the top row and a cell
in the Table.</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 project 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 new document.
' 5. Open the Immediate window.</span>
<span style="color:green;">' 6. Press F5.</span>
<span style="color:green;">'</span>
<span style="color:green;">' Postconditions:
' 1. Gets the transparency object for the active Layer and prints its
' transparency percentage to the Immediate window.
' 2. Changes the transparency percentage of the active Layer and prints
' its</span><span style="color:green;"> new percentage </span><span style="color:green;">to the Immediate window.
</span><span style="color:green;">' 3. Creates and activates a new TableStyle named <b>Sample Table Style</b></span><span style="color:green;">.
' 4. Inserts a Table and applies the <b>Sample Table Style</b> TableStyle</span>.<span style="color:green;">
' 5. Gets the transparency object for the Table.
' 6. Prints whether the transparency object for the Table is <b>ByLayer</b>.
' 7. If not, then changes and updates the transparency object
' of the Table to <b>ByLayer</b>.
' 8. Changes the top row's background color.
' 9. Changes the background color of the cell in the second row
' </span><span style="color:green;">and second column </span><span style="color:green;">to match the top row's background color.
'10. Prints the name of the TableStyle to the Immediate window.
'11. Examine the drawing and the Immediate window.
'----------------------------------------------------------------</span> </pre>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white"><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> DraftSight.Interop.dsAutomation.<span style="color:#2b91af;">Application</span>
<span style="color:green;">'Connect to DraftSight application</span>
dsApp = GetObject(, <span style="color:#a31515;">"DraftSight.Application"</span>)
<span style="color:green;">'Abort any command currently running in DraftSight</span>
<span style="color:green;">'to avoid nested commands</span>
dsApp.<b>AbortRunningCommand</b>()
<span style="color:green;">'Get active document</span>
<span style="color:blue;">Dim</span> dsDoc <span style="color:blue;">As</span> <span style="color:#2b91af;">Document</span>
dsDoc = dsApp.<b>GetActiveDocument</b>()
<span style="color:blue;">If</span> dsDoc <span style="color:blue;">Is</span> <span style="color:blue;">Nothing</span> <span style="color:blue;">Then</span>
MsgBox(<span style="color:#a31515;">"There are no open documents in DraftSight."</span>)
<span style="color:blue;">Return</span>
<span style="color:blue;">End</span> <span style="color:blue;">If
</span> <span style="color:green;">'Get how transparency is defined</span>
<span style="color:blue;">Dim</span> dsLayerManager <span style="color:blue;">As</span> <span style="color:#2b91af;">LayerManager</span>
<span style="color:blue;">Dim</span> dsLayer <span style="color:blue;">As</span> <span style="color:#2b91af;">Layer</span>
dsLayerManager = dsDoc.<b>GetLayerManager</b>()
dsLayer = dsLayerManager.<b>GetActiveLayer</b>()
<span style="color:#2b91af;">Debug</span>.Print(<span style="color:#a31515;">"Transparency percentage for active Layer: "</span> + <span style="color:#2b91af;">Convert</span>.ToString(dsLayer.<b>Transparency</b>))
<span style="color:green;">'Set new transparency percentage for the active Layer</span>
dsLayer.Transparency = 50
<span style="color:#2b91af;">Debug</span>.Print(<span style="color:#a31515;">"New transparency percentage for active Layer: "</span> + <span style="color:#2b91af;">Convert</span>.ToString(dsLayer.<b>Transparency</b>))
<span style="color:green;">'Get the TableStyle Manager</span>
<span style="color:blue;">Dim</span> dsTableStyleManager <span style="color:blue;">As</span> <span style="color:#2b91af;">TableStyleManager</span>
dsTableStyleManager = dsDoc.<b>GetTableStyleManager</b>
<span style="color:green;">'Create the TableStyle</span>
<span style="color:blue;">Dim</span> dsTableStyle <span style="color:blue;">As</span> <span style="color:#2b91af;">TableStyle</span>
<span style="color:blue;">Dim</span> sampleTableStyle <span style="color:blue;">As</span> <span style="color:blue;">String</span>
<span style="color:blue;">Dim</span> status <span style="color:blue;">As</span> <span style="color: #0000FF">Integer</span>
sampleTableStyle = <span style="color:#a31515;">"Sample Table Style"</span>
dsTableStyleManager.<b>CreateTableStyle</b>(sampleTableStyle, dsTableStyle, status)
<span style="color:green;">'Set the TableStyle styles</span>
<span style="color:green;">'Create the Table in a downward direction</span>
dsTableStyle.<b>HeaderOrientation</b> = <span style="color:#2b91af;">dsTableHeaderOrientation_e</span>.dsTableHeaderOrientation_Down
<span style="color:green;">'Set the Colors for the Table backgrounds</span>
<span style="color:blue;">Dim</span> dsColorHeader <span style="color:blue;">As</span> <span style="color:#2b91af;">Color</span>
<span style="color:blue;">Dim</span> dsColorData <span style="color:blue;">As</span> <span style="color:#2b91af;">Color</span>
<span style="color:blue;">Dim</span> dsColorTitle <span style="color:blue;">As</span> <span style="color:#2b91af;">Color</span>
</pre>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white"> dsColorHeader = dsTableStyle.<b>GetBackgroundColor</b>(<span style="color:#2b91af;">dsTableCellType_e</span>.dsTableCellType_Header)
dsColorHeader.<b>SetNamedColor</b>(<span style="color:#2b91af;">dsNamedColor_e</span>.dsNamedColor_Cyan)
dsTableStyle.<b>SetBackgroundColor</b>(<span style="color:#2b91af;">dsTableCellType_e</span>.dsTableCellType_Header, dsColorHeader)
dsColorData = dsTableStyle.<b>GetBackgroundColor</b>(<span style="color:#2b91af;">dsTableCellType_e</span>.dsTableCellType_Data)
dsColorData.<b>SetNamedColor</b>(<span style="color:#2b91af;">dsNamedColor_e</span>.dsNamedColor_Green)
dsTableStyle.<b>SetBackgroundColor</b>(<span style="color:#2b91af;">dsTableCellType_e</span>.dsTableCellType_Data, dsColorData)
dsColorTitle = dsTableStyle.<b>GetBackgroundColor</b>(<span style="color:#2b91af;">dsTableCellType_e</span>.dsTableCellType_Title)
dsColorTitle.<b>SetNamedColor</b>(<span style="color:#2b91af;">dsNamedColor_e</span>.dsNamedColor_White)
dsTableStyle.<b>SetBackgroundColor</b>(<span style="color:#2b91af;">dsTableCellType_e</span>.dsTableCellType_Title, dsColorTitle)</pre>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white">
<span style="color:green;">'Activate the TableStyle</span>
dsTableStyle.<b>Activate</b>()
<span style="color:green;">'Get the model document</span>
<span style="color:blue;">Dim</span> dsModel <span style="color:blue;">As</span> <span style="color:#2b91af;">Model</span>
dsModel = dsDoc.<b>GetModel</b>
<span style="color:green;">'Get the Sketch Manager</span>
<span style="color:blue;">Dim</span> dsSketchManager <span style="color:blue;">As</span> <span style="color:#2b91af;">SketchManager</span>
dsSketchManager = dsModel.<b>GetSketchManager</b>
<span style="color:green;">'Insert the Table</span>
<span style="color:blue;">Dim</span> dsTable <span style="color:blue;">As</span> <span style="color:#2b91af;">Table</span>
<span style="color:blue;">Dim</span> x <span style="color:blue;">As</span> <span style="color:blue;">Double</span>
x = 6
<span style="color:blue;">Dim</span> y <span style="color:blue;">As</span> <span style="color:blue;">Double</span>
y = 6
<span style="color:blue;">Dim</span> row <span style="color:blue;">As</span> <span style="color: #0000FF">Integer</span>
row = 4
<span style="color:blue;">Dim</span> col <span style="color:blue;">As</span> <span style="color: #0000FF">Integer</span>
col = 5
<span style="color:blue;">Dim</span> rowHeight <span style="color:blue;">As</span> <span style="color:blue;">Double</span>
rowHeight = 2
<span style="color:blue;">Dim</span> colWidth <span style="color:blue;">As</span> <span style="color:blue;">Double</span>
colWidth = 4
dsTable = dsSketchManager.<b>InsertTable</b>(x, y, row, col, rowHeight, colWidth, <span style="color:#2b91af;">dsTableCellType_e</span>.dsTableCellType_Title, <span style="color:#2b91af;">dsTableCellType_e</span>.dsTableCellType_Header, <span style="color:#2b91af;">dsTableCellType_e</span>.dsTableCellType_Data)</pre>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white"> <span style="color:green;">'Get transparency object for Table</span>
<span style="color:blue;">Dim</span> dsTransparency <span style="color:blue;">As</span> <span style="color:#2b91af;">Transparency</span>
dsTransparency = dsTable.<b>Transparency</b>()
<span style="color:green;">'Find out if Table's transparency is ByLayer</span>
<span style="color:#2b91af;">Debug</span>.Print(<span style="color:#a31515;">"Transparency defined ByLayer: "</span> + <span style="color:#2b91af;">Convert</span>.ToString(dsTransparency.<b>IsByLayer</b>))
<span style="color:green;">'If not, then change Table's transparency to ByLayer and </span>
<span style="color:green;">'update Table's transparency object</span>
<span style="color:blue;">If</span> <span style="color:blue;">Not</span> dsTransparency.<b>IsByLayer</b> <span style="color:blue;">Then</span>
dsTransparency.<b>SetByLayer</b>()
<span style="color:#2b91af;">Debug</span>.Print(<span style="color:#a31515;">"Transparency now ByLayer: "</span> + <span style="color:#2b91af;">Convert</span>.ToString(dsTransparency.<b>IsByLayer</b>))
<span style="color:green;">'Update Table's transparency object </span>
dsTable.<b>Transparency</b> = dsTransparency
<span style="color:blue;">End</span> <span style="color:blue;">If</span>
<span style="color:green;">'Change Table's top row's background color</span>
dsColorTitle.<b>SetNamedColor</b>(<span style="color:#2b91af;">dsNamedColor_e</span>.dsNamedColor_Yellow)
dsTable.<b>SetBackgroundColor</b>(<span style="color:#2b91af;">dsTableCellType_e</span>.dsTableCellType_Title, dsColorTitle)
<span style="color:green;">'Change background color of cell in the second row and </span>
<span style="color:green;">'second column to match the top row's background color</span>
dsTable.<b>SetCellBackgroundColor</b>(1, 1, dsColorTitle)
<span style="color:green;">'Get the name of the TableStyle for the just-inserted Table</span>
<span style="color:#2b91af;">Debug</span>.Print(<span style="color:#a31515;">"TableStyle applied to this table: "</span> + dsTableStyle.<b>Name</b>)
dsApp.<b>Zoom</b>(<span style="color:#2b91af;">dsZoomRange_e</span>.dsZoomRange_Fit, <span style="color:blue;">Nothing</span>, <span style="color:blue;">Nothing</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>