Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
draftsight / opt / dassault-systemes / DraftSight / APISDK / Create_Table_Example_VBA.htm
Size: Mime:
<html>

<head>
<title>Create Table Example (VBA)</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="VBA examples">
<meta name=MS-HKWD content="VBA examples, Tables">
<meta name=MS-HKWD content="VBA examples, TableStyles">
<meta name=MS-HKWD content="VBA examples, TableStyle Manager">
<meta name=MS-HKWD content="VBA examples, Layers">
<meta name=MS-HKWD content="VBA examples, transparency">
<meta name=MS-HKWD content="VBA examples, Colors">


</head>


<body>
<h1>Create Table Example (VBA)</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>'-------------------------------------------------------------
' Preconditions:
' 1. Create a VBA macro in a software product in which VBA is
'    embedded.
' 2. Copy and paste this example into the Visual Basic IDE.
' 3. Add a reference to the DraftSight type library,
'    <i>install_dir</i><b>\bin\dsAutomation.dll.</b>
' 4. Open the Immediate window.
' 5. Start DraftSight and open a new document.
' 6. Run the macro.
'
'&nbsp;Postconditions:&nbsp;
' 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 new percentage to the Immediate window.
'&nbsp;3.&nbsp;Creates and activates a&nbsp;new&nbsp;TableStyle&nbsp;named&nbsp;<b>Sample&nbsp;Table&nbsp;Style</b>.
'&nbsp;4.&nbsp;Inserts a&nbsp;Table and applies the&nbsp;<b>Sample&nbsp;Table&nbsp;Style</b>&nbsp;TableStyle.
' 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>.&nbsp;
' 8. Changes the top row's background color.
' 9. Changes the background color of the cell in the second row
'    and second column to match the top row's background color.&nbsp;&nbsp;
'10. Prints the name of the TableStyle to the Immediate window.
'11. Examine the drawing and the Immediate window.
'----------------------------------------------------------------</pre>
<pre>Option Explicit</pre>
<pre>    Sub main()    </pre>
<pre>        Dim dsApp As DraftSight.Application        </pre>
<pre>        'Connect to DraftSight application
        Set dsApp = GetObject(, &quot;DraftSight.Application&quot;)        </pre>
<pre>        'Abort any command currently running in DraftSight
        'to avoid nested commands
        dsApp.<b>AbortRunningCommand</b>        </pre>
<pre>        'Get active document
        Dim dsDoc As DraftSight.Document
        Set dsDoc = dsApp.<b>GetActiveDocument</b>()
        If dsDoc Is Nothing Then
            MsgBox (&quot;There are no open documents in DraftSight.&quot;)
            Return
        End If        </pre>
<pre>        'Get how transparency is defined
        Dim dsLayerManager As DraftSight.LayerManager
        Dim dsLayer As DraftSight.Layer
        Set dsLayerManager = dsDoc.<b>GetLayerManager</b>
        Set dsLayer = dsLayerManager.<b>GetActiveLayer</b>
        Debug.Print &quot;Transparency percentage for active Layer: &quot; &amp; dsLayer.<b>Transparency</b>
        'Set new transparency percentage for the active Layer
        dsLayer.<b>Transparency</b> = 50
        Debug.Print &quot;New transparency percentage for active Layer: &quot; &amp; dsLayer.<b>Transparency</b></pre>
<pre>        'Get the TableStyle Manager
        Dim dsTableStyleManager As DraftSight.TableStyleManager
        Set dsTableStyleManager = dsDoc.<b>GetTableStyleManager</b>        </pre>
<pre>        'Create the TableStyle
        Dim dsTableStyle As DraftSight.TableStyle
        Dim sampleTableStyle As String
        Dim status As Long
        sampleTableStyle = &quot;Sample Table Style&quot;
        dsTableStyleManager.<b>CreateTableStyle</b> sampleTableStyle, dsTableStyle, status        </pre>
