| 获取与给定对象 ID 对应的对象。 支持的平台:仅窗口 签名工 务 局: RetVal = object.ObjectIDToObject(ID) 返回值(RetVal)类型:对象 与给定对象 ID 对应的对象。 言论此方法只能返回当前文档中的对象。 例子工 务 局: Sub Example_ObjectIDToObject()
    ' This example creates a spline in model space, and returns the
    ' handle for the spline. Then the spline is returned from the handle and colored.
    
    ' Create the spline
    Dim splineObj As AcadSpline
    Dim startTan(0 To 2) As Double
    Dim endTan(0 To 2) As Double
    Dim fitPoints(0 To 8) As Double
    
    startTan(0) = 0.5: startTan(1) = 0.5: startTan(2) = 0
    endTan(0) = 0.5: endTan(1) = 0.5: endTan(2) = 0
    fitPoints(0) = 1: fitPoints(1) = 1: fitPoints(2) = 0
    fitPoints(3) = 5: fitPoints(4) = 5: fitPoints(5) = 0
    fitPoints(6) = 10: fitPoints(7) = 0: fitPoints(8) = 0
    Set splineObj = ThisDrawing.ModelSpace.AddSpline(fitPoints, startTan, endTan)
    
    ZoomAll
    
    Dim objectID As Long
    objectID = splineObj.ObjectID
    MsgBox "The objectID of the Spline is: " & objectID, , "ObjectIDToObject Example"
        
    ' Find an object from a given objectID
    Dim tempObj As AcadObject
    Set tempObj = ThisDrawing.ObjectIdToObject(objectID)
    ' Now use the newly initialized object variable to color the object
    Dim color As AcadAcCmColor
    Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor." & Left(AcadApplication.Version, 2))
    color.SetRGB 80, 100, 244
    
    tempObj.TrueColor = color
    
    ThisDrawing.Regen True
    MsgBox "The Spline is now blue.", , "ObjectIDToObject Example"
    
End SubVisual LISP: (vl-load-com)
(defun c:Example_ObjectIDToObject()
    ;; This example creates a spline in model space, and returns the
    ;; handle for the spline. Then the spline is returned from the handle and colored.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    ;; Create the spline
    (setq startTan (vlax-3d-point 0.5 0.5 0)
          endTan (vlax-3d-point 0.5 0.5 0)
          fitPoints (vlax-make-safearray vlax-vbDouble '(0 . 8)))
    (vlax-safearray-fill fitPoints '(1 1 0
                                     5 5 0
                                     10 0 0
                                    )
    )
    (setq modelSpace (vla-get-ModelSpace doc))
    (setq splineObj (vla-AddSpline modelSpace fitPoints startTan endTan))
    (vla-ZoomAll acadObj)
    
    ;; Find the objectID of the spline
    (setq objectID (vla-get-objectID splineObj))
    (alert (strcat "The objectID of the Spline is: " (itoa objectID)))
        
    ;; Find an object from a given objectID
    (setq tempObj (vla-ObjectIDToObject doc objectID))
    ;; Now use the newly initialized object variable to color the object 
    (setq color (vlax-create-object (strcat "AutoCAD.AcCmColor." (substr (getvar "ACADVER") 1 2))))
    (vla-SetRGB color 80 100 244)
  
    (vla-put-TrueColor tempObj color)
    
    (vla-Regen doc :vlax-true)
    (alert "The Spline is now blue.")
    (vlax-release-object color)
) | 
 |Archiver|CAD开发者社区
( 苏ICP备2022047690号-1   苏公网安备32011402011833)
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1   苏公网安备32011402011833)
GMT+8, 2025-11-1 07:38
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.