give me a simple delphi+acad2004 example please

Discussion in 'AutoCAD' started by acader, Feb 16, 2004.

  1. acader

    acader Guest

    Such as "hello world" or drawing a line in modelspace.
    I need a simple one to begin my study.Tell me which library should and how to import?

    by the way, i can not visit Tony's web site.
    thanks
     
    acader, Feb 16, 2004
    #1
  2. acader

    acader Guest

    i find one, maybe someone else will need it. but who can tell me something about the library which should be imported?

    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;
     
    acader, Feb 16, 2004
    #2
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.