Creating a block from a dxf file
Posted: 03 Nov 2010, 10:57
I need to insert an existing .dxf file as blocks into the main CADImage (TsgDrawingNavigator). I read the .dxf and copy all entities to a block (the layers/linetype will be done later, the testfile has only 1 polyline in layer 0).
When I run the program I see the new block in the drawing. As soon as I, for example, zoom with the Navigator I got a run-time error.
The source:
I don't want to use the AddScaledDXF funtion, because I need to save all as one large dxf file.
Can you please help me with this?
Thank you!
Frank
When I run the program I see the new block in the drawing. As soon as I, for example, zoom with the Navigator I got a run-time error.
The source:
Code: Select all
procedure TTestDlg.Button9Click(Sender: TObject);
var
InsCADFile:TsgCADImage;
Ent:TsgDXFEntity;
i:integer;
Conv:TsgDXFConverter;
Block:TsgDXFBlock;
Ins:TsgDXFInsert;
MainConv:TsgDXFConverter;
vLine:TsgDXFLine;
begin
InsCADFile:=TsgCADImage.Create;
try
InsCADFile:=GetCADFile('c:\test.dxf'); // Only one polyline
Conv:=InsCADFile.Converter;
Block:=TsgDXFBlock.Create;
Block.Name:='$'+IntToHex(Integer(Pointer(Block)),8);
for i:=0 to Conv.Counts[csEntities]-1 do begin
Ent:=TsgDXFEntityClass(TsgDXFEntity(Conv.Entities[i]).ClassType).Create;
Ent.AssignEntity(TsgDXFEntity(Conv.Entities[i]));
Block.AddEntity(Ent);
end;
//Manually add a Line works fine:
//vLine := TsgDXFLine.Create;
//vLine.Point := MakeFPoint( 80, 100, 0);// first point
//vLine.Point1 := MakeFPoint(150, 150, 0);// second point
//vLine.SetColor(clBlue);
//Block.AddEntity(vLine);
MainConv:=Img.Converter;// current TsgCADImage=Img
ShowMessage(IntToStr(MainConv.Counts[csEntities]));
for i:=0 to Block.Count-1 do begin
MainConv.OnCreate(Block.Entities[i]);
MainConv.Loads(Block.Entities[i]);
end;
MainConv.OnCreate(Block);
MainConv.Sections[csBlocks].AddEntity(Block);
MainConv.Loads(Block);
Ins:=TsgDXFInsert.Create;
MainConv.OnCreate(Ins);
Ins.Block:=Block;
Ins.Point:=MakeFPoint(100, 100, 0);
MainConv.Sections[csEntities].AddEntity(Ins);
MainConv.Loads(Ins);
Img.GetExtents;
fDNavigator.Invalidate;
DNavigator.FitToSize;
DNavigator.Refresh;
ShowMessage(IntToStr(MainConv.Counts[csEntities])); // 1 Entity is added that is correct
finally
InsCADFile.Free;
end;
end;
I don't want to use the AddScaledDXF funtion, because I need to save all as one large dxf file.
Can you please help me with this?
Thank you!
Frank