Value Example |
Using Programming Languages other than VBA
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
Comments? |