CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

相关分类

添加形状方法 (ActiveX)

2023-1-4 12:22| 发布者: admin| 查看: 715| 评论: 0|来自: AutoCAD

摘要: 基于按名称标识的模板、给定插入点、比例因子和旋转处创建 Shape 对象。

基于按名称标识的模板、给定插入点、比例因子和旋转处创建 Shape 对象。

支持的平台:仅窗口

签名

工 务 局:

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

类型:模型空间,图纸空间

此方法适用的对象。

名字

访问:仅输入

类型:字符串

要插入的形状的名称。

插入点

访问:仅输入

类型:变体(双精度的三元素数组)

插入形状的 3D WCS 坐标。

比例因子

访问:仅输入

类型:

要应用于形状的比例因子。使用 1.0 指定无比例。必须是正数。

旋转

访问:仅输入

类型:

要应用于形状的旋转角度(以弧度为单位)。

返回值(RetVal)

类型:形状

新创建的对象。Shape

言论

在添加 Shape 对象之前,必须使用该方法加载包含所需形状的文件。LoadShapeFile

例子

工 务 局:

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.")
    )
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-12 08:58

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部