AutoCAD Color Selector

AutoCAD Color Selector

Anonymous
Not applicable
1,458 Views
10 Replies
Message 1 of 11

AutoCAD Color Selector

Anonymous
Not applicable
What library can I find the AutoCAD standard color selector in? Is it
documented anywhere? What methods and properties does it have?
Thanks,
Kenneth Hutson
San Antonio, TX
0 Likes
1,459 Views
10 Replies
Replies (10)
Message 2 of 11

RonnieWilkins
Advocate
Advocate
http://discussion.autodesk.com/thread.jspa?messageID=4164145
Ronnie Wilkins, Jr.
0 Likes
Message 3 of 11

fxcastil
Advocate
Advocate
Kenneth ,

There is no Acad color library, but you can use the Acad Color
selector used in the layer manager.
I got this Lisp routine from someone on this group. This is any easy way to show the color dialog box and get the value of the color selected from lisp to VBA using USERI5 variable.

Search this group for USERI if you do not know about these acad internal variables.


Public Function ColorDialog() As Integer

Dim intVariable As Integer

If Connect Then
objAcad.Application.WindowState = acMin
'calls the acad color dialog and returns
'the index of the color selected or -1 if cancelled
'store current sysvar value
intVariable = ThisDrawing1.GetVariable("USERI5")
'call color dialog
ThisDrawing1.SendCommand ("(setq clr (acad_colordlg 1))" & vbCr)
ThisDrawing1.SendCommand ("(if (= clr nil)" & _
"(setvar ""USERI5"" -1)" & _
"(setvar ""USERI5"" clr))" & vbCr)
ColorDialog = ThisDrawing1.GetVariable("USERI5")
'reset sysvar
ThisDrawing1.SetVariable "USERI5", intVariable
End If


Fred C.
0 Likes
Message 4 of 11

Anonymous
Not applicable
Fred,
You need to be careful with that function. Since it utilizes SendCommnad,
its likely you will not get the correct value. Use the vlisp interface to
set the sysvar. Better yet use the vlisp interface to return the value
directly to vba.

--
----
Ed
----
wrote in message news:5020375@discussion.autodesk.com...
Kenneth ,

There is no Acad color library, but you can use the Acad Color
selector used in the layer manager.
I got this Lisp routine from someone on this group. This is any easy way to
show the color dialog box and get the value of the color selected from lisp
to VBA using USERI5 variable.

Search this group for USERI if you do not know about these acad internal
variables.


Public Function ColorDialog() As Integer

Dim intVariable As Integer

If Connect Then
objAcad.Application.WindowState = acMin
'calls the acad color dialog and returns
'the index of the color selected or -1 if cancelled
'store current sysvar value
intVariable = ThisDrawing1.GetVariable("USERI5")
'call color dialog
ThisDrawing1.SendCommand ("(setq clr (acad_colordlg 1))" & vbCr)
ThisDrawing1.SendCommand ("(if (= clr nil)" & _
"(setvar ""USERI5"" -1)" & _
"(setvar ""USERI5"" clr))" & vbCr)
ColorDialog = ThisDrawing1.GetVariable("USERI5")
'reset sysvar
ThisDrawing1.SetVariable "USERI5", intVariable
End If


Fred C.
0 Likes
Message 5 of 11

fxcastil
Advocate
Advocate
Ed,

You say "Since it utilizes SendCommnad, its likely you will not get the correct value" Several users have been using this function and have been getting the correct color value. Can you elaborate and maybe show example of using Vlisp interface. I have searched the group for "Vlisp Interface "
and I am not sure how to do this .

Thanks,
Fred Castillo
0 Likes
Message 6 of 11

Anonymous
Not applicable
Well, the SendCommand method is asyncronous and may (likely) run after your
vba code completes. Here is a possible sequence of events.
1. Call main function
2. dwg variable = 0
3. issue lisp via SendCommand
4. function returns 0 from dwg variable
5. SendCommand finishes
6. dwg variable = some #

The big problem here is that the function has no way to validate the data
stored in the dwg variable.

The visual lisp interface can be accessed using:
Set vl = ThisDrawing.Application.GetInterfaceObject("VL.Application.1")

You can download vlax.cls from www.acadx.com which makes using vl easy.

I wrote this function for use with vlax.cls.

Public Function AcadColorDialog() As Integer
'calls the acad color dialog and returns
'the index of the color selected or -1 if cancelled
Dim i As Integer
Dim vl As New VLAX

'call color dialog
vl.EvalLispExpression ("(setq clr (acad_colordlg 1))")
'if dialog was canceled, clr will be nil, set to -1 instead
i = vl.EvalLispExpression("(if (= clr nil)(setq clr -1)(setq clr clr))")
AcadColorDialog = i
Set vl = Nothing
End Function

You can use a similar method with the (getfiled) function if you need to use
acad's dialog rather than a vba dialog.

Another way I forgot about is mentioned here:
http://discussion.autodesk.com/thread.jspa?messageID=4147470

--
----
Ed
----
0 Likes
Message 7 of 11

fxcastil
Advocate
Advocate
Ed,

I am attaching my attempt at using the vlax.cls , I added reference to vlisp.tlb . But I do not see anyting in object browser with "Attribute" . I see this at top of vlax.cls ??
I use VBA not lisp or Vlisp so I am stuck in the mud. Searched the post looked at curve.cls sample at acadx.com same stuff at header, get error at stuff below.

BEGIN
MultiUse = -1 'True
End

Attribute VB_Name = "VLAX"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False

Thanks again,
Fred C
0 Likes
Message 8 of 11

Anonymous
Not applicable
The answer is to delete the red stuff (all the items that show up in red are not needed for vba)
0 Likes
Message 9 of 11

Anonymous
Not applicable
Not sure why you are recieving an error. None of that should even show up in
the ide. Did you just copy the code into a code module or did you import the
class from file?

--
----
Ed
----
0 Likes
Message 10 of 11

fxcastil
Advocate
Advocate
Ed,

I had copied and pasted this into a class module , I now imported this as file . Now it works , this was too easy !

Thanks Again

Fred C.
0 Likes
Message 11 of 11

Anonymous
Not applicable
Great.

--
----
Ed
----
0 Likes