P
pharaoh
Unregistered / Unconfirmed
GUEST, unregistred user!
请问如何用C#控制AutoCAD?
下面的是一段Delphi代码,主要是打开AutoCAD,绘制一些直线和圆弧等,请问如何在
C#中实现?
下面的是一段Delphi代码,主要是打开AutoCAD,绘制一些直线和圆弧等,请问如何在
C#中实现?
代码:
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;