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 / Switch_Layouts_Example_VBA.htm
Size: Mime:
<html>

<head>
<title>Switch Layouts 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,Sheets">
<meta name=MS-HKWD content="VBA examples,layouts">
<meta name=MS-HKWD content="VBA examples,models">
</head>


<body>
<h1>Switch Layouts Example (VBA)</h1>
<p>This example shows how to switch layouts.</p>
<p>&nbsp;</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. Start DraftSight and open a document.
' 5. Run the macro.
'
'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.
'----------------------------------------------------------------</pre>
<pre>Option Explicit</pre>
<pre>Sub main()
    Dim dsApp As DraftSight.Application
    Dim dsDoc As DraftSight.Document    </pre>
<pre>    'Connect to DraftSight
    Set dsApp = GetObject(, &quot;DraftSight.Application&quot;)
    'Abort any command currently running in DraftSight 
    'to avoid nested commands
    dsApp.<b>AbortRunningCommand</b>    </pre>
<pre>    'Get active document
    Set dsDoc = dsApp.GetActiveDocument()
    If Not dsDoc Is Nothing Then        </pre>
<pre>        'Activate each layout, one by one
        SwitchLayouts dsDoc        </pre>
<pre>    Else
        MsgBox &quot;There are no open documents in DraftSight.&quot;
    End If
End Sub</pre>
<pre>
Sub SwitchLayouts(dsDoc As DraftSight.Document)
    Dim dsSheet As DraftSight.Sheet
    Dim dsModel As DraftSight.Model
    Dim dsVarSheets As Variant
    Dim index As Integer
    Dim sheetName As String    </pre>
<pre>    'Get all sheets
    dsVarSheets = dsDoc.GetSheets    </pre>
<pre>    If IsArray(dsVarSheets) Then        </pre>
<pre>        For index = LBound(dsVarSheets) To UBound(dsVarSheets)        </pre>
<pre>            Set dsSheet = dsVarSheets(index)            </pre>
<pre>            'Get sheet name
            sheetName = dsSheet.Name            </pre>
<pre>            'Change sheet name, if it is not a model
            If sheetName &lt;&gt; &quot;Model&quot; Then            </pre>
<pre>                'Activate sheet
                dsSheet.Activate                </pre>
<pre>                'Verify if the sheet was activated
                If dsSheet.IsActive Then
                    MsgBox &quot;The sheet &quot; &amp; sheetName &amp; &quot; was activated.&quot;
                End If            </pre>
<pre>            Else            </pre>
<pre>                'Activate model sheet
                Set dsModel = dsDoc.GetModel                </pre>
<pre>                If Not dsModel Is Nothing Then                    </pre>
<pre>                    'Activate model sheet
                    dsModel.Activate                    </pre>
<pre>                    'Verify if the sheet was activated
                    If dsModel.IsActive Then
                        MsgBox &quot;The model sheet was activated.&quot;
                    End If                    </pre>
<pre>                End If            </pre>
<pre>            End If        </pre>
<pre>        Next        </pre>
<pre>    End If    
</pre>
<pre>End Sub</pre>

</body>

</html>