CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

相关分类

值属性 (ActiveX)

2023-1-3 01:50| 发布者: admin| 查看: 215| 评论: 0|来自: AutoCAD

摘要: 指定属性的当前值或新创建的克隆对象的对象 ID。

指定属性的当前值或新创建的克隆对象的对象 ID。

支持的平台:仅窗口

签名

工 务 局:

object.Value
对象

类型:动态块引用属性IDPair

此属性适用的对象。

属性值

只读:否 (DynamicBlockReferenceProperty), Yes (IDPair)

类型:Variant (DynamicBlockReferenceProperty), Long_PTR (IDPair)

DynamicBlockReferenceProperty:属性的当前值。

IDPair:操作中新创建的克隆对象的对象ID。CopyObjects

言论

动态块引用属性:如果无法设置指定的属性值,则不会返回任何错误。例如,如果属性具有允许值列表或最小-最大范围,并且提供的值不在列表中或超出范围,则不会返回任何错误。

IDPair:使用属性获取源对象的对象 ID。Key

例子

工 务 局:

Sub Example_Value()
    ' This example creates two Circle objects and uses the CopyObjects
    ' method to copy them. It then returns the object IDs
    ' of the new objects using the Value property and uses the
    ' object IDs to remove the new (target) objects

    Dim circleObj1 As AcadCircle, circleObj2 As AcadCircle
    Dim circleObj1Copy As AcadCircle, circleObj2Copy As AcadCircle
    Dim centerPoint(0 To 2) As Double
    Dim radius1 As Double, radius2 As Double
    Dim radius1Copy As Double, radius2Copy As Double
    Dim objCollection(0 To 1) As Object
    Dim retObjects As Variant
    Dim IDPairs As Variant
    Dim TargetObject As AcadObject
    
    ' Define the Circle object
    centerPoint(0) = 0: centerPoint(1) = 0: centerPoint(2) = 0
    radius1 = 5#: radius2 = 7#
    radius1Copy = 1#: radius2Copy = 2#
    
    ' Add two circles to the drawing
    Set circleObj1 = ThisDrawing.ModelSpace.AddCircle(centerPoint, radius1)
    Set circleObj2 = ThisDrawing.ModelSpace.AddCircle(centerPoint, radius2)
    ThisDrawing.Application.ZoomAll
    
    ' Copy objects
    '
    ' First put the objects to be copied into a form compatible with CopyObjects
    Set objCollection(0) = circleObj1
    Set objCollection(1) = circleObj2
    
    ' Copy object and get back a collection of the new objects (copies)
    retObjects = ThisDrawing.CopyObjects(objCollection, , IDPairs)
    
    ' Get newly created object and apply new properties to the copies
    Set circleObj1Copy = retObjects(0)
    Set circleObj2Copy = retObjects(1)
    
    circleObj1Copy.radius = radius1Copy
    circleObj2Copy.radius = radius2Copy
        
    ThisDrawing.Application.ZoomAll
    ThisDrawing.Regen acAllViewports
    
    ' Display the object IDs of the source objects used for the copy
    MsgBox "The first target object ID is: " & IDPairs(0).Value & vbCrLf & _
           "The second target object ID is: " & IDPairs(1).Value

    ' This key can be used with objectIDtoObject to reference the source objects,
    ' which is useful if the user manually selected the source objects.
    '
    ' Here we delete the source objects from the ID obtained
    Set TargetObject = ThisDrawing.ObjectIdToObject(IDPairs(0).Value)
    TargetObject.Delete
    Set TargetObject = ThisDrawing.ObjectIdToObject(IDPairs(1).Value)
    TargetObject.Delete
    
    ThisDrawing.Regen acAllViewports
    
    MsgBox "The target objects have been deleted!", vbInformation
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_Value()
    ;; This example creates two Circle objects and uses the CopyObjects
    ;; method to copy them. It then returns the object IDs
    ;; of the new objects using the Value property and uses the
    ;; object IDs to remove the new (target) objects
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    
    ;; Define the Circle object
    (setq centerPoint (vlax-3d-point 0 0 0)  
          radius1 5
          radius2 7
          radius1Copy 1
          radius2Copy 2)
    
    ;; Add two circles to the drawing
    (setq modelSpace (vla-get-ModelSpace doc))
    (setq circleObj1 (vla-AddCircle modelSpace centerPoint radius1))
    (setq circleObj2 (vla-AddCircle modelSpace centerPoint radius2))
    (vla-ZoomAll acadObj)
    
    ;; Copy objects
    ;;
    ;; First put the objects to be copied into a form compatible with CopyObjects
    (setq objCollection (vlax-make-safearray vlax-vbObject '(0 . 1)))
    (vlax-safearray-put-element objCollection 0 circleObj1)
    (vlax-safearray-put-element objCollection 1 circleObj2)
    
    ;; Copy object and get back a collection of the new objects (copies)
    (setq retObjects (vlax-variant-value (vla-CopyObjects doc objCollection nil 'IDPairs)))
          
    ;; Get newly created object and apply new properties to the copies
    (setq circleObj1Copy (vlax-safearray-get-element retObjects 0))
    (setq circleObj2Copy (vlax-safearray-get-element retObjects 1))
    
    (vla-put-Radius circleObj1Copy radius1Copy)
    (vla-put-Radius circleObj2Copy radius2Copy)
        
    (vla-ZoomAll acadObj)
    (vla-Regen doc acAllViewports)
    
    ;; Display the object IDs of the source objects used for the copy
    (alert (strcat "The first target object ID is: " (itoa (vla-get-Value (vlax-safearray-get-element IDPairs 0)))
                   "\nThe second target object ID is: " (itoa (vla-get-Value (vlax-safearray-get-element IDPairs 1)))))

    ;; This key can be used with objectIDtoObject to reference the source objects,
    ;; which is useful if the user manually selected the source objects.
    ;;
    ;; Here we delete the source objects from the ID obtained
    (setq TargetObject (vla-ObjectIdToObject doc (vla-get-Value (vlax-safearray-get-element IDPairs 0))))
    (vla-Delete TargetObject)
    (setq TargetObject (vla-ObjectIdToObject doc (vla-get-Value (vlax-safearray-get-element IDPairs 1))))
    (vla-Delete TargetObject)
    
    (vla-Regen doc acAllViewports)
    
    (alert "The target objects have been deleted!")
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-12 11:26

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部