Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
<html>
<head>
<title>Insert Embedded Object 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, embedded objects">
</head>
<body>
<h1>Insert Embedded Object Example (VBA)</h1>
<p>This example shows how to embed a file object in a DraftSight drawing.</p>
<p class="APICODE">
'-----------------------------------------------------------------------------<br>
' Preconditions:<br>
' 1. Create a VBA macro in a software product in which VBA is<br>
' embedded.<br>
' 2. Copy and paste this example into the Visual Basic IDE.<br>
' 3. Add a reference to the DraftSight type library,<br>
' <i>install_dir</i><b>\bin\dsAutomation.dll</b>.<br>
' 4. Modify the document name referenced in the code.<br>
' 5. Start DraftSight and open a drawing document.<br>
' 6. Start debugging the project.<br>
'<br>
' Postconditions:<br>
' 1. The file object is embedded in the drawing.<br>
' 2. Inspect the Immediate window for its position and parameters.<br>
'----------------------------------------------------------------<br>
Dim dsApp As DraftSight.Application<br>
Option Explicit<br>
Sub Main()<br>
'Connect to DraftSight<br>
Set dsApp = GetObject(, "DraftSight.Application")<br>
'Abort any command currently running in DraftSight <br>
'to avoid nested commands<br>
dsApp.<b>AbortRunningCommand</b></p>
<p class="APICODE"> 'Get active document<br>
Dim dsDoc As DraftSight.Document<br>
Set dsDoc = dsApp.<b>GetActiveDocument</b>()<br>
If dsDoc Is Nothing Then<br>
MsgBox ("There are no open
documents in DraftSight.")<br>
Return<br>
End If</p>
<p class="APICODE"> 'Get model space<br>
Dim dsModel As DraftSight.Model<br>
Set dsModel = dsDoc.<b>GetModel</b>()</p>
<p class="APICODE"> 'Get sketch manager<br>
Dim dsSketchMgr As DraftSight.SketchManager<br>
Set dsSketchMgr = dsModel.<b>GetSketchManager</b>()</p>
<p class="APICODE"> 'Embedded object parameters<br>
Dim filePath As String<br>
filePath = "full_path\SampleDoc.docx"<br>
Dim link As Boolean<br>
link = True<br>
Dim displayAsIcon As Boolean<br>
displayAsIcon = False</p>
<p class="APICODE"> 'Insert embedded object<br>
Dim dsEmbeddedObject As DraftSight.EmbeddedObject<br>
Set dsEmbeddedObject = dsSketchMgr.<b>InsertEmbeddedObjectFromFile</b>(filePath,
link, displayAsIcon)<br>
If Not (dsEmbeddedObject Is Nothing) Then<br>
Call PrintParameters(dsEmbeddedObject)<br>
Else<br>
MsgBox ("Embedded object entity was
not added to the current drawing.")<br>
End If<br>
End Sub</p>
<p class="APICODE">Sub PrintParameters(dsEmbeddedObject As EmbeddedObject)<br>
Debug.Print ("Embedded object parameters...")</p>
<p class="APICODE"> 'Print common entity parameters<br>
Debug.Print ("Handle = " & dsEmbeddedObject.<b>Handle</b>)<br>
Debug.Print ("Color = " & dsEmbeddedObject.<b>Color</b>.<b>GetNamedColor</b>())<br>
Debug.Print ("Erased = " & dsEmbeddedObject.<b>Erased</b>)<br>
Debug.Print ("Layer = " & dsEmbeddedObject.<b>Layer</b>)<br>
Debug.Print ("LineScale = " & dsEmbeddedObject.<b>LineScale</b>)<br>
Debug.Print ("LineStyle = " & dsEmbeddedObject.<b>LineStyle</b>)<br>
Debug.Print ("LineWeight = " & dsEmbeddedObject.<b>LineWeight</b>)<br>
Debug.Print ("Visible = " & dsEmbeddedObject.<b>Visible</b>)</p>
<p class="APICODE"> Dim x1 As Double, y1 As Double, z1 As
Double<br>
Dim x2 As Double, y2 As Double, z2 As Double<br>
dsEmbeddedObject.GetBoundingBox x1, y1, z1, x2, y2, z2<br>
Debug.Print ("BoundingBox: " & x1 & ", " & y1 & ", " & z1 & "
and " & ", " & x2 & ", " & y2 & ", " & z2)</p>
<p class="APICODE"> 'Print embedded object parameters<br>
Debug.Print ("Height = " & dsEmbeddedObject.<b>Height</b>)<br>
Debug.Print ("Width = " & dsEmbeddedObject.<b>Width</b>)<br>
Debug.Print ("PrintQuality = " & dsEmbeddedObject.<b>PrintQuality</b>)<br>
Debug.Print ("LinkPath = " & dsEmbeddedObject.<b>GetLinkPath</b>())<br>
Debug.Print ("SourceApplication = " & dsEmbeddedObject.<b>GetSourceApplication</b>())<br>
Debug.Print ("Type: " & dsEmbeddedObject.[<b>GetType</b>]())</p>
<p class="APICODE"> 'Get position of embedded object<br>
Dim x As Double, y As Double, z As Double<br>
dsEmbeddedObject.<b>GetPosition</b> x, y, z<br>
Debug.Print ("Position: " & x & ", " & y & ", " & z)<br>
End Sub</p>
</body>
</html>