Creates a new raster image based on an existing image file.
Supported platforms: Windows only
VBA:
RetVal = object.AddRaster(ImageFileName, InsertionPoint, ScaleFactor, RotationAngle)
Type: Block, ModelSpace, PaperSpace
The objects this method applies to.
Access: Input-only
Type: String
The full path and file name of the image.
Access: Input-only
Type: Variant (three-element array of doubles)
The 3D WCS coordinates in the drawing where the raster image will be created.
Access: Input-only
Type: Double
The raster image scale factor. The default image scale factor is 1. The scale factor must be a positive number. You can set the scale of the image to the scale of the geometry created in the AutoCAD drawing.
Access: Input-only
Type: Double
The rotation angle in radians for the raster image.
Images placed through the AddRaster method are not actually part of the drawing file. The raster image is linked to the drawing file through a path name or document ID. Linked image paths can be changed or removed at any time by using the SupportPath property. By attaching images using linked image paths, you place images in your drawing without increasing the file size of the drawing.
You can add the same raster image file to your drawing file multiple times. Each instance has its own clip boundary and its own settings for brightness, contrast, fade, and transparency. A single image can be cut into multiple pieces that can be rearranged independently in your drawing.
VBA:
Sub Example_AddRaster() ' This example adds a raster image in model space. ' This example uses a file named "2d Projected Polylines.jpg." ' You should change this example to use ' a raster file on your computer. Dim insertionPoint(0 To 2) As Double Dim scalefactor As Double Dim rotationAngle As Double Dim imageName As String Dim rasterObj As AcadRasterImage imageName = "C:\AutoCAD\2d Projected Polylines.jpg" insertionPoint(0) = 5#: insertionPoint(1) = 5#: insertionPoint(2) = 0# scalefactor = 1# rotationAngle = 0 On Error Resume Next ' Creates a raster image in model space Set rasterObj = ThisDrawing.ModelSpace.AddRaster(imageName, insertionPoint, scalefactor, rotationAngle) If Err.Description = "File error" Then MsgBox imageName & " could not be found." Exit Sub End If ZoomExtents End Sub
Visual LISP:
(vl-load-com) (defun c:Example_AddRaster() ;; This example adds a raster image in model space. (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) ;; This example uses a file named "2d Projected Polylines.jpg." ;; You should change this example to use ;; a raster file on your computer. (setq insertionPoint (vlax-3d-point 5 5 0) imageName ".\\Sample\\VBA\\2d Projected Polylines.jpg" scalefactor 1 rotationAngle 0) ;; Creates a raster image in model space (if (/= (findfile imageName) nil) (progn (setq modelSpace (vla-get-ModelSpace doc)) (setq rasterObj (vla-AddRaster modelSpace (findfile imageName) insertionPoint scalefactor rotationAngle)) (vla-ZoomExtents acadObj) ) (alert (strcat imageName " could not be found.")) ) )