CAD rectangle and position question

Hello,

Is there a way to draw rectangle using Aspose.CAD? I didn’t find such element in your entities but this is the basic element and for sure must be supported. Of course, I could draw it using polyline but polyline, for example, can’t be filled, can’t have a border and so on.

And my second question is how do I get a position of ICadBaseEntity? Some of them have Alignment value, some of them have coordinates. Is there any unified property where I can get position of an object.

Regards

1 Like

I am also looking for a way for drawing elements by coordinates.
is there anybody do it before??

@AlexBilakovskyi

Can you please elaborate your requirements for drawing rectangles as API does not support it currently.

For this, can you please share the details with us for required properties so that we may help you further.

@mudassir.fayyaz

Can you please elaborate your requirements for drawing rectangles as API does not support it currently.

For my goals, I would like to have standart rectangle’s functionality as: opportunity to hatch it with given samples (SOLID, ANGLE, ANSI31 etc). Opportunity to change it’s color, transparency, opacity. Possibility to change border’s width, color, style. That’s what I would like to see in your future rectangle support :slight_smile: But I guess there should be more available features in AutoCAD to implement in your library.

For this, can you please share the details with us for required properties so that we may help you further.

My main question is how to get entity coordinates on the layer? For example, I have method deleteAllEntities which takes RectangleF as parameter. Inside this method I want to delete all entities that are inside this rectangle. For this purpose I am iterating through cadImage.BlockEntities["*Model_Space"].Entities. Each entity is ICadBaseEntity and it does not have any coordinates, offsets, alignments etc. To detect where this entity is positioned I have to cast it. That looks to me like not optimized solution. Example is shown below.

private void DeleteAllEntities(CadImage cadImage, RectangleF rectangle)
    {
        foreach (ICadBaseEntity baseEntity in cadImage.BlockEntities["*Model_Space"].Entities)
        {
            if (baseEntity.GetType() == typeof(CadText))
            {
                CadText entityText = (CadText)baseEntity;

                List<Point> entityPoints = new List<Point>
                {
                    new Point((float) entityText.FirstAlignment.X, (float) entityText.FirstAlignment.Y),
                    new Point((float) entityText.FirstAlignment.X , (float) entityText.FirstAlignment.Y + (float)entityText.TextHeight),
                    new Point((float) entityText.FirstAlignment.X + (float)entityText.TextWidth, (float) entityText.FirstAlignment.Y),
                    new Point((float) entityText.FirstAlignment.X + (float)entityText.TextWidth, (float) entityText.FirstAlignment.Y + (float)entityText.TextHeight)
                };

                if (InIntersected(rectangle, entityPoints))
                {
                    // todo logic
                }
            }
            else if (baseEntity.GetType() == typeof(CadMText))
            {
                CadMText entityText = (CadMText)baseEntity;

                List<Point> entityPoints = new List<Point>
                {
                    new Point((float) entityText.InsertionPoint.X, (float) entityText.InsertionPoint.Y),
                    new Point((float) entityText.InsertionPoint.X , (float) entityText.InsertionPoint.Y + (float)entityText.InitialTextHeight),
                    new Point((float) entityText.InsertionPoint.X + (float)entityText.HorizontalWidth, (float) entityText.InsertionPoint.Y),
                    new Point((float) entityText.InsertionPoint.X + (float)entityText.HorizontalWidth, (float) entityText.InsertionPoint.Y + (float)entityText.InitialTextHeight)
                };

                if (InIntersected(rectangle, entityPoints))
                {
                    // todo logic
                }
            }
            else if (baseEntity.GetType() == typeof(CadCircle))
            {
                CadCircle entityCircle = (CadCircle)baseEntity;

                Tuple<Cad3DPoint, double> circleCoords =
                    new Tuple<Cad3DPoint, double>(entityCircle.CenterPoint, entityCircle.Radius);

                if (InIntersected(rectangle, circleCoords))
                {
                    // todo logic
                }
            }
            // etc
        }
    }

Now I actively research Aspose.CAD library so I came up with 3rd question. How do I set text style for CadMText component? By text style I mean Italic, Bold, Strikeout, Underline. And is it possible, for example, to strikeout just part of the text?

Thanks for help

1 Like

@AlexBilakovskyi

I have created a ticket with ID CADNET-1351 in our issue tracking system to further analyze the requirements shared by you. We will get back to you with feedback as soon as the investigation will be completed internally on our end.

Hello Alex, do you have an anver for you Question. A have the same Question and I would like to know the answer.

@imas0804,
Hello, please, clarify what is your question, probably, I can help.

I want to add a filled rectangle at a certain position in a DWG file with aspose.cad

@imas0804,
OK. There is no such object as rectangle in DWG, it is represented as polylines only. Here is the example how to add and fill:

using (CadImage cadImage = (CadImage)Image.Load(fileName))
{

CadLwPolyline polyline = new CadLwPolyline();
polyline.Coordinates = new List();
polyline.Coordinates.Add(new Cad2DPoint(-5d, -5d));
polyline.Coordinates.Add(new Cad2DPoint(-5d, 10d));
polyline.Coordinates.Add(new Cad2DPoint(20d, 10d));
polyline.Coordinates.Add(new Cad2DPoint(20d, -5d));
polyline.Flag = CadLwPolylineFlag.Closed;
polyline.ConstantWidth = 0.1;

CadHatch hatch = new CadHatch();
hatch.PatternName = “SOLID”;
hatch.ColorId = 1; // index of color: AutoCAD Color Index RGB Equivalents
hatch.HatchPatternType = 1; // 0 = User-defined; 1 = Predefined; 2 = Custom, we support only predefined now
hatch.BoundaryPaths = new List();
CadHatchBoundaryPathContainer container = new CadHatchBoundaryPathContainer();
container.BoundaryPath = new List();

CadEdgeBoundaryPath path = new CadEdgeBoundaryPath();
path.Objects = new List();
path.Objects.Add(new CadBoundaryPathLine() { FirstPoint = new Point2D(-5, -5), SecondPoint = new Point2D(-5, 10) });
path.Objects.Add(new CadBoundaryPathLine() { FirstPoint = new Point2D(-5, 10), SecondPoint = new Point2D(20, 10) });
path.Objects.Add(new CadBoundaryPathLine() { FirstPoint = new Point2D(20, 10), SecondPoint = new Point2D(20, -5) });
path.Objects.Add(new CadBoundaryPathLine() { FirstPoint = new Point2D(20, -5), SecondPoint = new Point2D(-5, -5) });

container.BoundaryPath.Add(path);
hatch.BoundaryPaths.Add(container);

List entities = new List();
entities.Add(polyline);
entities.Add(hatch);
cadImage.Entities = entities.ToArray();
cadImage.UpdateSize();

}

Super cool! The solution worked for me! It was a great help for me! Thank you very much Oleksii!

1 Like