CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2025 开发者帮助

EntityColor 属性 (ActiveX)

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

EntityColor 属性 (ActiveX)

指定真颜色的颜色值。

支持的平台:仅限 Windows

签名

VBA:

object.EntityColor
对象

类型:AcCmColor

此属性应用于的对象。

属性值

只读:

类型:

真彩色的颜色值。

言论

此属性指定颜色的 32 位部分。AcCmEntityColor

例子

VBA:

Sub Example_EntityColor()
    Dim line As AcadLine
    Set line = CreateLine

    Dim color As AcadAcCmColor
    Set color = line.TrueColor
    Dim y As Long
    y = MakeLong(MakeWord(194, 122), MakeWord(133, 144))
    color.EntityColor = y

    line.TrueColor = color
    Dim retcolor As AcadAcCmColor
    Set retcolor = line.TrueColor
    
    Dim x As Long
    x = retcolor.EntityColor
    
    Dim BreakLong(3) As Byte
    BreakLong(0) = x And &HFF&
    BreakLong(1) = (x And &HFF00&) \ &H100&
    BreakLong(2) = (x And &HFF0000) \ &H10000
    BreakLong(3) = (x And &H7F000000) \ &H1000000
    If x < 0 Then BreakLong(3) = BreakLong(3) Or &H80
    
    MsgBox "ColorMethod = " & BreakLong(3) & vbCrLf & _
           "Red = " & BreakLong(2) & vbCrLf & _
           "Green = " & BreakLong(1) & vbCrLf & _
           "Blue = " & BreakLong(0)
End Sub

Private Function CreateLine() As AcadLine
    Dim lineObj As AcadLine
    Dim startPoint(0 To 2) As Double
    Dim endPoint(0 To 2) As Double
    
    startPoint(0) = 1#: startPoint(1) = 1#: startPoint(2) = 0#
    endPoint(0) = 5#: endPoint(1) = 5#: endPoint(2) = 0#
    
    Set lineObj = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint)
    Set CreateLine = lineObj
    ZoomAll
End Function

Private Function MakeLong(WordHi As Variant, WordLo As Integer) As Long

   ' High word is coerced to a variant on the call, to allow
   ' it to overflow the limits of multiplication, which shifts
   ' it left.

   MakeLong = (WordHi * &H10000) + (WordLo And &HFFFF&)
End Function

Private Function MakeWord(ByteHi As Byte, ByteLo As Byte) As Integer
   ' If the high byte would push the final result out of the
   ' signed integer range, it must be slid back.

   If ByteHi > &H7F Then
      MakeWord = ((ByteHi * &H100&) + ByteLo) - &H10000
   Else
      MakeWord = (ByteHi * &H100&) + ByteLo
   End If
End Function

可视化 LISP:

(vl-load-com)
(defun c:Example_EntityColor()
    (setq acadObj (vlax-get-acad-object)
          doc (vla-get-ActiveDocument acadObj))

    (setq modelSpace (vla-get-ModelSpace doc)
          line (CreateLine)
          color (vla-get-TrueColor line))
  
    (setq y (MakeLong (MakeWord 194 122) (MakeWord 133 144)))

    (vla-put-EntityColor color y)
    (vla-put-TrueColor line color)
    (setq retcolor (vla-get-TrueColor line))
    
    (setq x (vla-get-EntityColor retcolor))
    
    (setq BreakLong (vlax-make-safearray vlax-vbDouble '(0 . 3)))
    (vlax-safearray-put-element BreakLong 0 (logand x 255))
    (vlax-safearray-put-element BreakLong 1 (/ (logand x 65280) 256))
    (vlax-safearray-put-element BreakLong 2 (/ (logand x 16711680) 65536))
    (vlax-safearray-put-element BreakLong 3 (/ (logand x 2130706432) 16777216))

    (if (< x 0)
        (vlax-safearray-put-element BreakLong 3 (logior (fix (vlax-safearray-get-element BreakLong 3)) 128))
    )
    
    (alert (strcat "ColorMethod = " (itoa (fix (vlax-safearray-get-element BreakLong 3))) "\n"
                   "Red = " (itoa (fix (vlax-safearray-get-element BreakLong 2))) "\n"
                   "Green = " (itoa (fix (vlax-safearray-get-element BreakLong 1))) "\n"
                   "Blue = " (itoa (fix (vlax-safearray-get-element BreakLong 0)))))
)

(defun CreateLine()
    (setq acadObj (vlax-get-acad-object)
          doc (vla-get-ActiveDocument acadObj))

    (setq startPoint (vlax-3d-point 1 1 0)
          endPoint (vlax-3d-point 5 5 0)) 

    (setq modelSpace (vla-get-ModelSpace doc)
          lineObj (vla-AddLine modelSpace startPoint endPoint))

    (vla-ZoomAll acadObj)

    lineObj
)

(defun MakeLong (WordHi WordLo)
   ;; High word is coerced to a variant on the call, to allow
   ;; it to overflow the limits of multiplication, which shifts
   ;; it left.
   (+ (* WordHi 65536) (logand WordLo 65535))
)

(defun MakeWord(ByteHi ByteLo)
   ;; If the high byte would push the final result out of the
   ;; signed integer range, it must be slid back.
   (if (> ByteHi 127)
      (- (+ (* ByteHi 256) ByteLo) 65536)
      (+ (* ByteHi 256) ByteLo)
   )
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-6-27 15:53

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部