AddShape Method (ActiveX)

Creates a Shape object based on a template identified by name, at the given insertion point, scale factor, and rotation.

Supported platforms: Windows only

Signature

VBA:

RetVal = object.AddShape(Name, InsertionPoint, ScaleFactor, Rotation)
object

Type: Block, ModelSpace, PaperSpace

The objects this method applies to.

Name

Access: Input-only

Type: String

The name of the shape to insert.

InsertionPoint

Access: Input-only

Type: Variant (three-element array of doubles)

The 3D WCS coordinates at which to insert the shape.

ScaleFactor

Access: Input-only

Type: Double

The scale factor to be applied to the shape. Use 1.0 to specify no scale. Must be a positive number.

Rotation

Access: Input-only

Type: Double

The angle of rotation in radians to be applied to the shape.

Return Value (RetVal)

Type: Shape

The newly created Shape object.

Remarks

Before adding a Shape object, you must load the file containing the desired shape using the LoadShapeFile method.

Examples

VBA:

Sub Example_AddShape()
    ' This example creates a BAT shape from the ltypeshp.shx file.
    
    ' Load the shape file containing the shape you wish to create.
    ' Note: Replace the ltypeshp.shx file name
    ' with a valid shape file for your system.
    On Error GoTo ERRORHANDLER
    ThisDrawing.LoadShapeFile ("C:/Program Files/AutoCAD/Support/ltypeshp.shx")

    
    Dim shapeObj As AcadShape
    Dim shapeName As String
    Dim insertionPoint(0 To 2) As Double
    Dim scalefactor As Double
    Dim rotation As Double
    
    ' "diode" is defined in es.shx file
    shapeName = "BAT"
    insertionPoint(0) = 2#: insertionPoint(1) = 2#: insertionPoint(2) = 0#
    scalefactor = 1#
    rotation = 0#       ' Radians
    
    ' Create the diode shape object in model space
    Set shapeObj = ThisDrawing.ModelSpace.AddShape(shapeName, insertionPoint, scalefactor, rotation)
    Exit Sub
    
ERRORHANDLER:
    MsgBox "Cannot find the shape file.", , "AddShape Example"
    
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_AddShape()
    ;; This example creates a BAT shape from the ltypeshp.shx file.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
  
    ;; Load the shape file containing the shape you wish to create.
    ;; Note: Replace the ltypeshp.shx file name
    ;; with a valid shape file for your system.
    (setq shapeFile ".\\ltypeshp.shx")

    (if (/= (findfile shapeFile) nil)
        (progn
	           (vla-LoadShapeFile doc (findfile shapeFile))

            ;; "diode" is defined in es.shx file
            (setq insertionPoint (vlax-3d-point 2 2 0)
                  shapeName "BAT"
                  scalefactor 1
                  rotation 0)      ;; Radians
    
            ;; Create the diode shape object in model space
	           (setq modelSpace (vla-get-ModelSpace doc))
	           (setq shapeObj (vla-AddShape modelSpace shapeName insertionPoint scalefactor rotation))
        )
        (alert "Cannot find the shape file.")
    )
)