How to draw shapes using Cadlib library?

1
Sachin Tripathi
11/26/2019 9:54 AM

Hi,

I wanted to draw multiple solid shapes(attached) with text in the middle in the DWG file.
Is there any way to achieve this?

DxfHatch is something I found while exploring. Please suggest the right way to do it.

Wout
11/26/2019 12:21 PM

Hi,

Yes, you would need to use the DxfHatch entity. See the documentation for more details and examples.

- Wout

Sachin Tripathi
11/28/2019 9:04 AM

Hi Wout,

I can draw a Rectangle, Triangle, Hexagon, Circle but unable to draw Terminator or Delay shape(attached). Can you please share some snippet that can help me out.

Thanks,
Sachin

Wout
11/28/2019 12:02 PM

Attachment is not there.

Sachin Tripathi
11/28/2019 12:09 PM

Please find the attachment.

Wout
11/28/2019 12:17 PM

You can put together a series of Line and Arc/Spline edges to create them. If you need me to write sample code, you'll have to order a support ticket for that (you can order here).

- Wout

Sachin Tripathi
11/29/2019 5:35 AM

Hi Wout,
I tried as suggested but shapes are not coming properly. Can you please suggest to me what I'm doing wrong here.

C# Code:
 public static void DrawTerminator()
        {
            DxfModel model = new DxfModel(DxfVersion.Dxf14);

            DxfHatch hatch = new DxfHatch();
            hatch.Color = EntityColors.LightBlue;
            hatch.ElevationPoint = new Point3D(0, 0, 0);

            //// A boundary path bounded by lines.
            DxfHatch.BoundaryPath boundaryPath1 = new DxfHatch.BoundaryPath(BoundaryPathType.None);            
            hatch.BoundaryPaths.Add(boundaryPath1);
            boundaryPath1.Edges.Add(new DxfHatch.BoundaryPath.LineEdge(new Point2D(0, 0), new Point2D(10, 0)));
            boundaryPath1.Edges.Add(new DxfHatch.BoundaryPath.LineEdge(new Point2D(10, 0), new Point2D(10, 10)));
            boundaryPath1.Edges.Add(new DxfHatch.BoundaryPath.LineEdge(new Point2D(10, 10), new Point2D(0, 10)));
            boundaryPath1.Edges.Add(new DxfHatch.BoundaryPath.LineEdge(new Point2D(0, 10), new Point2D(0, 0)));

            DxfHatch.BoundaryPath.EllipseEdge topEdge = new DxfHatch.BoundaryPath.EllipseEdge();
            topEdge.CounterClockWise = true;
            topEdge.Center = new Point2D(5, 10);
            topEdge.MajorAxisEndPoint = new Vector2D(5d, 0d);
            topEdge.MinorToMajorRatio = 0.3;
            topEdge.StartAngle = 0;
            topEdge.EndAngle = 180 * Constants.DegreesToRadians;
            boundaryPath1.Edges.Add(topEdge);

            DxfHatch.BoundaryPath.EllipseEdge bottomEdge = new DxfHatch.BoundaryPath.EllipseEdge();
            bottomEdge.CounterClockWise = false;
            bottomEdge.Center = new Point2D(5, 0);
            bottomEdge.MajorAxisEndPoint = new Vector2D(5d, 0d);
            bottomEdge.MinorToMajorRatio = 0.3;
            bottomEdge.StartAngle = 0;
            bottomEdge.EndAngle = 180 * Constants.DegreesToRadians;
            boundaryPath1.Edges.Add(bottomEdge);

            model.Entities.Add(hatch);

            DxfWriter.Write(@"D:\HCS\POC_Layout\DWG Conversion\Test.netDxf\Hatch_Example_hatch_solid.dxf", model, false);
        }

The output image is attached.

Wout
11/29/2019 12:27 PM

Hi,

If you need me to write code for you or debug your code you'll have to order a support ticket.

- Wout

1