Create Many Layout in DWG
Posted: 02 Nov 2023, 13:27
Hello everyone,
I am looking to create multiple Layouts in a DWG file. Unfortunately, the created file does not work correctly in DraftSight and causes an error in AutoCad.
The DraftSight error test shows this message:
Error:ACAD_LAYOUT Dictionary: Sheet (6A) associated with invalid BlockTableRecord should be Removed (Test:Invalid)
Here is the source code used to create a layout in "AddEntities" projet (provided by CADSoftTools) :
Anyone have a solution?
I am looking to create multiple Layouts in a DWG file. Unfortunately, the created file does not work correctly in DraftSight and causes an error in AutoCad.
The DraftSight error test shows this message:
Error:ACAD_LAYOUT Dictionary: Sheet (6A) associated with invalid BlockTableRecord should be Removed (Test:Invalid)
Here is the source code used to create a layout in "AddEntities" projet (provided by CADSoftTools) :
Code: Select all
{ function AddNewLayout
Generates new paperspace block with new layout }
function AddNewLayout(const AConv: TsgDXFConverter; var ALayoutName: string;
ASize: PF2DPoint; AGenerateViewPort: Boolean = True): TsgDXFBlock;
var
I: Integer;
vNewName: string;
vPrintArea: TFRect;
begin
// find unique paperspace block name
I := 0;
repeat
vNewName := sPaperSpace;
if I > 0 then
vNewName := vNewName + IntToStr(I);
Inc(I);
until AConv.BlockByName(vNewName) = nil;
// create new paperspace block
Result := TsgDXFBlock.Create;
// set paperspace block name
Result.Name := vNewName;
// create new layout and
// set paperspace for new layout
TsgDXFLayout.Create.PaperSpaceBlock := Result;
// add paperspace block to the section
AConv.Sections[csBlocks].AddEntity(Result);
if AConv.LayoutByName(vNewName) = nil then
vNewName := ALayoutName
else
begin
// find unique layout name
I := 1;
repeat
vNewName := sLayout + IntToStr(I);
Inc(I);
until AConv.LayoutByName(vNewName) = nil;
ALayoutName := vNewName;
end;
// set layout name
Result.Layout.Name := vNewName;
// add layout to the section
AConv.Sections[csLayouts].AddEntity(Result.Layout);
if AGenerateViewPort then
begin
if ASize <> nil then
begin
TsgDXFLayout(Result.Layout).PlotSettings.PlotPaperSize := ASize^;
TsgDXFConverterAccess(AConv).GenerateDisplayAndModelViewPort(
TsgDXFLayout(Result.Layout),
ASize^.X, ASize^.Y, 0);
end
else
begin
// reset plotsettings
TsgDXFLayout(Result.Layout).PlotSettings.ResetForDefaultValue(nil); //??
vPrintArea := TsgDXFLayout(Result.Layout).PlotSettings.PlotMarginsArea;
// create new display viewport
TsgDXFConverterAccess(AConv).GenerateDisplayAndModelViewPort(
TsgDXFLayout(Result.Layout),
vPrintArea.Right - vPrintArea.Left,
Abs(vPrintArea.Top - vPrintArea.Bottom), 0);
end;
end;
// loads new entities
AConv.Loads(Result);
AConv.Loads(Result.Layout);
end;
function TForm1.AddLayout(const cnstLayoutName:String; ASize: PF2DPoint): TsgDXFLayout;
var
vLayoutName: string;
vPaperSpaceBlock: TsgDXFBlock;
begin
vLayoutName := cnstLayoutName;
vPaperSpaceBlock := AddNewLayout(FCADFile.Converter, vLayoutName, ASize);
Result := TsgDXFLayout(vPaperSpaceBlock.Layout);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
vSize: TF2DPoint;
begin
if not CreateCADFile then
Exit;
AddLayer;
AddLineType;
AddStyle;
AddText1;
AddText2;
AddMText;
AddLine;
AddPolyline1;
AddPolyline2;
AddLWPolyline;
AddSpline;
AddArc;
AddCircle;
AddSolid;
AddDimension;
AddHatch;
AddImageEnt;
AddInsert;
FCADFile.GetExtents;
vSize := MakeF2DPoint(297, 210);
AddLayout(cnstLayoutTest, @vSize);
//AddDisplayViewPort(297, 210, cnstLayoutTest);
//AddModelViewPort(297, 210, cnstLayoutTest);
vSize := MakeF2DPoint(210, 297);
AddLayout(cnstLayoutTest2, @vSize);
//AddDisplayViewPort(210, 297, cnstLayoutTest2);
//AddModelViewPort( 210, 297, cnstLayoutTest2);
vSize := MakeF2DPoint(420, 297);
AddLayout(cnstLayoutTest3, @vSize);
LoadLayouts;
SetGraphic;
end;