What triggers events in autocad vba?

Posted on 2009-04-22
Last Modified: 2013-12-04
So I just started programming in Autocad VBA.  I have have list events, but not what triggers them.  Does anyone have a good reference that tells what they all mean.  Some are obvious, but some aren't.  What I need right now is to know if adding a project triggers an event, and if so, which one.  (Tools->Macro->VBA Manager->New)
Question by:iwtblj247
    LVL 10

    Accepted Solution

    It sounds like you are referring to the basics of Object Oriented Programming. Start with the Help in AutoCAD and do a few starter exercises. These may help also.
    LVL 11

    Expert Comment

    Without trying all of them, you can only make a guess.

    I doubt ARXLoaded will do it although it would if you were ARX programming.

    Modified may do it but I doubt it, it's designed for things like layers or entities. MAybe VBA projects are internally stored in a way they would trigger it but I don't think so.

    Same with ObjectAdded,ObjectModified,ObjectErased I would guess those won't either...less lileky than  the Modified event.

    SysVarChanged but it would depend if loading a new VBA project changed any sysvars. I'm not aware if any iff the top of my head but I didn't look either so there may be.

    Your best bet is the EndCommand event where you'd have to then check which command just ended.

    The others I wouldn't even bother to try.

    I wounldn't spend much time with VBA. Microsoft doesn't support it any longer and Autodesk is providing it only as an additinoal download and install. Might better try Lisp or VB.Net/C#.


    Expert Comment


    Hi iwtblj247,

    You're Q is not entirely clear to me, buy you should think of AuotCAD VBA just as all OOP:
    Study the objectmodel. Forn there you'll get the idea of it all.

    Any app notices the windows event loop, so to build an ACAD app is the easyest w. a VBA dialog responce.

    Here's a sample:
    Make a form with a textbox : Text1
                                3 buttons : cmdHelp, cmdCancel  and cmdApply
                     and a spinbutton : SpinButton1
    Now, add the code as shown in the Snippet

    'the form - frmChangePoly
    Option Explicit
    Private Sub cmdApply_Click()
    '           ==============
        Dim elem As Object
        Dim Width As Double
        Width = CDbl(Text1.Text)
        If Width < 0# Then
            MsgBox "Please enter a positive value for the width"
            For Each elem In ThisDrawing.ModelSpace
                With elem
                    If StrComp(.ObjectName, "AcDbPolyLine", 1) = 0 Then
                        ' there's a hit..
                        .ConstantWidth = Width
                        '.Update  ' Uncomment to see each change
                    End If
                End With
            Next elem
            ThisDrawing.Application.Update ' Do one Update
        End If
    End Sub
    Private Sub cmdCancel_Click()
        Unload Me
    End Sub
    Private Sub cmdHelp_Click()
        MsgBox "Changes the width of all polylines in ModelSpace." & Chr(13) & Chr(13) _
        & "You must first draw a polyline using the PLINE command."
    End Sub
    Private Sub SpinButton1_Change()
        Text1.Text = SpinButton1.Value / 10
    End Sub
    ' === EOF ===
    'The module - modChangePoly
    Option Explicit
    Sub ChgPolyWidth()
    End Sub
    '=== EOF ===

    Open in new window

    LVL 11

    Expert Comment

    Did you still need assistance with this issue? Let us know and we'll try to help out.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    If, like me, you find yourself repeatedly and tediously joining many segments (lines, arcs) in other people's drawings back into polylines that can be used more effectively in Computer Aided Machining and Laser Cutting, then this article is for you!…
    The following article will describe how to add/edit a dimension style through AutoCAD VBA. AutoCAD VBA has its quirks and when it comes to dimensions and controlling how they look through VBA.  This is where AutoCAD can be vividly confusing. The…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now