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 / Insert_Embedded_Object_Example_VBA.htm
Size: Mime:
<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>
'&nbsp;&nbsp;&nbsp; embedded.<br>
' 2. Copy and paste this example into the Visual Basic IDE.<br>
' 3. Add a reference to the DraftSight type library,<br>
'&nbsp;&nbsp;&nbsp; <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>
&nbsp;&nbsp;&nbsp; 'Connect to DraftSight<br>
&nbsp;&nbsp;&nbsp; Set dsApp = GetObject(, &quot;DraftSight.Application&quot;)<br>
&nbsp;&nbsp;&nbsp; 'Abort any command currently running in DraftSight <br>
&nbsp;&nbsp;&nbsp; 'to avoid nested commands<br>
&nbsp;&nbsp;&nbsp; dsApp.<b>AbortRunningCommand</b></p>
<p class="APICODE">&nbsp;&nbsp;&nbsp; 'Get active document<br>
&nbsp;&nbsp;&nbsp; Dim dsDoc As DraftSight.Document<br>
&nbsp;&nbsp;&nbsp; Set dsDoc = dsApp.<b>GetActiveDocument</b>()<br>
&nbsp;&nbsp;&nbsp; If dsDoc Is Nothing Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox (&quot;There are no open 
documents in DraftSight.&quot;)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return<br>
&nbsp;&nbsp;&nbsp; End If</p>
<p class="APICODE">&nbsp;&nbsp;&nbsp; 'Get model space<br>
&nbsp;&nbsp;&nbsp; Dim dsModel As DraftSight.Model<br>
&nbsp;&nbsp;&nbsp; Set dsModel = dsDoc.<b>GetModel</b>()</p>
<p class="APICODE">&nbsp;&nbsp;&nbsp; 'Get sketch manager<br>
&nbsp;&nbsp;&nbsp; Dim dsSketchMgr As DraftSight.SketchManager<br>
&nbsp;&nbsp;&nbsp; Set dsSketchMgr = dsModel.<b>GetSketchManager</b>()</p>
<p class="APICODE">&nbsp;&nbsp;&nbsp; 'Embedded object parameters<br>
&nbsp;&nbsp;&nbsp; Dim filePath As String<br>
&nbsp;&nbsp;&nbsp; filePath = &quot;full_path\SampleDoc.docx&quot;<br>
&nbsp;&nbsp;&nbsp; Dim link As Boolean<br>
&nbsp;&nbsp;&nbsp; link = True<br>
&nbsp;&nbsp;&nbsp; Dim displayAsIcon As Boolean<br>
&nbsp;&nbsp;&nbsp; displayAsIcon = False</p>
<p class="APICODE">&nbsp;&nbsp;&nbsp; 'Insert embedded object<br>
&nbsp;&nbsp;&nbsp; Dim dsEmbeddedObject As DraftSight.EmbeddedObject<br>
&nbsp;&nbsp;&nbsp; Set dsEmbeddedObject = dsSketchMgr.<b>InsertEmbeddedObjectFromFile</b>(filePath, 
link, displayAsIcon)<br>
&nbsp;&nbsp;&nbsp; If Not (dsEmbeddedObject Is Nothing) Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Call PrintParameters(dsEmbeddedObject)<br>
&nbsp;&nbsp;&nbsp; Else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox (&quot;Embedded object entity was 
not added to the current drawing.&quot;)<br>
&nbsp;&nbsp;&nbsp; End If<br>
End Sub</p>
<p class="APICODE">Sub PrintParameters(dsEmbeddedObject As EmbeddedObject)<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;Embedded object parameters...&quot;)</p>
<p class="APICODE">&nbsp;&nbsp;&nbsp; 'Print common entity parameters<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;Handle = &quot; &amp; dsEmbeddedObject.<b>Handle</b>)<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;Color = &quot; &amp; dsEmbeddedObject.<b>Color</b>.<b>GetNamedColor</b>())<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;Erased = &quot; &amp; dsEmbeddedObject.<b>Erased</b>)<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;Layer = &quot; &amp; dsEmbeddedObject.<b>Layer</b>)<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;LineScale = &quot; &amp; dsEmbeddedObject.<b>LineScale</b>)<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;LineStyle = &quot; &amp; dsEmbeddedObject.<b>LineStyle</b>)<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;LineWeight = &quot; &amp; dsEmbeddedObject.<b>LineWeight</b>)<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;Visible = &quot; &amp; dsEmbeddedObject.<b>Visible</b>)</p>
<p class="APICODE">&nbsp;&nbsp;&nbsp; Dim x1 As Double, y1 As Double, z1 As 
Double<br>
&nbsp;&nbsp;&nbsp; Dim x2 As Double, y2 As Double, z2 As Double<br>
&nbsp;&nbsp;&nbsp; dsEmbeddedObject.GetBoundingBox x1, y1, z1, x2, y2, z2<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;BoundingBox: &quot; &amp; x1 &amp; &quot;, &quot; &amp; y1 &amp; &quot;, &quot; &amp; z1 &amp; &quot; 
and &quot; &amp; &quot;, &quot; &amp; x2 &amp; &quot;, &quot; &amp; y2 &amp; &quot;, &quot; &amp; z2)</p>
<p class="APICODE">&nbsp;&nbsp;&nbsp; 'Print embedded object parameters<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;Height = &quot; &amp; dsEmbeddedObject.<b>Height</b>)<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;Width = &quot; &amp; dsEmbeddedObject.<b>Width</b>)<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;PrintQuality = &quot; &amp; dsEmbeddedObject.<b>PrintQuality</b>)<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;LinkPath = &quot; &amp; dsEmbeddedObject.<b>GetLinkPath</b>())<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;SourceApplication = &quot; &amp; dsEmbeddedObject.<b>GetSourceApplication</b>())<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;Type:&nbsp; &quot; &amp; dsEmbeddedObject.[<b>GetType</b>]())</p>
<p class="APICODE">&nbsp;&nbsp;&nbsp; 'Get position of embedded object<br>
&nbsp;&nbsp;&nbsp; Dim x As Double, y As Double, z As Double<br>
&nbsp;&nbsp;&nbsp; dsEmbeddedObject.<b>GetPosition</b> x, y, z<br>
&nbsp;&nbsp;&nbsp; Debug.Print (&quot;Position: &quot; &amp; x &amp; &quot;, &quot; &amp; y &amp; &quot;, &quot; &amp; z)<br>
End Sub</p>

</body>

</html>