See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Color Dialog in VBA

  1. #1
    100 Club KevinBarnett's Avatar
    Join Date
    2001-10
    Location
    Pretoria, South Africa
    Posts
    119
    Login to Give a bone
    0

    Question Color Dialog in VBA

    Greetings Gang,

    Is there a way to call the color dialog in Acad 2005's VBA?

    I am still using the VLAX class to call the dialog in lisp - I hope this isnt the only way.

    TIA,

    Kevin.

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,419
    Login to Give a bone
    0

    Default Re: Color Dialog in VBA

    Here's two different methods.

    Code:
    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
    
    Public Function AcadFileDialog(DlgTitle As String, _
                    Optional DefaultFile As String = "", _
                    Optional Ext As String = "*", _
                    Optional Flag As Integer = 0) As String
        'calls the acad file dialog and returns
        'the file name or a null string "" if cancelled
        'for a list of available flags, see help for (getfiled).
        Dim strFileName As String
        'store current sysvar value
        strFileName = ThisDrawing.GetVariable("USERS5")
        'call color dialog
        ThisDrawing.SendCommand ("(setq fn (getfiled """ & DlgTitle & _
            """ """ & DefaultFile & """ """ & Ext & """ " & Flag & "))" & vbCr)
        ThisDrawing.SendCommand ("(if (= fn nil)" & _
                                 "(setvar ""USERS5"" """")" & _
                                 "(setvar ""USERS5"" fn))" & vbCr)
        AcadFileDialog = ThisDrawing.GetVariable("USERS5")
        'reset sysvar
        ThisDrawing.SetVariable "USERS5", strFileName
    End Function
    C:> ED WORKING....


    LinkedIn

  3. #3
    Member
    Join Date
    2006-01
    Posts
    9
    Login to Give a bone
    0

    Default Re: Color Dialog in VBA

    Well, when I start macro it says:

    'User-defined type not defined.'
    'DIM vl As New VLAX'

    Maybe I need to add Reference?
    I'm using Civil3D 2007, WinXP SP2


    Quote Originally Posted by Ed Jobe View Post
    Here's two different methods.

    Code:
    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
    
    Public Function AcadFileDialog(DlgTitle As String, _
                    Optional DefaultFile As String = "", _
                    Optional Ext As String = "*", _
                    Optional Flag As Integer = 0) As String
        'calls the acad file dialog and returns
        'the file name or a null string "" if cancelled
        'for a list of available flags, see help for (getfiled).
        Dim strFileName As String
        'store current sysvar value
        strFileName = ThisDrawing.GetVariable("USERS5")
        'call color dialog
        ThisDrawing.SendCommand ("(setq fn (getfiled """ & DlgTitle & _
            """ """ & DefaultFile & """ """ & Ext & """ " & Flag & "))" & vbCr)
        ThisDrawing.SendCommand ("(if (= fn nil)" & _
                                 "(setvar ""USERS5"" """")" & _
                                 "(setvar ""USERS5"" fn))" & vbCr)
        AcadFileDialog = ThisDrawing.GetVariable("USERS5")
        'reset sysvar
        ThisDrawing.SetVariable "USERS5", strFileName
    End Function

  4. #4
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,419
    Login to Give a bone
    0

    Default Re: Color Dialog in VBA

    Search this forum for "vlax.cls". Its a class that allows you to execute lisp from vba.
    C:> ED WORKING....


    LinkedIn

  5. #5
    Member
    Join Date
    2006-01
    Posts
    9
    Login to Give a bone
    0

    Default Re: Color Dialog in VBA

    Thanks!
    Works fine!

    Can You give me brief axplanation haw to call a lisp dialog
    and retrieve data from it in VBA?

    I sow the functions of VLAX but I'm new to Lisp.

  6. #6
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,419
    Login to Give a bone
    0

    Default Re: Color Dialog in VBA

    Its much easier to use a vba form.
    C:> ED WORKING....


    LinkedIn

  7. #7
    Member
    Join Date
    2006-01
    Posts
    9
    Login to Give a bone
    0

    Default Re: Color Dialog in VBA

    Ok, I agree!

    But, look of the form designed in VBA is poor against the look of the dcl dialog.
    Dcl is more CAD-like.

  8. #8
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    1

    Default Re: Color Dialog in VBA

    If you want to avoid using "SendCommand", try this.

    PHP Code:
    Public Declare Function acedSetColorDialog Lib "acad.exe" (color As LongByVal bAllowMetaColor As BooleanByVal nCurLayerColor As Long) As Boolean

    Sub example_usage
    ()
     
    On Error Resume Next
     Dim blnMetaColor 
    As Boolean
     Dim lngCurClr 
    As Long
     Dim lngInitClr 
    As Long
     
    If acedSetColorDialog(lngInitClrblnMetaColorlngCurClrThen
        MsgBox lngInitClr
     End 
    If
    End Sub 
    R.K. McSwain | CAD Panacea |

  9. #9
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,419
    Login to Give a bone
    0

    Default Re: Color Dialog in VBA

    Quote Originally Posted by branimirj View Post
    Dcl is more CAD-like.
    I didn't know there was such a thing as "CAD-like". AutoCAD is a Windows program and vba uses Windows controls. You can design a dialog to look like dcl if you choose to.

    Anyway, I haven't tried calling a dcl dialog directly from vba. It works on lisp reactors. So it would probably be simplest to have a lisp front-end to the dialog, i.e. instead of calling the dialog from vba, create a function that calls it and returns a value. Then you can call that function from vba. However,
    C:> ED WORKING....


    LinkedIn

  10. #10
    Member
    Join Date
    2006-01
    Posts
    9
    Login to Give a bone
    0

    Default Re: Color Dialog in VBA

    Cheers!

    Well I'll try to explain what I meant by the CAD-like form.
    There are rounded corners in the frame, while line and text are colored.
    When you move the mouse near form object (CheckBox for example) it appears colored and so on (like rollover effect on web page).
    In VBA forms there are no such stuff.

    Background story of the idea is to use dlg instead of VBA forms.
    In routine that I created in VBA (it was finished and works fine), there are a lot of user inputs and I spend lots of time to design well organized form.
    For example when I take a look at the Plot Dialog, it has many information on it and they are still well organized. I think maybe I will achieve the same result by using dlg dialogs.

    I can send You screens to see what I mean, if You are interested.

Page 1 of 2 12 LastLast

Similar Threads

  1. Calling Revit's native color dialog
    By some buddy in forum Revit - API
    Replies: 11
    Last Post: 2009-10-08, 02:18 PM
  2. Color dialog - highlight box system variable?
    By Coolmo in forum AutoCAD General
    Replies: 1
    Last Post: 2006-03-22, 12:59 AM
  3. Color Dialog Box Not Showing Up.
    By tmccoy in forum AutoCAD General
    Replies: 4
    Last Post: 2006-01-07, 01:17 AM
  4. MTEXT dialog box background color
    By ldibenedetto in forum AutoCAD Wish List
    Replies: 6
    Last Post: 2005-01-31, 01:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •