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

<head>
<title>Insert Picture 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,images">
<meta name=MS-HKWD content="VBA examples,pictures">
<meta name=MS-HKWD content="VBA examples,Referenced images">
</head>


<body>
<h1>Insert Picture Example (VBA)</h1>

<p>This example shows how to insert a picture in a drawing document.</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. Change the path and file name of the picture to insert.
'    <b>NOTE</b>: The picture must be a PNG file.
' 5. Start DraftSight and open a drawing.
' 6. Run the macro.
'
' Postconditions: A message box pops up when the specified picture 
' is inserted in the drawing document.
'--------------------------------------------------------------
Option Explicit

Sub main()

    Dim dsApp As DraftSight.Application
    Dim dsDoc As DraftSight.Document
    Dim dsModel As DraftSight.Model
    Dim dsSketchManager As DraftSight.SketchManager
    Dim dsPicture As DraftSight.ReferenceImage
    Dim imageFileName As String    </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.<b>GetActiveDocument</b>()
    If Not dsDoc Is Nothing Then        </pre>
<pre>        'Get model space
        Set dsModel = dsDoc.<b>GetModel</b>()        </pre>
<pre>        'Get Sketch Manager
        Set dsSketchManager = dsModel.<b>GetSketchManager</b>()        </pre>
<pre>        'Replace picture's path and file
        'name with yours
        imageFileName = &quot;c:\test\note.png&quot;        </pre>
<pre>        'Insert picture
        Set dsPicture = dsSketchManager.<b>InsertPicture</b>(imageFileName, 0#, 0#, 0#, 1#, 0#)        </pre>
<pre>        If dsPicture Is Nothing Then
            MsgBox imageFileName &amp; &quot; file was not found.&quot;
        Else
            MsgBox &quot;A picture was inserted in the drawing.&quot;
        End If        </pre>
<pre>    Else        </pre>
<pre>        MsgBox &quot;There are no open documents in DraftSight.&quot;        </pre>
<pre>    End If
End Sub</pre>

</body>

</html>