Our Friends: Leaflet Printing , Presented by: Talia Cad Software

Sign In

Subscribe

Subscribe to Daily Autocad.


Nov 26
Monday
Autocad, Programming, VBA
My first VBA application in AutoCAD

AutoCAD 13 & higher versions

There is no doubt that the most important difference of Autocad from any other CAD software is its various tools of customization and automation. Some macro programmes can be written and managed in Autocad to ease the routine works. Although VBA (Visual Basic Application) has the whole control, loop etc. mechanisms of Basic Language, it lacks some options compared to the other versions of Visual Basic. The one who knows even a little about Basic Language and/or uses one of Visual Basic IDE can get used to VBA for Autocad very easily.

VBA.IDE that is integrated in Autocad can be opened by clicking the ‘Visual Basic Editor’ in macro line in Tools menu. If ‘Toolbox’ does not exist, just select it form the ‘View’ menu.

Fig.1
Figure.1

The Toolbox Menu icludes the controls the interfaces of the macros that you prepare.

Fig.2
Figure.2

A new form will be added when you apply the steps seen in Figure.2. The desired control is selected by clicking in the “Toolbox Menu” and it is placed by clicking the appropriate button in the form.

Let us attach a Command Button, two Text Box and a Label to our form by the method shown in Figure.1.

Fig.3
Figure.3

Change the box as ‘Sum‘ that corresponds to ‘Caption’ box in the ‘Properties’ window by selecting the CommandButton of the form we have added. Set the ‘TextAlign’ property in the same window as it is in the figure below.

Fig.4
Figure.4

Fig.5
Figure.5

We have just prepared the form that we will use. Next step is assigning an event to the Button.

Double click the button in the form. The code page and the lines below should be opened.

Private Sub CommandButton1_Click()

'''your code here

End Sub

Add the

Label1.Caption = Val(TextBox1.Text) + Val(TextBox2.Text)

Code between the lines above. Now we can run the macro. It can be done by selecting the ‘Run Sub/UserForm’ in the Run Menu.

Fig.6
Figure.6

The sum of the numbers are printed automatically in the label control when you write some numbers into the two Text Box and click the button.

Label1.Caption

expression means the caption property of the label control that we have just changed in the Properties window.

TextBox1.Text

expression means the Text property of the TextBox1. By means of the Val() function, the content is changed into a numerical value.

The same process is done for the TextBox2. They are summed and transferred to the caption property of the + label control.

VBA Mathematical Operations and Process Priorities

^ Exponential operator.
* Multiplication operator.
/ Real division operator. (Ex:5/2=2.5)
\ Integer division operator. (Ex:5\2=2)
Mod Mod operator. (Ex:5 Mod 2)
+ Summation operator.
- Subtraction operator.

We gave general information about the usage of VBA in Autocad and explained how a VBA macro is run. Besides, some basic properties of Visual Basic Language was studied. But this is not the limit of the usage of VBA for Autocad and OLE (ActiveX, COM). We will study this subject in more detail in coming lessons.

Regards.

Read in other languages: TR

Technorati Tags: , ,

Viewed 8,913 times so far... This week: 82 Today: 4 Latest: 5 July 2009, 2:47

Post Tags:

9 Responses to “ My first VBA application in AutoCAD ”
  1. Microsft has said that it will no longer continue developing VBA – if you are starting a language it’s a good idea to look at VB.Net or C#.Net because they have a brighter future.
    http://www.3DCADMax.com

  2. I work with a company that uses metric data, but wants it displayed imperical. We have to do the conversion from imperical to metric. I would like a script that will do this for me as I am entering the imperical number on the command line.

    Thanks

  3. I just learnt ACAD… i have some programming knowledge but i dont know how to start programming in ACAD… what should i keep in mind and what should i practice on…..???
    please do give me some tips
    Regards
    Imran

  4. ghassan mansour

    May 31, 2008
    Reply

    Ghassan mansour

    I just learnt ACAD… i have some programming knowledge but i dont know how to start programming in ACAD… what should i keep in mind and what should i practice on…..???
    please do give me some tips
    Regards

    ghassan mansour

  5. SATISH ALETI

    Jun 24, 2008
    Reply

    Yeah it is fine, but how it is going to be useful for autocad.

    I need to do programming for autocad using vb6.0 and i need code for creation of autocad files

  6. suresh Nair

    Sep 2, 2008
    Reply

    I am working on a program in VB where i am stuck and need your assistance.
    I would like to have the code to draw a rectangular array in autocad. I am a begener and need your assistance.

  7. the autocad program is afuture programing but as u see the grate way to start is not the lange vba or vb6 or vb.net op c++ is waht u want to do in autocad

  8. Hi Hugh Compton
    > Microsft has said that it will no longer continue developing VBA
    There has been some inaccurate information circulating online regarding VBA, please, see:
    http://blogs.msdn.com/excel/archive/2008/01/16/clarification-on-vba-support.aspx

    Regards,

    David

  9. I am working on a program in VB6  where i am stuck and need your assistance.
    I would like to have the code to draw a rectangular array in autocad. I am a begener and need your assistance.


Post a Comment



All content and source © 2008 Daily Autocad | News Plus wordpress theme brought to you by Zidalgo.