CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

相关分类

实体颜色属性 (ActiveX)

2023-1-3 17:10| 发布者: admin| 查看: 333| 评论: 0|来自: AutoCAD

摘要: 指定真彩色的颜色值。

指定真彩色的颜色值。

支持的平台:仅窗口

签名

工 务 局:

object.EntityColor
对象

类型:AcCm颜色

此属性适用的对象。

属性值

只读:

类型:

真彩色的颜色值。

言论

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

例子

工 务 局:

Sub Example_EntityColor()
    Dim color As AcadAcCmColor
    Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor." & Left(AcadApplication.Version, 2))
    Dim y As Long
    y = MakeLong(MakeWord(194, 122), MakeWord(133, 144))
    color.EntityColor = y
    Dim line As AcadLine
    Set line = CreateLine
    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

Visual LISP:

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

    (setq color (vlax-create-object (strcat "AutoCAD.AcCmColor." (substr (getvar "ACADVER") 1 2))))
  
    (setq y (MakeLong (MakeWord 194 122) (MakeWord 133 144)))
    (vla-put-EntityColor color y)

    (setq modelSpace (vla-get-ModelSpace doc))
    (setq line (CreateLine))
    (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)))))

    (vlax-release-object color)
)


(defun CreateLine()
    (setq acadObj (vlax-get-acad-object))
    (setq 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))  
    (setq 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-5-12 01:03

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部