Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
<html>
<head>
<title>Insert Picture Example (VB.NET)</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="VB.NET examples">
<meta name=MS-HKWD content="VB.NET examples,images">
<meta name=MS-HKWD content="VB.NET examples,pictures">
<meta name=MS-HKWD content="VB.NET examples,Referenced images">
</head>
<body>
<h1>Insert Picture Example (VB.NET)</h1>
<p>This example shows how to insert a picture in a drawing document.</p>
<pre>'--------------------------------------------------------------
' Preconditions:
' 1. Create a VB.NET Windows console project.
' 2. Copy and paste this example into the VB.NET IDE.
' 3. Add a reference to:
' <i>install_dir</i>\<b>APISDK\tlb\DraftSight.Interop.dsAutomation.dll</b>.
' 4. Change the path and file name of the picture file to insert.
' <b>NOTE</b>: The picture must be a PNG file.
' 5. Start DraftSight and open a drawing.
' 6. Start debugging the project.
'
' Postconditions: A message box pops up when the specified picture
' is inserted in the drawing document.
'----------------------------------------------------------------
Imports DraftSight.Interop.dsAutomation</pre>
<pre>Module Module1</pre>
<pre> Sub Main()</pre>
<pre> Dim dsApp As Application
Dim dsDoc As Document
Dim dsModel As Model
Dim dsSketchManager As SketchManager
Dim dsPicture As ReferenceImage
Dim imageFileName As String</pre>
<pre> 'Connect to DraftSight
dsApp = GetObject(, "DraftSight.Application")
dsApp.<b>AbortRunningCommand</b>() ' abort any command currently running in DraftSight to avoid nested commands</pre>
<pre> 'Get active document
dsDoc = dsApp.<b>GetActiveDocument</b>()
If Not dsDoc Is Nothing Then
'Get model space
dsModel = dsDoc.<b>GetModel</b>()
'Get Sketch Manager
dsSketchManager = dsModel.<b>GetSketchManager</b>()
'Replace picture's path and file
'name with yours
imageFileName = "c:\test\note.png"
'Insert picture
dsPicture = dsSketchManager.<b>InsertPicture</b>(imageFileName, 0.0#, 0.0#, 0.0#, 1.0#, 0.0#)
If dsPicture Is Nothing Then
MsgBox(imageFileName & " file was not found.")
Else
MsgBox("A picture was inserted in the drawing.")
End If
Else
MsgBox("There are no open documents in DraftSight.")
End If
End Sub</pre>
<pre>End Module</pre>
<p> </p>
</body>
</html>