<pre>        'Set the TableStyle styles
        'Create the Table in a downward direction
        dsTableStyle.<b>HeaderOrientation</b> = dsTableHeaderOrientation_Down</pre>
<pre>        'Set the Colors for the Table backgrounds
        Dim dsColorHeader As DraftSight.Color
        Dim dsColorData As DraftSight.Color
        Dim dsColorTitle As DraftSight.Color        </pre>
<pre>        Set dsColorHeader = dsTableStyle.<b>GetBackgroundColor</b>(dsTableCellType_Header)
        dsColorHeader.<b>SetNamedColor</b> dsNamedColor_e.dsNamedColor_Cyan
        dsTableStyle.<b>SetBackgroundColor</b> dsTableCellType_Header, dsColorHeader
        </pre>
<pre>        Set dsColorData = dsTableStyle.<b>GetBackgroundColor</b>(dsTableCellType_Data)
        dsColorData.<b>SetNamedColor</b> dsNamedColor_e.dsNamedColor_Green
        dsTableStyle.<b>SetBackgroundColor</b> dsTableCellType_Data, dsColorData
        </pre>
<pre>        Set dsColorTitle = dsTableStyle.<b>GetBackgroundColor</b>(dsTableCellType_Title)
        dsColorTitle.<b>SetNamedColor</b> dsNamedColor_e.dsNamedColor_White
        dsTableStyle.<b>SetBackgroundColor</b> dsTableCellType_Title, dsColorTitle</pre>
<pre>        'Activate the TableStyle
        dsTableStyle.<b>Activate</b>        </pre>
<pre>        'Get the model document
        Dim dsModel As DraftSight.Model
        Set dsModel = dsDoc.<b>GetModel</b>        </pre>
<pre>        'Get the Sketch Manager
        Dim dsSketchManager As DraftSight.SketchManager
        Set dsSketchManager = dsModel.<b>GetSketchManager</b>        </pre>
<pre>        'Insert the Table
        Dim dsTable As DraftSight.Table
        Dim x As Double
        x = 6
        Dim y As Double
        y = 6
        Dim row As Long
        row = 4
        Dim col As Long
        col = 5
        Dim rowHeight As Double
        rowHeight = 2
        Dim colWidth As Double
        colWidth = 4
 	Set dsTable = dsSketchManager.<b>InsertTable</b>(x, y, row, col, rowHeight, colWidth, dsTableCellType_Title, dsTableCellType_Header, dsTableCellType_Data)</pre>
<pre>        'Get transparency object for Table
        Dim dsTransparency As DraftSight.Transparency
        Set dsTransparency = dsTable.<b>Transparency</b>
        'Find out if Table's transparency is ByLayer
        Debug.Print &quot;Transparency defined ByLayer: &quot; &amp; dsTransparency.<b>IsByLayer</b>
        'If not, then change Table's transparency to ByLayer and
        'update Table's transparency object
        If Not dsTransparency.<b>IsByLayer</b> Then
            dsTransparency.<b>SetByLayer</b>
            Debug.Print &quot;Transparency now ByLayer: &quot; &amp; dsTransparency.<b>IsByLayer</b>
            'Update Table's transparency object
	    dsTable.<b>Transparency</b> = dsTransparency
        End If        </pre>
<pre>        'Change Table's top row's background color
        dsColorTitle.<b>SetNamedColor</b> (dsNamedColor_Yellow)
        dsTable.<b>SetBackgroundColor</b> dsTableCellType_Title, dsColorTitle
        'Change background color of cell in second row and
        'second column to match the top row's background color
        dsTable.<b>SetCellBackgroundColor</b> 1, 1, dsColorTitle

        'Get the name of the TableStyle for the just-inserted Table
        Debug.Print (&quot;TableStyle applied to this table: &quot; &amp; dsTableStyle.<b>Name</b>) 

        dsApp.<b>Zoom</b> dsZoomRange_Fit, Nothing, Nothing

End Sub</pre>

</body>

</html>