CAD CAM CAE - CADinfo.net - home

 microsites>> SmartDraw - CAD results without CAD hassles  

CAD, CAM, CAE, design, technical drawing, drafting, delineation, visualization, manufacturing ISSN 1442-2255 : 5/10/2008 - 2:06:52 AM
 

Rubber Stamp Program

VBA Preview in IntelliCAD 98

Frank Zander

VBA has fired the curiosity of many IntelliCAD users. In Part I, Frank Zander explored some of the working and non-working parts of IntelliCAD's Preview VBA. Now, for the adventurous, in Part II he shows how to create a small 'rubber-stamp' program in IntelliCAD's working VBA environment

I wanted to create a simple program that would be useful to all IntelliCAD users and not be specific to one discipline (i.e., Mechanical, Structural, or Architectural, etc.). I also wanted to create a very simple program that would be easy for the non-programmer to create and understand. Hopefully I have achieved this with the rubber stamp program.

Rubber Stamp program

The "rubber stamp" program gets the drawing name and path information from the active document. The current Windows system time is captured and several items are presented to the user to select the type of "stamp" to place on the drawing. The rubber stamp program then places a Mtext object in the drawing when the user presses the Stamp button. The resulting Mtext object is placed in the drawing at coordinates 1,1 with the drawing information as shown in the rubber stamp user interface.

For this example, the information is:

Drawing: d:\drawings\copper sky\schooner.dwg

Date: 07/08/98 10:50:30 AM

Stamp: As Built

To make the rubber stamp project:

At the IntelliCAD command prompt type VBA.

Create a Form. From the pull-down menus in the VBA interface select Insert > UserForm.

From the Properties Window (press F4 to activate) change the Caption of the UserForm1 to rubber stamp.

Create the Exit command button; select the Command Button control from the Toolbox, place your mouse over the Form and draw a rectangle to create the button.

Select the command button control

Change the command button to display Exit rather than the current text CommandButton1. To change the text CommandButton1 to Exit, look at the Properties Window (F4) displaying properties-commandbutton1 — change the Caption information from CommandButton1 to Exit. Slowly double-click the CommandButton1 on the Form and edit the text in-place. The commandbutton1 should now display Exit.

Setup the click event on the Exit button. So far the command button is in location and shows Exit, but does nothing. Why? You have not assigned an event to the command button.

What is an event? An event is what happens when a user changes something or interacts with a program. The event you want to monitor is when the user clicks the Exit button. Double-click the Exit Command Button quickly. Notice that VBA view window changes to a View Code window. Also notice that you are presented with the code following:

Private Sub CommandButton1_Click()

End Sub

In between the Private Sub CommanButton1_Click() and the End Sub is where you write code. Add the code Unload UserForm1.

Save your project.

Run the project. Press F5 or select the pull-down menu Run > Sub/UserForm.

To exit your program click the Exit button you just created.

Create the stamp button using the same technique described at step 4 above. Fill in the code for CommandButton2 as shown in the code section next section.

Create the Textbox1, TextBox2 and TextBox3 on the UserForm1 by selecting the TextBox control in the Toolbox and draw three textboxs on the Form.

Copy the code from Private Sub UserForm_Initialize() to End Sub to setup the information that is displayed in the Form as it is initialized (loaded).

Save your project.

Run your project

Press F5 or select the pull-down menu Run > Sub/UserForm.

Select the Stamp Options Combo Box to choose the appropriate stamp type. Press the Stamp button to place the stamp in the drawing.

Note: The drawing will need to be regenerated and zoomed to the extents to see the stamp.

The Code

Private Sub CommandButton1_Click()
' This code is for the Exit button
Unload UserForm1
End Sub

Private Sub CommandButton2_Click()
' This code is for the Stamp button
' Information filled out/displayed on the UserForm1 is
' placed into drawing

Dim CADD As Object
Dim Doc As Object
Dim NewText As Object
Dim pt1 As Object
Dim StampText As String
Dim TextOut As String
Dim NewSS As Object
Dim myCommand As Object

