- UID
- 447302
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2006-5-31
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2006-6-5 13:43:56
|
显示全部楼层
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleServer, AutoCAD_TLB, ExtCtrls, StdCtrls, ComObj, Math;
const
PI = 3.1415926535897932384626433;
ExtLine = 20;
Rmin = 3;
W = 8;
type
TMainForm = class(TForm)
Timer1: TTimer;
AcadDoc: TAcadDocument;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure AcadDocObjectAdded(ASender: TObject;
const Object_: IDispatch);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
LastDoc: string;
public
{ Public declarations }
function CreateDimStyle(AName:string): IAcadDimStyle;
function CreateLayer(AName: ACAD_LAYER; AColor: ACAD_COLOR;
ALineType: ACAD_LTYPE;
ALineWeight: ACAD_LWEIGHT = acLnWtByLwDefault;
ALineTypeFile: string = 'acadiso.lin'): IAcadLayer;
function CreateTextStyle(AName: string; AFontFile: string;
ABigFontFile: string;
AWidth: Double = 1;
AObliqueAngle: Double =0;
AHeight: Double = 0): IAcadTextStyle;
procedure DrawN1_N3(L, D, K, Df, C, Dk, Dp, tp, tw, tl: Double);
function FindDimStyle(AName: string; var AStyle: IAcadDimStyle): Boolean;
function FindLayer(AName: ACAD_LAYER; var ALayer: IAcadLayer): Boolean;
function FindLineType(AName: ACAD_LTYPE): Boolean;
function FindTextStyle(AName: string; var AStyle: IAcadTextStyle): Boolean;
function SetPoint(x, y, z: Double): ACAD_POINT; overload;
function SetPoint(base: ACAD_POINT; x, y, z: Double): ACAD_POINT; overload;
//function AddLine(StartPoint, EndPoint: ACAD_POINT): IAcadLine;
//function AddLineReXYZ(StartPoint: ACAD_POINT; x, y, z: Double): IAcadLine;
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
function TMainForm.CreateDimStyle(AName:string): IAcadDimStyle;
begin
if not FindDimStyle(AName, Result) then
Result := AcadDoc.DimStyles.Add(AName);
end;
function TMainForm.CreateLayer(AName: ACAD_LAYER; AColor: ACAD_COLOR;
ALineType: ACAD_LTYPE;
ALineWeight: ACAD_LWEIGHT;
ALineTypeFile: string): IAcadLayer;
begin
if not FindLayer(AName, Result) then
Result := AcadDoc.Layers.Add(AName);
Result.color := AColor;
if not FindLineType(ALineType) then
AcadDoc.Linetypes.Load(ALineType, ALineTypeFile);
Result.Linetype := ALineType;
Result.Lineweight := ALineWeight;
end;
function TMainForm.CreateTextStyle(AName: string; AFontFile: string;
ABigFontFile: string; AWidth: Double;
AObliqueAngle: Double;
AHeight: Double): IAcadTextStyle;
begin
if not FindTextStyle(AName, Result) then
Result := AcadDoc.TextStyles.Add(AName);
Result.fontFile := AFontFile;
Result.BigFontFile := ABigFontFile;
Result.Width := AWidth;
Result.ObliqueAngle := AObliqueAngle;
Result.Height := AHeight;
end;
procedure TMainForm.DrawN1_N3(L, D, K, Df, C, Dk, Dp, tp, tw, tl: Double);
var
BasePoint: ACAD_POINT;
Point1, Point2, Point3, Point4, Point5, Point6: ACAD_POINT;
Point7, Point8, Point9, Point10, Point11, Point12: ACAD_POINT;
Point13, Point14, Point15, Point16: ACAD_POINT;
PC1, PC2: ACAD_POINT;
Points: OleVariant;
OldDimStyle: IAcadDimStyle;
OldLayer: IAcadLayer;
OldTextStyle: IAcadTextStyle;
Hatch: IAcadHatch;
PL: IAcadLWPolyline;
OuterLoop: array of IAcadEntity;
InnerLoop: array of IAcadEntity;
R: Double;
Line1, Line2: IAcadLine;
DimObj: IAcadDimAligned;
begin
OldDimStyle := nil;
OldLayer := nil;
OldTextStyle := nil;
SetLength(InnerLoop, 1);
try
OldDimStyle := AcadDoc.ActiveDimStyle;
OldLayer := AcadDoc.ActiveLayer;
OldTextStyle := AcadDoc.ActiveTextStyle;
// Get base point
BasePoint := AcadDoc.Utility.GetPoint(EmptyParam, 'Base point:');
// Draw Center line
AcadDoc.ActiveLayer := CreateLayer('Center', acRed, 'CENTER');
PC1 := SetPoint(BasePoint, - ExtLine, 0, 0);
PC2 := SetPoint(BasePoint, L + ExtLine, 0, 0);
AcadDoc.ModelSpace.AddLine(PC1, PC2);
Point3 := SetPoint(PC2, 0, K / 2, 0);
Point4 := SetPoint(Point3, - C - 2 * ExtLine, 0, 0);
AcadDoc.ModelSpace.AddLine(Point3, Point4).Mirror(PC1, PC2);
// Draw Pipe
AcadDoc.ActiveLayer := CreateLayer('Pipe', acGreen, 'Continuous');
Hatch := AcadDoc.ModelSpace.AddHatch(0, 'ANSI31', True, 0);
if tp <= Rmin then
begin
tp := Rmin;
R := Rmin;
end
else
R := trunc(tp * 0.7);
Points := VarArrayCreate([0, 7], varDouble);
Points[0] := BasePoint[0];
Points[1] := BasePoint[1] + Dp / 2;
Points[2] := BasePoint[0] + L;
Points[3] := Points[1];
Points[4] := Points[2];
Points[5] := BasePoint[1] - Dp / 2;
Points[6] := BasePoint[0];
Points[7] := Points[5];
SetLength(OuterLoop, 1);
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.Closed := True;
OuterLoop[0] := PL;
Hatch.AppendOuterLoop(OuterLoop);
Hatch.AppendInnerLoop(OuterLoop);
if tp > R then
begin
Points := VarArrayCreate([0, 11], varDouble);
Points[0] := BasePoint[0] + L;
Points[1] := BasePoint[1] + Dp / 2;
Points[2] := BasePoint[0];
Points[3] := Points[1];
Points[4] := Points[2];
Points[5] := Points[3] - tp + R;
Points[6] := Points[4] + R;
Points[7] := Points[3] - tp;
Points[8] := Points[0] - R;
Points[9] := Points[7];
Points[10] := Points[0];
Points[11] := Points[5];
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.Closed := True;
PL.SetBulge(2, Tan(PI / 8));
PL.SetBulge(4, Tan(PI / 8));
InnerLoop[0] := PL;
Hatch.AppendInnerLoop(InnerLoop);
Points[0] := BasePoint[0];
Points[1] := BasePoint[1] - Dp / 2;
Points[2] := BasePoint[0] + L;
Points[3] := Points[1];
Points[4] := Points[2];
Points[5] := Points[3] + tp - R;
Points[6] := Points[4] - R;
Points[7] := Points[3] + tp;
Points[8] := BasePoint[0] + R;
Points[9] := Points[7];
Points[10] := BasePoint[0];
Points[11] := Points[5];
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.Closed := True;
PL.SetBulge(2, Tan(PI / 8));
PL.SetBulge(4, Tan(PI / 8));
InnerLoop[0] := PL;
Hatch.AppendInnerLoop(InnerLoop);
end
else
begin
Points := VarArrayCreate([0, 7], varDouble);
Points[0] := BasePoint[0] + L;
Points[1] := BasePoint[1] + Dp / 2;
Points[2] := BasePoint[0];
Points[3] := Points[1];
Points[4] := Points[2] + R;
Points[5] := Points[1] - R;
Points[6] := BasePoint[0] - R;
Points[7] := Points[5];
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.Closed := True;
PL.SetBulge(1, Tan(PI / 8));
PL.SetBulge(3, Tan(PI / 8));
InnerLoop[0] := PL;
Hatch.AppendInnerLoop(InnerLoop);
Points[0] := BasePoint[0];
Points[1] := BasePoint[1] - Dp / 2;
Points[2] := BasePoint[0] + L;
Points[3] := Points[1];
Points[4] := Points[2] - R;
Points[5] := Points[3] + R;
Points[6] := BasePoint[0] + R;
Points[7] := Points[5];
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.Closed := True;
PL.SetBulge(1, Tan(PI / 8));
PL.SetBulge(3, Tan(PI / 8));
InnerLoop[0] := PL;
Hatch.AppendInnerLoop(InnerLoop);
end;
Hatch.PatternAngle := 0.5 * PI;
Hatch.HatchStyle := acHatchStyleNormal;
Hatch.PatternScale := 3;
Hatch.Evaluate;
Hatch.Update;
// Draw Flange
Point2 := SetPoint(BasePoint, L, D / 2, 0);
Point1 := SetPoint(Point2, -C, 0, 0);
Point3 := SetPoint(BasePoint, L - C, Dp / 2, 0);
Point4 := SetPoint(BasePoint, L - C, -Dp / 2, 0);
Point6 := SetPoint(BasePoint, L, -D / 2, 0);
Point5 := SetPoint(Point6, -C, 0, 0);
AcadDoc.ActiveLayer := CreateLayer('Flange', acGreen, 'Continuous');
Hatch := AcadDoc.ModelSpace.AddHatch(0, 'ANSI31', True, 0);
SetLength(OuterLoop, 6);
Line1 := AcadDoc.ModelSpace.AddLine(Point4, Point3);
Line1.color := acRed;
if not FindLineType('DASHED') then
AcadDoc.Linetypes.Load('DASHED', 'acadiso.lin');
Line1.Linetype := 'DASHED';
OuterLoop[0] := Line1;
OuterLoop[1] := AcadDoc.ModelSpace.AddLine(Line1.EndPoint, Point1);
OuterLoop[2] := AcadDoc.ModelSpace.AddLine(Line1.StartPoint, Point5);
OuterLoop[3] := AcadDoc.ModelSpace.AddLine(Point2, Point6);
OuterLoop[4] := AcadDoc.ModelSpace.AddLine((OuterLoop[1] as IAcadLine).EndPoint, (OuterLoop[3] as IAcadLine).StartPoint);
OuterLoop[5] := AcadDoc.ModelSpace.AddLine((OuterLoop[2] as IAcadLine).EndPoint, (Outerloop[3] as IAcadLine).EndPoint);
Hatch.AppendOuterLoop(OuterLoop);
Hatch.AppendInnerLoop(OuterLoop);
Points := VarArrayCreate([0, 7], varDouble);
Points[0] := Point1[0];
Points[1] := Point1[1];
Points[2] := Point2[0];
Points[3] := Point2[1];
Points[4] := Points[2];
Points[5] := BasePoint[1] + (K + Dk) / 2;
Points[6] := Points[0];
Points[7] := Points[5];
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.Closed := True;
InnerLoop[0] := PL;
Hatch.AppendInnerLoop(InnerLoop);
Points[0] := Point5[0];
Points[1] := Point5[1];
Points[2] := Point6[0];
Points[3] := Point6[1];
Points[4] := Points[2];
Points[5] := BasePoint[1] - (K + Dk) / 2;
Points[6] := Points[0];
Points[7] := Points[5];
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.Closed := True;
InnerLoop[0] := PL;
Hatch.AppendInnerLoop(InnerLoop);
Points := VarArrayCreate([0, 9], varDouble);
Points[0] := Point1[0];
Points[1] := BasePoint[1] + Df / 2;
Points[2] := Point1[0];
Points[3] := BasePoint[1] + (K - Dk) / 2;
Points[4] := Point2[0];
Points[5] := Points[3];
Points[6] := Point2[0];
Points[7] := Point3[1] + W;
Points[8] := Point2[0] - W + (Df - Dp) / 2;
Points[9] := Points[1];
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.Closed := True;
InnerLoop[0] := PL;
Hatch.AppendInnerLoop(InnerLoop);
Points[0] := Point1[0];
Points[1] := BasePoint[1] - Df / 2;
Points[2] := Point1[0];
Points[3] := BasePoint[1] - (K - Dk) / 2;
Points[4] := Point2[0];
Points[5] := Points[3];
Points[6] := Point2[0];
Points[7] := Point4[1] - W;
Points[8] := Point2[0] - W + (Df - Dp) / 2;
Points[9] := Points[1];
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.Closed := True;
InnerLoop[0] := PL;
Hatch.AppendInnerLoop(InnerLoop);
Hatch.HatchStyle := acHatchStyleNormal;
Hatch.PatternScale := 1.5;
Hatch.Evaluate;
Hatch.Update;
// Draw Shell
Point7 := SetPoint(BasePoint, 0, K / 2, 0);
Point8 := SetPoint(Point7, tw, tw / 2, 0);
Point9 := SetPoint(BasePoint, tw, Dp / 2, 0);
Point10 := SetPoint(BasePoint, tw, - Dp / 2, 0);
Point11 := SetPoint(BasePoint, 0, - K / 2, 0);
Point12 := SetPoint(Point11, tw, tw / 2, 0);
AcadDoc.ActiveLayer := CreateLayer('Shell', acGreen, 'Continuous');
Hatch := AcadDoc.ModelSpace.AddHatch(0, 'ANSI31', True, 0);
SetLength(OuterLoop, 6);
Line1 := AcadDoc.ModelSpace.AddLine(Point9, Point10);
Line1.color := acRed;
Line1.Linetype := 'DASHED';
OuterLoop[0] := Line1;
OuterLoop[1] := AcadDoc.ModelSpace.AddLine(Line1.EndPoint, Point12);
OuterLoop[2] := AcadDoc.ModelSpace.AddLine(Line1.StartPoint, Point8);
OuterLoop[3] := AcadDoc.ModelSpace.AddLine(Point7, Point11);
Line1 := AcadDoc.ModelSpace.AddLine((OuterLoop[1] as IAcadLine).EndPoint, (OuterLoop[3] as IAcadLine).EndPoint);
Line2 := AcadDoc.ModelSpace.AddLine((OuterLoop[2] as IAcadLine).EndPoint, (Outerloop[3] as IAcadLine).StartPoint);
OuterLoop[4] := Line1;
OuterLoop[5] := Line2;
Hatch.AppendOuterLoop(OuterLoop);
Hatch.AppendInnerLoop(OuterLoop);
Points := VarArrayCreate([0, 9], varDouble);
Points[0] := Point7[0];
Points[1] := Point7[1];
Points[2] := Point8[0];
Points[3] := Point8[1];
Points[4] := Point9[0];
Points[5] := Point9[1] + 2 + (tw - 2) * tan(50 * PI / 180);
Points[6] := Points[0] + 2;
Points[7] := Point9[1] + 2;
Points[8] := Points[0];
Points[9] := Points[7];
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.Closed := True;
InnerLoop[0] := PL;
Hatch.AppendInnerLoop(InnerLoop);
Points[0] := Point11[0];
Points[1] := Point11[1];
Points[2] := Point12[0];
Points[3] := Point12[1];
Points[4] := Point10[0];
Points[5] := Point10[1] - 2 - (tw - 2) * tan(50 * PI / 180);
Points[6] := Points[0] + 2;
Points[7] := Point10[1] - 2;
Points[8] := Points[0];
Points[9] := Points[7];
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.Closed := True;
InnerLoop[0] := PL;
Hatch.AppendInnerLoop(InnerLoop);
Hatch.HatchStyle := acHatchStyleNormal;
Hatch.PatternScale := 3;
Hatch.Evaluate;
Hatch.Update;
Line1.StartPoint := SetPoint(BasePoint, - tl - 3, (K - tl - 3)/ 2, 0);
Line1.EndPoint := SetPoint(BasePoint, tw + 3, (K + tw + 3) / 2, 0);
Line2.StartPoint := SetPoint(BasePoint, - tl - 3, - (K + tl + 3) / 2, 0);
Line2.EndPoint := SetPoint(BasePoint, tw + 3, (- K + tw + 3) / 2, 0);
// Draw Lining
AcadDoc.ActiveLayer := CreateLayer('Lining', acRed, 'Continuous');
Point13 := SetPoint(Point2, tl, 0, 0);
Point14 := SetPoint(Point6, tl, 0, 0);
Point15 := SetPoint(BasePoint, - tl, (K - tl) / 2, 0);
Point16 := SetPoint(BasePoint, - tl, (- K - tl) / 2, 0);
AcadDoc.ModelSpace.AddLine(Point15, Point16);
AcadDoc.ModelSpace.AddLine(Point13, Point14);
AcadDoc.ModelSpace.AddLine(Point2, Point13).Mirror(PC1, PC2);
AcadDoc.ModelSpace.AddLine(SetPoint(BasePoint, L, (K + Dk) / 2, 0),
SetPoint(BasePoint, L + tl, (K + Dk) / 2, 0)).Mirror(PC1, PC2);
AcadDoc.ModelSpace.AddLine(SetPoint(BasePoint, L, (K - Dk) / 2, 0),
SetPoint(BasePoint, L + tl, (K - Dk) / 2, 0)).Mirror(PC1, PC2);
AcadDoc.ModelSpace.AddLine(SetPoint(BasePoint, R, Dp / 2 - tp - tl, 0),
SetPoint(BasePoint, L - R, Dp / 2 - tp - tl, 0)).Mirror(PC1, PC2);
AcadDoc.ModelSpace.AddArc(SetPoint(BasePoint, R, Dp / 2 - tp + R, 0),
R + tl, PI, 1.5 * PI).Mirror(PC1, PC2);
AcadDoc.ModelSpace.AddArc(SetPoint(BasePoint, L - R, Dp / 2 - tp + R, 0),
R + tl, 1.5 * PI, 0).Mirror(PC1, PC2);
// Draw Welding
AcadDoc.ActiveLayer := CreateLayer('Welding', acRed, 'Continuous');
Points := VarArrayCreate([0, 5], varDouble);
SetLength(OuterLoop, 1);
Hatch := AcadDoc.ModelSpace.AddHatch(0, 'Solid', True, 0);
Points[0] := Point1[0];
Points[1] := BasePoint[1] + Dp / 2;
Points[2] := Points[0] - W;
Points[3] := Points[1];
Points[4] := Points[0];
Points[5] := Points[1] + W;
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.color := acGreen;
PL.Closed := True;
OuterLoop[0] := PL;
Hatch.AppendOuterLoop(OuterLoop);
Hatch.HatchStyle := acHatchStyleNormal;
Hatch.Evaluate;
Hatch.Update;
Hatch := AcadDoc.ModelSpace.AddHatch(0, 'Solid', True, 0);
Points[0] := Point2[0];
Points[1] := BasePoint[1] + Dp / 2;
Points[2] := Points[0] - W;
Points[3] := Points[1];
Points[4] := Points[0];
Points[5] := Points[1] + W;
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.color := acGreen;
PL.Closed := True;
OuterLoop[0] := PL;
Hatch.AppendOuterLoop(OuterLoop);
Hatch.HatchStyle := acHatchStyleNormal;
Hatch.Evaluate;
Hatch.Update;
Hatch := AcadDoc.ModelSpace.AddHatch(0, 'Solid', True, 0);
Points[0] := Point1[0];
Points[1] := BasePoint[1] - Dp / 2;
Points[2] := Points[0] - W;
Points[3] := Points[1];
Points[4] := Points[0];
Points[5] := Points[1] - W;
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.color := acGreen;
PL.Closed := True;
OuterLoop[0] := PL;
Hatch.AppendOuterLoop(OuterLoop);
Hatch.HatchStyle := acHatchStyleNormal;
Hatch.Evaluate;
Hatch.Update;
Hatch := AcadDoc.ModelSpace.AddHatch(0, 'Solid', True, 0);
Points[0] := Point2[0];
Points[1] := BasePoint[1] - Dp / 2;
Points[2] := Points[0] - W;
Points[3] := Points[1];
Points[4] := Points[0];
Points[5] := Points[1] - W;
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.color := acGreen;
PL.Closed := True;
OuterLoop[0] := PL;
Hatch.AppendOuterLoop(OuterLoop);
Hatch.HatchStyle := acHatchStyleNormal;
Hatch.Evaluate;
Hatch.Update;
Hatch := AcadDoc.ModelSpace.AddHatch(0, 'Solid', True, 0);
Points := VarArrayCreate([0, 9], varDouble);
Points[0] := Point7[0];
Points[1] := Point9[1];
Points[2] := Points[0];
Points[3] := Points[1] + 2;
Points[4] := Points[2] + 2;
Points[5] := Points[3];
Points[6] := Point9[0];
Points[7] := Points[3] + (tw - 2) * tan(50 * PI / 180);
Points[8] := Point9[0];
Points[9] := Point9[1];
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.color := acGreen;
PL.Closed := True;
OuterLoop[0] := PL;
Hatch.AppendOuterLoop(OuterLoop);
Hatch.HatchStyle := acHatchStyleNormal;
Hatch.Evaluate;
Hatch.Update;
Hatch := AcadDoc.ModelSpace.AddHatch(0, 'Solid', True, 0);
Points := VarArrayCreate([0, 9], varDouble);
Points[0] := Point11[0];
Points[1] := Point10[1];
Points[2] := Points[0];
Points[3] := Points[1] - 2;
Points[4] := Points[2] + 2;
Points[5] := Points[3];
Points[6] := Point10[0];
Points[7] := Points[3] - (tw - 2) * tan(50 * PI / 180);
Points[8] := Point10[0];
Points[9] := Point10[1];
PL := AcadDoc.ModelSpace.AddLightWeightPolyline(Points);
PL.color := acGreen;
PL.Closed := True;
OuterLoop[0] := PL;
Hatch.AppendOuterLoop(OuterLoop);
Hatch.HatchStyle := acHatchStyleNormal;
Hatch.Evaluate;
Hatch.Update;
// Draw Dimension
AcadDoc.ActiveLayer := CreateLayer('Dimension', acCyan, 'Continuous');
AcadDoc.ActiveTextStyle := CreateTextStyle('HZTXT','geditxt.shx',
'hztxt.shx',0.7);
AcadDoc.SetVariable('DIMCLRT', acYellow);
AcadDoc.SetVariable('DIMDEC', 0);
AcadDoc.SetVariable('DIMTXSTY', 'HZTXT');
// DimObj := AcadDoc.ModelSpace.AddDimAligned(Point1, Point2, SetPoint(Point1, 0, 20, 0)); //就是这句会出错
// CreateDimStyle('M10').CopyFrom(AcadDoc.ActiveDimStyle);
finally
if OldTextStyle <> nil then
AcadDoc.ActiveTextStyle := OldTextStyle;
if OldLayer <> nil then
AcadDoc.ActiveLayer := OldLayer;
if OldDimStyle <> nil then
AcadDoc.ActiveDimStyle := OldDimStyle;
SetLength(OuterLoop, 0);
SetLength(InnerLoop, 0);
end;
end;
function TMainForm.FindDimStyle(AName: string; var AStyle: IAcadDimStyle): Boolean;
var
i: Integer;
begin
Result := False;
for i := 0 to AcadDoc.DimStyles.Count - 1 do
if AcadDoc.DimStyles.Item(i).Name = AName then
begin
AStyle := AcadDoc.DimStyles.Item(i);
Result := True;
Break;
end;
end;
function TMainForm.FindLayer(AName: ACAD_LAYER; var ALayer: IAcadLayer): Boolean;
var
i: Integer;
begin
Result := False;
for i := 0 to AcadDoc.Layers.Count - 1 do
if AcadDoc.Layers.Item(i).Name = AName then
begin
ALayer := AcadDoc.Layers.Item(i);
Result := True;
Break;
end;
end;
function TMainForm.FindLineType(AName: ACAD_LTYPE): Boolean;
var
i: Integer;
begin
Result := False;
for i := 0 to AcadDoc.Linetypes.Count - 1 do
if AcadDoc.Linetypes.Item(i).Name = AName then
begin
Result := True;
Break;
end;
end;
function TMainForm.FindTextStyle(AName: string; var AStyle: IAcadTextStyle): Boolean;
var
i: Integer;
begin
Result := False;
for i := 0 to AcadDoc.TextStyles.Count - 1 do
if AcadDoc.TextStyles.Item(i).Name = AName then
begin
AStyle := AcadDoc.TextStyles.Item(i);
Result := True;
Break;
end;
end;
function TMainForm.SetPoint(x, y, z: Double): ACAD_POINT;
begin
Result := VarArrayCreate([0, 2], varDouble);
Result[0] := x;
Result[1] := y;
Result[2] := z;
end;
function TMainForm.SetPoint(base: ACAD_POINT; x, y, z: Double): ACAD_POINT;
begin
Result := VarArrayCreate([0, 2], varDouble);
Result[0] := base[0] + x;
Result[1] := base[1] + y;
Result[2] := base[2] + z;
end;
{
function TMainForm.AddLine(StartPoint, EndPoint: ACAD_POINT): IAcadLine;
begin
Result := AcadDoc.ModelSpace.AddLine(StartPoint, EndPoint);
end;
function TMainForm.AddLineReXYZ(StartPoint: ACAD_POINT; x, y, z: Double): IAcadLine;
begin
Result := AcadDoc.ModelSpace.AddLine(StartPoint,
SetPoint(StartPoint, x, y, z));
end;
}
procedure TMainForm.FormCreate(Sender: TObject);
var
v: OleVariant;
begin
try
v := GetActiveOleObject('AutoCAD.Application');
AcadDoc.ConnectTo((IDispatch(v) as IAcadApplication).ActiveDocument);
except
AcadDoc.Connect;
end;
LastDoc := AcadDoc.Path + '\' + AcadDoc.Name;
end;
procedure TMainForm.Timer1Timer(Sender: TObject);
var
v: OleVariant;
begin
try
if LastDoc <> AcadDoc.Application.ActiveDocument.Name then
begin
try
AcadDoc.Disconnect;
except
end;
try
v := GetActiveOleObject('AutoCAD.Application');
AcadDoc.ConnectTo((IDispatch(v) as IAcadApplication).ActiveDocument);
LastDoc:= AcadDoc.Path + '\' + AcadDoc.Name;
except
end;
end;
except
end;
Caption:= LastDoc;
end;
procedure TMainForm.AcadDocObjectAdded(ASender: TObject;
const Object_: IDispatch);
begin
AcadDoc.Utility.Prompt('Object added' + #13 + #10);
end;
procedure TMainForm.Button1Click(Sender: TObject);
begin
DrawN1_N3(600, 1175, 1120, 1024, 42, 30, 1020, 11, 16, 8);
end;
end.
报的错误如下图 |
|