Page 1 of 1
How to mirror an CADArc
Posted: 03 Oct 2019, 23:29
by rafaellippert
Hello,
Is it possible to mirror an entire entity?
I tried to do it manually in each entity, but in the arches I have some difficulty. Is there any practical way to do? What would it be like?
Thanks,
RafaelLi
Re: How to mirror an CADArc
Posted: 04 Oct 2019, 00:15
by support
Hello Rafael,
Yes, it is possible to mirror an entity in the X or Y axis by applying coordinate transformation to CADEntity derivatives. You will need to use the following code:
Code: Select all
public enum CADAxis
{
OX,
OY,
OZ,
}
public static float Mod(double AValue, double ABase)
{
return (float)(AValue - (Int64)(Math.Truncate(AValue / ABase)) * ABase);
}
public static void MirrorEntityInAxis(CADImage cadImage, CADEntity entity, CADAxis axis)
{
CADMatrix m = new CADMatrix();
m.IdentityMat();
DPoint vector = DPoint.One;
double angle = 0;
switch (axis)
{
case CADAxis.OX:
vector = new DPoint(1, -1, 1);
angle = 180;
break;
case CADAxis.OY:
vector = new DPoint(-1, 1, 1);
break;
}
m = m.Scale(vector);
switch (entity.EntType)
{
case EntityType.Line:
CADLine line = entity as CADLine;
line.Point = DPoint.XMat(line.Point, m);
line.Point1 = DPoint.XMat(line.Point1, m);
cadImage.Converter.Loads(line);
break;
case EntityType.LWPolyline:
CADLWPolyLine lwPolyline = entity as CADLWPolyLine;
lwPolyline.Vertexes.ForEach(vertex => (vertex as CADVertex).Point = (vertex as CADVertex).Point.XMat(m));
cadImage.Converter.Loads(lwPolyline);
break;
case EntityType.Circle:
CADCircle circle = entity as CADCircle;
circle.Point = DPoint.XMat(circle.Point, m);
cadImage.Converter.Loads(circle);
break;
case EntityType.Arc:
CADArc arc = entity as CADArc;
arc.Point = DPoint.XMat(arc.Point, m);
cadImage.Converter.Loads(arc);
arc.Extrusion = new DPoint(arc.Extrusion.X, arc.Extrusion.Y, -arc.Extrusion.Z);
arc.StartAngle = arc.StartAngle + angle;
arc.EndAngle = arc.EndAngle + angle;
cadImage.Converter.Loads(arc);
break;
case EntityType.Spline:
CADSpline spline = entity as CADSpline;
if (spline.FitCount > 0)
{
for (int i = 0; i < spline.FitCount; i++)
spline.Fit[i] = DPoint.XMat(spline.Fit[i], m);
}
else
{
for (int i = 0; i < spline.ControlCount; i++)
spline.Controls[i] = DPoint.XMat(spline.Controls[i], m);
}
cadImage.Converter.Loads(spline);
break;
case EntityType.Insert:
CADInsert insert = entity as CADInsert;
insert.Point = DPoint.XMat(insert.Point, m);
insert.Angle = Mod(-insert.Angle - 180, 360);
if (axis == CADAxis.OX)
insert.Scale = new DPoint(-insert.Scale.X, insert.Scale.Y, insert.Scale.Z);
if (axis == CADAxis.OY)
insert.Scale = new DPoint(insert.Scale.X, -insert.Scale.Y, insert.Scale.Z);
cadImage.Converter.Loads(insert);
break;
}
}
Mikhail
Re: How to mirror an CADArc
Posted: 04 Oct 2019, 00:45
by rafaellippert
Thanks!!
but, how to use this example?
Like this: ?
MirrorEntityInAxis(cadImage2, cadImage2.CurrentLayout, CADAxis.OX)
I need to Mirror vertically all the entities contained in cadImage2.CurrentLayout.
An example DXF File is attached.
Thanks,
RafaelLi
Re: How to mirror an CADArc
Posted: 04 Oct 2019, 00:58
by support
Rafael,
You should call the MirrorEntityInAxis method for each CADEntity on the current layout. For example:
Code: Select all
cadImage2.CurrentLayout.Entities.ForEach(entity => MirrorEntityInAxis(cadImage2, entity, CADAxis.OX));
Mikhail
Re: How to mirror an CADArc
Posted: 04 Oct 2019, 01:36
by rafaellippert
Thansks,
but is now generate with entities with problems. The strokes are misaligning.
The image and DXF File is attached .
Any ideas what it might be?
Thanks,
Re: How to mirror an CADArc
Posted: 04 Oct 2019, 02:18
by support
Rafael,
Could you please specify your CAD .NET version? The latest version (14.1.0) gives the correct result (see attached).
Mikhail
Re: How to mirror an CADArc
Posted: 04 Oct 2019, 02:25
by rafaellippert
I'm using the version 12.1.20.21127
Re: How to mirror an CADArc
Posted: 04 Oct 2019, 02:35
by support
rafaellippert wrote: ↑04 Oct 2019, 02:25
I'm using the version 12.1.20.21127
We couldn't reproduce the problem when using this version. The MirrorEntityInAxis method gives the correct result.
Could you please attach a project which reproduces the problem?
Mikhail
Re: How to mirror an CADArc
Posted: 04 Oct 2019, 21:05
by rafaellippert
Hello,
I downloaded the new version CadImport 14 Trial version.
However, it still has the same problem.
Attached is an example in C # with a demo project in the "DEBUG" folder.
What can I be doing wrong?
Thanks
Re: How to mirror an CADArc
Posted: 05 Oct 2019, 00:18
by support
Hello Rafael,
The code I posted requires a CADImage to be drawn on a GDI+ drawing surface (Graphics object) before mirroring an entity. To draw the CADImage on a certain Graphics object, one needs to use a
CADImage.Draw method which has the following definition:
Code: Select all
public void Draw(Graphics gr, RectangleF Rect);
public void Draw(Graphics gr, RectangleF Rect, System.Windows.Forms.Control control);
In case of a console application which doesn't have a form or control to draw onto, you may use a GDI+ bitmap (Bitmap object) as the drawing surface:
Code: Select all
var arq = @"1101.dxf";
var arq2 = @"1101_virou.dxf";
var cadImage2 = CADImage.CreateImageByExtension(arq);
cadImage2.LoadFromFile(arq);
Bitmap bitmap = new Bitmap((int)cadImage2.PureExtents.Width, (int)cadImage2.PureExtents.Height);
cadImage2.Draw(Graphics.FromImage(bitmap), new RectangleF(0, 0, (int)cadImage2.PureExtents.Width, (int)cadImage2.PureExtents.Height));
cadImage2.CurrentLayout.Entities.ForEach(entity => MirrorEntityInAxis(cadImage2, entity, CADAxis.OX));
Mikhail
Re: How to mirror an CADArc
Posted: 05 Oct 2019, 00:33
by rafaellippert
Perfect!
Now it's Working fine!
Thanks!!
Re: How to mirror an CADArc
Posted: 05 Oct 2019, 19:48
by rafaellippert
Hello Mikhail
The example file 1101_mirrored.dxf you created has the same problem (Compacted with SevenZip).
Please see the attached GIF Video.
After clicking on the ARCs they are moved to the old position..
Thanks,
Re: How to mirror an CADArc
Posted: 07 Oct 2019, 21:31
by support
rafaellippert wrote: ↑05 Oct 2019, 19:48
Hello Mikhail
The example file 1101_mirrored.dxf you created has the same problem (Compacted with SevenZip).
Please see the attached GIF Video.
After clicking on the ARCs they are moved to the old position..
Thanks,
Thank you for the video, we could reproduce the problem with wrong position of the arcs after moving. Please note that the problem concerns only CAD .NET editor, AutoCAD displays the moved arcs correctly.
Mikhail