' Hide the UserForm1
UserForm1.Hide

' Get the information/selection of the Stamp ComboBox1
If ComboBox1.ListIndex <> -1 Then
StampText = ComboBox1.List(ComboBox1.ListIndex)
End If

' Text information from the UserForm1 to place
' in the drawing as MText
TextOut = "Drawing: " & TextBox1.Text & "\P" & _
"Date: " & TextBox2.Text & "\P" & _
"Stamp: " & StampText & "\P"

' Specify the insert point of the text at location 1,1
Set pt1 = Library.CreatePoint(1, 1)

' Get the IntelliCAD application as an object
Set CADD = GetObject(, "icad.application")

' Get the current IntelliCAD Document/Drawing
Set Doc = CADD.ActiveDocument

' Add a MText object to the drawing
Set NewText = ActiveDocument.Entities.AddMText(pt1, 8, TextOut)

' Display a message box to the user that the drawing
' requires a Regen to see new Stamp
MsgBox "Drawing Requires a redraw or Regen to see Stamp"

' *** To redisplay the UserForm1 uncomment the
' line below...
' UserForm1.Show
Unload UserForm1
End Sub

Private Sub UserForm_Initialize()

' When UserForm1 loads (Initializes) the
' following information is filled out in
' the appropriate areas.

Dim CADD As Object
Dim Doc As Object

' *** To run the program with AutoCAD uncomment
' the line below...
' Set CADD = GetObject(, "autocad.application")

' *** To run the program with AutoCAD comment
' out the line below...
Set CADD = GetObject(, "icad.application")

' Get the active Document in the running CADD program
Set Doc = CADD.ActiveDocument

' Fill in the "text" value in TextBox1 on the
' UserForm1 to have the Document Path shown
TextBox1.Text = Doc.Path

' Fill in the "text" value in TextBox2 to have
' the current system date
TextBox2.Text = CDate(Now)

' Add selections to the Stamp Options ComboBox1
ComboBox1.AddItem ("Plot")
ComboBox1.AddItem ("Check Plot")
ComboBox1.AddItem ("For Approval")
ComboBox1.AddItem ("Approved")
ComboBox1.AddItem ("As Built")
ComboBox1.AddItem ("Proposal")
ComboBox1.AddItem ("Confidential")
ComboBox1.AddItem ("Top Secret")

' Set the default displayed information in
' ComboBox1 to ListIndex 0
' the 0 list index in this case is the Item "Plot"
ComboBox1.ListIndex = 0

End Sub

Cut-and-paste the code from your browser or download the code as an IntelliCAD VBA project (STAMP.ZIP 18Kb - contains STAMP.VBI)

Conclusion

IntelliCAD has laid out the groundwork for future releases of VBA in IntelliCAD. IntelliCAD has an extensive object library and library of object functions. However, I found current preview VBA in IntelliCAD to be at an almost "beta" stage of implementation. Many of the drawing object and object functions do not operate. I look forward to a future release of IntelliCAD that fully implements all drawing objects in VBA.

This article was originally published in Technical Design Solutions
© 1998 ConnectPress Ltd
Re-published by permission

Please rate our article...
Click on a button to rate this article Click on a button to rate this article

Click to tell a friend about this page...

 

 

Sponsored Links

AnyDWG Offers DWG to PDF, DWG to DXF, PDF to DWG, DWG to JPG, PDF to DXF Converters

AutoDWG offers DWF to DWG, DWG to PDF , PDF to DWG, DWG to Flash Converters, DWG Viewer.

eCampus.com
Get your stuff for College... Cheap!
Textbooks, Greek Gear, DVD's, University Clothing, Computers and MORE!

Access Your PC from Anywhere
Free Trial plus 10% Off!

 

 

Footer
   
All rights reserved © 1996-2007 Digital Business Media Pty Ltd  home : editorial archive : contact : legal