How to mirror an CADArc
Moderators: SDS, support, admin
-
- Posts: 15
- Joined: 12 May 2016, 18:00
How to mirror an CADArc
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
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
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:
Mikhail
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;
}
}
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
-
- Posts: 15
- Joined: 12 May 2016, 18:00
Re: How to mirror an CADArc
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
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
- Attachments
-
- 1101.zip
- (374 Bytes) Downloaded 763 times
Re: How to mirror an CADArc
Rafael,
You should call the MirrorEntityInAxis method for each CADEntity on the current layout. For example:
Mikhail
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));
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
-
- Posts: 15
- Joined: 12 May 2016, 18:00
Re: How to mirror an CADArc
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,
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,
- Attachments
-
- 1101.zip
- (374 Bytes) Downloaded 707 times
-
- cadimport.png (23.76 KiB) Viewed 9832 times
Re: How to mirror an CADArc
Rafael,
Could you please specify your CAD .NET version? The latest version (14.1.0) gives the correct result (see attached).
Mikhail
Could you please specify your CAD .NET version? The latest version (14.1.0) gives the correct result (see attached).
Mikhail
- Attachments
-
- 1101_mirrored.zip
- The drawing 1101.dxf mirrored in the X axis using CADImport.dll 14.1.0 and MirrorEntityInAxis method.
- (1.72 KiB) Downloaded 749 times
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
-
- Posts: 15
- Joined: 12 May 2016, 18:00
Re: How to mirror an CADArc
I'm using the version 12.1.20.21127
Re: How to mirror an CADArc
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
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
-
- Posts: 15
- Joined: 12 May 2016, 18:00
Re: How to mirror an CADArc
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
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
- Attachments
-
- Teste_CADImport_EspelharWindows.zip
- (939.36 KiB) Downloaded 714 times
Re: How to mirror an CADArc
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:
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:
Mikhail
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);
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));
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
-
- Posts: 15
- Joined: 12 May 2016, 18:00
Re: How to mirror an CADArc
Perfect!
Now it's Working fine!
Thanks!!
Now it's Working fine!
Thanks!!
-
- Posts: 15
- Joined: 12 May 2016, 18:00
Re: How to mirror an CADArc
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,
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,
- Attachments
-
- cadImport_14_Trial.7z
- (1015.27 KiB) Downloaded 724 times
Re: How to mirror an CADArc
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.rafaellippert wrote: ↑05 Oct 2019, 19:48Hello 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,
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support