A Sip From The Firehose: Tuesday, May 5, 1998

By: David Intersimone

Abstract: Red Hot Salsa Drawings with Borland Delphi 3 and Autodesk's AutoCAD Release 14.

Tuesday, May 5 1998
Scotts Valley, California

Red Hot Salsa Drawings with Borland Delphi 3 and Autodesk's AutoCAD Release 14.

It is Cinco de Mayo and time for a fiesta! Cinco de Mayo celebrates the victory of the Mexican Army over the French at the Battle of Puebla, May 5 1862. To celebrate, I'll add a second recipe to "Betty Hacker's Down Home Developer's Cookbook" (the first recipe was the Fresh Blackberry Internet Browser). To add to your own cookbook just cut and paste the recipe included below. The new recipe allows developers to use AutoCAD Release 14 (R14) as a graphics rendering engine and control it from your Delphi applications. In R14, all object are exposed and are accessible using OLE automation. This capability allows developers to create (according to Autodesk) "object controllers, macros and even complete applications."


Betty Hacker's Quick 'n Easy
Red Hot Salsa Drawings
Delphi 3

To make the hottest salsa drawings you need the spiciest ingredients. To make the best tasting salsa you need the freshest ingredients. With Borland Delphi 3 and Autodesk's AutoCAD Release 14 you have two award winning ingredients to mix up a batch of the best Red Hot Salsa Drawings on the planet.

Ingredients:
5 pounds AutoCAD Release 14
2 pounds Delphi 3 (Professional or Client Server Suite strength)
1 blank Delphi form
1 TButton
19 helpings sample Delphi drawing source code
2 cups chopped tomatoes (your favorite variety)
2 cups chopped chiles (your favorite variety)
2 cloves garlic
1/2 cup chopped onions
1/4 cup fresh cilantro
1 pinch of salt
1 pinch of chili powder
1 bag taco chips
1 cold glass milk

Preparation:
Preheat your PC to 110 volts (220 volts for most developers outside the US).

To your hard drive bowl...
      Pour in AutoCAD Release 14
      Mix in Delphi 3

Chop and mix the Red Hot Salsa Drawing application.

Bunch of Peppers

Chop and mix the Red Hot Salsa Drawing application: Select File | New Application.

Fold in the form's caption: Set the Form's caption property to Automating AutoCAD R14 with Delphi 3 or your own caption text to taste.

Drop in a Button: From the Standard component palette page drop down a TButton control(size the button to taste). Set the Caption property to Click to make AutoCad R14 do something cool !.

Blend in an event handler for the Button: Double click on the button to create and event handler. Inside the event handler you can add the following code to drive the Red Hot Salsa Drawing. The code uses Delphi 3's CreateOleObject function to create an instance of the AutoCAD OLE automation object using the class name AutoCAD.Application.14. CreateOleObject returns a reference to the interface that is used to call the AutoCAD methods.

This code was given to me by one of the world's best Delphi developers and former member of the Delphi R&D team, Alain Tadros. Hats off to Lino for all his great work.

procedure TForm1.Button1Click(Sender: TObject);
var
 p1, p2, p3: OleVariant; // start & end points of line
 Mspace, Acad : OleVariant;
begin
  // Create variant arrays to hold coordinates
  // VT_R8 = 5; { 8 byte real defined in /Source/RTL/Win/ActiveX.Pas }
  p1 := VarArrayCreate([0, 2], VT_R8);
  p2 := VarArrayCreate([0, 2], VT_R8);
  p3 := VarArrayCreate([0, 2], VT_R8);
  // Assign values to array elements
  p1[0] := 2.0; p1[1] := 4.0; p1[2] := 0.0;// from 2,4,0
  p2[0] := 12.0; p2[1] := 14.0; p2[2] := 0.0; // to 12,14,0
  p3[0] := 7.0; p3[1] := 8.0; p3[2] := 0.0;
  // Get Application and ModelSpace objects:
  try
    // see if AutoCAD is already running
    Acad := GetActiveOleObject('AutoCAD.Application.14');
  except
    // if it is not running - start it up
    Acad:= CreateOleObject('AutoCad.Application.14');
  end;
  // bring AutoCAD to the windows desktop
  Acad.visible:= True;
  Mspace := Acad.ActiveDocument.ModelSpace;
  // use AutoCAD methods to draw a line and 3 circles
  Mspace.AddLine(VarArrayRef(p1), VarArrayRef(p2)).Update;
  MSpace.AddCircle(VarArrayRef(p1), 1.5).Update;
  MSpace.AddCircle(VarArrayRef(p2), 1).Update;
  MSpace.AddCircle(VarArrayRef(p3), 2.0).Update;
  // use AutoCAD methods to draw other shapes and text
  MSpace.AddArc(VarArrayRef(p3), 1.2, 1, 2).Update;
  MSpace.AddBox(VarArrayRef(p2), 5, 3, 2).Update;
  MSpace.AddCone(VarArrayRef(p1), 1.3, 2).Update;
  MSpace.AddCylinder(VarArrayRef(p3), 1.7, 1.5).Update;
  MSpace.AddMtext(VarArrayRef(p3), 10, 'Delphi 3 Rocks!!!').update;
end;

Chill for approximately 3-5 seconds or until the salsa is thoroughly blended.

Salsa and Chips

Combine all remaining salsa ingredients in a real bowl. Or better yet, go to your favorite store and pick up a jar of your favorite salsa.

Chill (hit the F9 key) for approximately 3-5 seconds or until salsa is thoroughly blended. Serve with the taco chips and that cold glass of milk or the beverage of your choice. If you follow the instructions carefully you should see the following result on your screen.

Yield:
One Red Hot Salsa Drawing application per developer.

Variations:
None

David Intersimone
davidi@inprise.com


Server Response from: BDN9A

 
© Copyright 2008 Embarcadero Technologies, Inc. All Rights Reserved. Contact Us   Site Map   Legal Notices   Privacy Policy   Report Software Piracy