Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
draftsight
/
opt
/
dassault-systemes
/
DraftSight
/
APISDK
/
Load_and_Activate_LineStyles_Example_VBA.htm
|
|---|
<html>
<head>
<title>Load and Activate LineStyles 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,LineStyles">
<meta name=MS-HKWD content="VBA examples,LineStyle Manager">
<meta name=MS-HKWD content="VBA examples,Lines">
</head>
<body>
<h1>Load and Activate LineStyles Example (VBA)</h1>
<p>This example shows how to load and activate LineStyles.</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. Start debugging the project.
'
' Postconditions:
' 1. Gets the active document.
' 2. Gets the LineStyle Manager.
' 3. Loads the BATTING and ZIGAG LineStyles.
' 4. Activates and draws a Line for each LineStyle
' loaded in Step 3.
'----------------------------------------------------------------
Option Explicit</pre>
<pre> Sub main()</pre>
<pre> Dim dsApp As DraftSight.Application</pre>
<pre> 'Connect to DraftSight application
Set dsApp = GetObject(, "DraftSight.Application") </pre>
<pre> 'Abort any command currently running in DraftSight
'to avoid nested commands
dsApp.<b>AbortRunningCommand</b></pre>
<pre> If dsApp Is Nothing Then
Return
End If</pre>
<pre> 'Get active document
Dim dsDoc As DraftSight.Document
Set dsDoc = dsApp.<b>GetActiveDocument</b>()
If dsDoc Is Nothing Then
MsgBox ("There are no open documents in DraftSight.")
Return
End If </pre>
<pre> 'Get LineStyle manager
Dim dsLineStyleMgr As DraftSight.LineStyleManager
Set dsLineStyleMgr = dsDoc.<b>GetLineStyleManager</b>() </pre>
<pre> 'Load LineStyles
Dim lineStyleFile As String
lineStyleFile = "c:\Program Files\Dassault Systemes\DraftSight\Default Files\Linestyles\MM.LIN"
Dim dsLineStyle As DraftSight.LineStyle
dsLineStyleMgr.<b>LoadLineStyle</b> "BATTING", lineStyleFile, dsLineStyle
dsLineStyleMgr.<b>LoadLineStyle</b> "ZIGZAG", lineStyleFile, dsLineStyle </pre>
<pre> 'Get Sketch manager
Dim dsSketchMgr As DraftSight.SketchManager
Set dsSketchMgr = dsDoc.<b>GetModel</b>().<b>GetSketchManager</b>() </pre>
<pre> 'Activate BATTING LineStyle and insert Line
Set dsLineStyle = dsLineStyleMgr.<b>GetLineStyle</b>("BATTING")
dsLineStyle.<b>Activate</b>
dsSketchMgr.<b>InsertLine</b> 0, 0, 0, 100, 100, 0</pre>
<pre> 'Activate ZIGZAG LineStyle and insert Line
Set dsLineStyle = dsLineStyleMgr.<b>GetLineStyle</b>("ZIGZAG")
dsLineStyle.<b>Activate</b>
dsSketchMgr.<b>InsertLine</b> 100, 0, 0, 200, 100, 0
</pre>
<pre> End Sub</pre>
</body>
</html>