Some VBA toolbox questions (R. Robert Bell, are you out there?)

Discussion in 'AutoCAD' started by Gordon Price, Jan 8, 2004.

  1. Gordon Price

    Gordon Price Guest

    I have finally given up on doing a Vlisp based layer management tool. I just
    can't get Mtext and Dimensions to work like I want. SO I am looking at
    making layer management event driven with VBA, which I think is really a
    better solution, at least conceptually.
    In trying to emulate the system usually used in Lisp, I would use
    BeginCommand and EndCommend events, and set layers and such accordingly.
    However, I see some issues.
    1: How do you handle canceled commands? There doesn't seem to be a
    CommandCanceled event, without which you can't cleanup.
    2: How do you handle commands in lisp? Events would fire for every (command
    "XXX") in your lisp code as well. Do you handle this by flagging a lisp as
    active and suspending your layer management code when the command comes from
    inside lisp?
    3: How do you make sure both command events bracket a single command, so
    that you can reset clayer and such after the command ends? Or is the only
    way to nest commands with transparent commands that you don't react to. I
    guess you could set a variable to the command name you did manage layers on,
    and then in the EndCommand event check to see that the ended command is the
    one in question and cleanup if so. Again, pretty ugly if the user cancels
    and you can't see that event.

    Having looked at all of this, one thought is to use a single ObjectAdded
    event, and change the layer of the object after the fact. This works until
    the user changes the layer of an object for good reason, then copies it, and
    the new object is forced back to the old layer. I guess you could use
    BeginCommand to store what command was in effect, then if the user uses
    Mtext, force the layer, but if using copy don't? Any thoughts?

    Lastly, I only find TrueColor as a property. Now, I can use TrueColor to
    create a layer of color 30, but it shows up in the layer list as the RGB
    numbers, not 30. Long term this is not a huge deal, but right now I am
    working my users into STBs and freaking them out with new color numbers is
    not high on my list, not to mention the TrueColor RGB value just takes up
    too much space. Is there a way to assign an indexed color # in VBA?

    Has anyone gone down this road in VBA? Is there a spiffy website dealing
    with how to do this? Mr. Bell, are you planning a VBA version of your
    excellent Error Handling AUGI/AU class? Hint, hint ;)

    Best,
    Gordon
     
    Gordon Price, Jan 8, 2004
    #1
  2. Gordon, comments in-line. Others, please jump in where you see the need to.

    | I have finally given up on doing a Vlisp based layer management tool. I
    just
    | can't get Mtext and Dimensions to work like I want. SO I am looking at
    | making layer management event driven with VBA, which I think is really a
    | better solution, at least conceptually.
    | In trying to emulate the system usually used in Lisp, I would use
    | BeginCommand and EndCommend events, and set layers and such accordingly.
    | However, I see some issues.


    EndCommand events can hose the Undo facility, so you need to be careful
    there.


    | 1: How do you handle canceled commands? There doesn't seem to be a
    | CommandCanceled event, without which you can't cleanup.


    There is no CommandCanceled event, curses. I haven't sweated it myself, but
    I have seen some code that sets a flag during the prior command event, and a
    new BeginCommand checks that flag to do a reset. I'm not thrilled with that
    either. 8^(


    | 2: How do you handle commands in lisp? Events would fire for every
    (command
    | "XXX") in your lisp code as well. Do you handle this by flagging a lisp as
    | active and suspending your layer management code when the command comes
    from
    | inside lisp?


    The Begin/EndLISP events help here.


    | 3: How do you make sure both command events bracket a single command, so
    | that you can reset clayer and such after the command ends? Or is the only
    | way to nest commands with transparent commands that you don't react to. I
    | guess you could set a variable to the command name you did manage layers
    on,
    | and then in the EndCommand event check to see that the ended command is
    the
    | one in question and cleanup if so. Again, pretty ugly if the user cancels
    | and you can't see that event.


    This is why I try to post-process. Too many problems can crop up.


    | Having looked at all of this, one thought is to use a single ObjectAdded
    | event, and change the layer of the object after the fact. This works until
    | the user changes the layer of an object for good reason, then copies it,
    and
    | the new object is forced back to the old layer. I guess you could use
    | BeginCommand to store what command was in effect, then if the user uses
    | Mtext, force the layer, but if using copy don't? Any thoughts?


    That is a sound approach. However, ObjectAdded can get very busy so you need
    to account for performance issues too.


    | Lastly, I only find TrueColor as a property. Now, I can use TrueColor to
    | create a layer of color 30, but it shows up in the layer list as the RGB
    | numbers, not 30. Long term this is not a huge deal, but right now I am
    | working my users into STBs and freaking them out with new color numbers is
    | not high on my list, not to mention the TrueColor RGB value just takes up
    | too much space. Is there a way to assign an indexed color # in VBA?


    Sub Test()
    Dim aLayer As AcadLayer
    Set aLayer = ThisDrawing.Layers.Add("Test")

    Dim aColor As AcadAcCmColor
    Set aColor = New AcadAcCmColor
    aColor.ColorIndex = 30

    aLayer.TrueColor = aColor
    End Sub


    | Has anyone gone down this road in VBA? Is there a spiffy website dealing
    | with how to do this? Mr. Bell, are you planning a VBA version of your
    | excellent Error Handling AUGI/AU class? Hint, hint ;)


    There aren't any errors possible in VBA, are there?! (I'm too stinking busy
    to do any class coursework right now, sad to say.) But thanks for the kind
    words.
     
    R. Robert Bell, Jan 8, 2004
    #2
  3. Gordon Price

    Gordon Price Guest

    That is a sound approach. However, ObjectAdded can get very busy so you
    need
    Hmm. Tried some big copy/pastes, with the ObjectAdded just counting, and it
    was SLOW... So I wonder, can you 'disable' an event? In other words, could I
    have an ObjectAdded event that normally doesn't do anything. Then I use the
    BeginCommand event to toggle ObjectAdded 'on' for particular commands?
    SOmehow I think I really should learn C#.net huh? ;)

    Gordon
     
    Gordon Price, Jan 9, 2004
    #3
  4. Think flag...

    --
    R. Robert Bell, MCSE
    www.AcadX.com


    | > That is a sound approach. However, ObjectAdded can get very busy so you
    | need
    | > to account for performance issues too.
    |
    | Hmm. Tried some big copy/pastes, with the ObjectAdded just counting, and
    it
    | was SLOW... So I wonder, can you 'disable' an event? In other words, could
    I
    | have an ObjectAdded event that normally doesn't do anything. Then I use
    the
    | BeginCommand event to toggle ObjectAdded 'on' for particular commands?
    | SOmehow I think I really should learn C#.net huh? ;)
    |
    | Gordon
    |
    |
     
    R. Robert Bell, Jan 9, 2004
    #4
  5. Gordon, I utilize the ObjectAdded event to autolayer text, dims, and such.
    Of the nearly 100 users currently using the system, never has one of them
    ever complained about it being slow. I'm willing to bet that the amount of
    time saved in 15 or so minutes of drafting and not worrying about layering
    anything more than makes up for any extra time that it may take to
    copy/paste even large amounts of drawing objects.

    <deleted paragraph that sounded way to preachy on second read thru>

    TGIF!
     
    Bobby C. Jones, Jan 9, 2004
    #5
  6. You're back!


    "Bobby C. Jones" <bobbyj (at) acadx (dot) com> wrote in message
    |
    | TGIF!
     
    R. Robert Bell, Jan 9, 2004
    #6
  7. Gordon Price

    Gordon Price Guest

    Hmm. I agree the pause is minor, certainly less than that which is saved.
    However, I am running into new problems (see my other post about
    ObjectAdded). Any chance you could jot down in pseudo-code how you are doing
    this? You mention doing it with text and dims, perhaps you are not doing it
    with blocks (where my current brain flatulance is happening)?

    Thanks,
    Gordon
    (in frozen disfunctional, burried under SIX INCHES of snow, Portland. No
    comments from those in the NE & MW please.)
     
    Gordon Price, Jan 9, 2004
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.