Circle with fill solid color

Aug 18, 2012 at 10:21 AM

hi ,

how to create a circle and filling it with a color(ie hatches).

please give some code hint so that i can put in my project .

 

thanks and regards,

Ravi Reddy Bokkala.

Sep 26, 2012 at 6:10 PM

to me too! I have the same problem.

Giovanni

Coordinator
Sep 28, 2012 at 3:51 AM

Until now you couldn't, no hatches no way of filling a circle with a color. Now that hatches are implemented it is really easy to do. Check the following example (also included in the source code, TestDxfDocument project) hope it will clarify your doubts.

private static void HatchCircleBoundary()
        {
            DxfDocument dxf = new DxfDocument();

            // create a circle that will be our hatch boundary in this case it is a circle with center (5.5, -5.5, 0.0) and a radius 10.0
            Circle circle = new Circle(new Vector3(5.5, -5.5, 0), 10);

            // create the hatch boundary path with only the circle (a circle is already a closed loop it is all we need to define a valid boundary path)
            // a hatch can have many boundaries (closed loops) and every boundary path can be made of several entities (lines, polylines, arcs, circles and ellipses)
            List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>
                                                        {
                                                            new HatchBoundaryPath(new List<IEntityObject>{circle})
                                                        };  

            // create the hatch in this case we will use the predefined Solid hatch pattern and our circle as the boundary path
            Hatch hatch = new Hatch(HatchPattern.Solid, boundary);

            // to give a color to the hatch, we have to options:

            // create a new layer with a color for the hatch (in this case by default the hatch will have a ByLayer color)
            //Layer hatchLayer = new Layer("HathLayer") {Color = AciColor.Green};
            //hatch.Layer = hatchLayer;

            // or give the hatch a color just for it
            // old AutoCAD versions only had 255 colors (indexed color), now in AutoCAD you can use true colors (8 bits per channel) but at the moment this is not supported.
            // if you try to give r, g, b values to define a color it will be converted to an indexed color
            // (I haven't tested this code a lot, so errors might appear and the result might not be what you expected).
            hatch.Color = AciColor.Red;

            // the hatch by itself will not show the boundary, but we can use the same entity to show the limits of the hatch, adding it to the document 
            dxf.AddEntity(circle);

            // add the hatch to the document
            dxf.AddEntity(hatch);

            dxf.Save("circle solid fill.dxf", DxfVersion.AutoCad2000);
        }

Daniel

Sep 28, 2012 at 4:35 PM

Thank you so much!

Giovanni