Viewport AnnotationScale

1
Toky
6/30/2021 3:02 AM

Hello, Wout

I am Ji.

I downloaded the trial version of CadLib and am currently testing it.

Set a annotation scale to viewport, but does not apply.

DxfScale mainScale = new DxfScale();
scale.DrawingUnits = 1;
scale.PaperUnits = 2;
scale.Name = "mainScale";

DxfViewport mainViewport = new DxfViewport();
mainViewport.AnnotationScale = mainScale,


How to set annotation scale to viewport?

Thanks Regards

Wout
7/15/2021 1:15 PM

Hi Ji,

Can you post your complete program so I can compile and test it?

- Wout

Toky
7/16/2021 1:24 AM

Thank you for your reply.

Our evaluation is almost complete.
But it still does not solve this problem.

Following is my code.
Best Regards.
----------------------------------------------------------------
static void Main(string[] args)
{
test1();
}
static void test1()
{
DxfModel model = DxfReader.Read("drawing1.dxf");

DxfLayout batch = new DxfLayout("batch");
batch.PlotPaperSize = new Size2D(292, 210);
batch.UnprintableMarginLeft = 5d;
batch.UnprintableMarginRight = 5d;
batch.UnprintableMarginTop = 5d;
batch.UnprintableMarginBottom = 5d;
batch.TabOrder = 1;
batch.PlotRotation = PlotRotation.None;
model.Layouts.Add(batch);

// This viewport is mandatory, it describes paper space itself.
DxfViewport paperSpaceViewport = new DxfViewport();
paperSpaceViewport.ViewCenter = new Point2D(297 / 2, 210 / 2);
paperSpaceViewport.Size = batch.PlotPaperSize;
paperSpaceViewport.Visible = true;
paperSpaceViewport.ViewHeight = 210;
paperSpaceViewport.PaperSpace = true;
paperSpaceViewport.Target = new Point3D(0, 0, 0);
batch.Viewports.Add(paperSpaceViewport);


BoundsCalculator calculator = new BoundsCalculator();
calculator.GetBounds(model);
Bounds3D bounds = calculator.Bounds;

DxfScale scale = new DxfScale();
scale.DrawingUnits = 1;
scale.PaperUnits = 2;
scale.Name = "2:1@";
model.Scales.Add(scale);

// This viewport is a viewport showing a piece of model space in paper space.
// The total scale factor will be Size.Y / ViewHeight.
DxfViewport mainVp = new DxfViewport();
mainVp.ViewCenter = new Point2D(bounds.Center.X, bounds.Center.Y);
mainVp.Size = new Size2D(150, 150);
mainVp.Visible = true;
mainVp.ViewHeight = (bounds.Max.Y - bounds.Min.Y) * 1.1;
mainVp.PaperSpace = true;

Vector3D boxOrg = new Vector3D(mainVp.Size.X / 2, -mainVp.Size.Y / 2, 0);
Point3D vpLocation = new Point3D(10, 180, 0);

mainVp.Center = vpLocation + boxOrg;
mainVp.Target = new Point3D(0, 0, 0);

mainVp.AnnotationScale = model.Scales[scale.Name]; //value is null after set

batch.Viewports.Add(mainVp);

DxfWriter.Write("test.dxf", model);
}

1