CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2020 开发者帮助

Replace 方法 (ActiveX)

2024-5-18 18:20| 发布者: admin| 查看: 107| 评论: 0|原作者: admin|来自: AutoCAD

Replace 方法 (ActiveX)

将字典中的项目替换为给定项目。

支持的平台:仅限 Windows

签名

VBA:

object.Replace Name, NewObject
对象

类型: 字典

此方法应用到的对象。

名字

访问:仅输入

类型:字符串

要替换的对象的名称(关键字)。

新对象

访问:仅输入

类型:对象

新对象。

返回值 (RetVal)

无返回值。

言论

例如,以下字典中的“FirstKeyword”:

  • 我的词典
  • 关键字对象
  • FirstKeyword 对象 1
  • SecondKeyword 对象2

附加了一个新对象“NewObject”:

  • 我的词典
  • 关键字对象
  • FirstKeyword NewObject
  • SecondKeyword 对象2

例子

VBA:

Sub Example_Replace()
    ' This example creates a dictionary and adds
    ' a custom object to that dictionary. It then
    ' replaces the object in the dictionary.
    
    Dim dictObj As AcadDictionary
    Set dictObj = ThisDrawing.Dictionaries.Add("TEST_DICTIONARY")
    
    ' Load the ObjectARX application that defines the custom object.
    ' Note: The application listed here does not exist and
    ' will cause an error when run. Change the application name
    ' to the path and name of your ObjectARX application.
    ThisDrawing.Application.LoadArx "MyARXApp.dll"
    
    ' Create the custom object in the dictionary
    Dim keyName As String
    Dim className As String
    Dim customObj As AcadObject
    
    keyName = "OBJ1"
    className = "CAsdkDictObject"
    
    Set customObj = dictObj.AddObject(keyName, className)
    
    ' Replace the object from the dictionary with a different object
    Dim newCustomObject As AcadObject
    dictObj.Replace keyName, newCustomObject
    
End Sub

可视化 LISP:

(vl-load-com)
(defun c:Example_Replace()
    ;; This example creates a dictionary and adds
    ;; a custom object to that dictionary. It then
    ;; replaces the object in the dictionary.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    (setq dictionaries (vla-get-Dictionaries doc))
  
    (setq dictObj (vla-Add dictionaries "TEST_DICTIONARY"))
    
    ;; Load the ObjectARX application that defines the custom object.
    ;; Note: The application listed here does not exist and
    ;; will cause an error when run. Change the application name
    ;; to the path and name of your ObjectARX application.
    (vla-LoadArx acadObj "MyARXApp.dll")
    
    ;; Create the custom object in the dictionary
    (setq keyName "OBJ1")
    (setq className "CAsdkDictObject")
    
    (setq customObj (vla-AddObject dictObj keyName className))
    
    ;; Replace the object from the dictionary with a different object
    (setq newCustomObject (vlax-make-variant))
    (vlax-variant-type newCustomObject vlax-vbObject)
    (vla-Replace dictObj keyName newCustomObject)
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2025-1-19 07:30

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部