EntityColor Example |
Using Programming Languages other than VBA
Sub Example_EntityColor() Dim color As AcadAcCmColor Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.16") 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
Comments? |