Converting dwg to directx using C#

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

anitha
Posts: 2
Joined: 21 May 2008, 08:34

Converting dwg to directx using C#

Post by anitha » 21 May 2008, 08:43

Hai,

I want to know, how to convert the dwg file into directx file in C# using cadimport.net? Im using VisualStudio 2005. Is there any dll to be added additionally for this purpose?

Regards,
Anitha

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: Converting dwg to directx using C#

Post by support » 21 May 2008, 09:05

Hello Anitha,

Unfortunately we have no products which allow converting DWG files to a DirectX form.

Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

anitha
Posts: 2
Joined: 21 May 2008, 08:34

Re: Converting dwg to directx using C#

Post by anitha » 21 May 2008, 09:44

Hai Sergey,

Thanks for ur reply...
Is there any possible way 2 convert dwg file to directx file using C# program? Or can we apply the dwg file directly to C# program so that we can implement all the animation effects(zooming, rotation..) as like that in directx file?

Regards,
Anitha.N

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: Converting dwg to directx using C#

Post by support » 21 May 2008, 10:50

Hello Anitha,

We would suggest you to try CAD Import .NET. Web page is: http://www.cadsofttools.com/en/products ... _.net.html
This library gives access to inner data of DWG/DXF files which can be further converted to a DirectX form or interpreted some other way. In this case extended version of the library is required. Please contact us to support@cadsofttools.com accordingly the question of getting extended version of the library.

Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Chris
Posts: 17
Joined: 17 Jun 2008, 01:15

Re: Converting dwg to directx using C#

Post by Chris » 17 Jun 2008, 02:19

I have been successful in using your CAD Import .NET tool to render complex DirectX 3D scenes. I have a few requests on how to streamline the CAD Import .NET utility to make this a cleaner process.

Currently I can support over 500,000 entities rendering at a sustained 30fps on less then impressive video cards.

I am still having a few entity type issues with getting clear information from your dll, but I'm sure that can be easily resolved through collaboration.

by the way, this is Firebird.. no idea where I put the password or email I signed up with, sorry about that.

I will be perusing this forum daily until this project is finished, as the remainder of the 3D interface is completed. I'll gladly show a public promo release once it's available :)

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: Converting dwg to directx using C#

Post by support » 17 Jun 2008, 08:42

Hello!

We are ready to give you all available information about CAD Import .NET.

Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Chris
Posts: 17
Joined: 17 Jun 2008, 01:15

Re: Converting dwg to directx using C#

Post by Chris » 17 Jun 2008, 18:20

The Chief Technical officer will be returning next week and will be able to authorize some of the fine points regarding this process.

As a preview however, there are a few math considerations needed to translate from the CAD world to the real world.

Arc, Circles, and Ellipse, can all be solved by putting their data into this class:

DX.Vector3 CenterPoint // 3 floats X,Y,Z
int Group // handle of the group (default 0, the group contains the handle for the layer)
float Radius // unitless (default 1)
float StartAngle // radians (default 0)
float StopAngle // radians (default 6.283185)
float Ratio // unitless (default 1)
int Sides // number of sides = 0 for self optimization (default 0)
float Rotation // radians (default 0)
Int32 Diffuse // line color (default White.toARGB())
float Height // line height (default 0)
float Width // line width (default 0)

Some video cards can handle double precision floating points, however the benifits versus cost are rarely worth it.

All angles must be positive radians, and the start angle must be smaller then the stop angle. Use coterminals to achieve this.
The angle of Zero should always be on the +X axis
The angle of 1/2 PI should always be on the +Y axis
Elevation values should always be on the +Z axis

Within my 3D GUI, I can add and manipulate these Arc with no problems. Where I am having issues, is trying to figure out why some of the Arc, Circles, and Ellipse provided by the CAD Import .NET library, and in some cases Lines, are reporting coordinates that appear to be reflected over the X axis, or reflected over the Y axis, or translated into some remote area.

I am aware that the DXF file format has a number of locations where entities can inherit translations, and even a header value where entities can inherit rotations, and a number of places where it appears to be able to change the axis of orientation. I can ponder why they did it this way just in the DXF format, however it would be great if there was a WYSIWYG interface with your DLL. Regardless of whatever internal voodoo is required by CAD, if I get values for an Arc or Line, I need those values to be absolute. (I do not store any secondary translations or rotations in the groups or layers, slows down the render cycle)

Here is an abstract of the method and classes I am using to read your DLL's results.

this.trvEntity = new System.Windows.Forms.TreeView();
...
int TotalChildrenNodes = 0;
int TotalParentNodes = trvEntity.GetNodeCount(false);
for (int i = 0; i < TotalParentNodes; i++)
trvEntity.SelectedNode = trvEntity.Nodes;
TotalChildrenNodes = trvEntity.Nodes.GetNodeCount(false);
for (int j = 0; j < TotalChildrenNodes; j++)
selEntity = CADImport.FaceModule.CADImportFace.DecodeEntityExt(trvEntity.SelectedNode, FCADImage, null, 1.0f);
switch (selEntity.EntType)
case EntityType.Line:
case EntityType.Polyline:
case EntityType.Ellipse:
case EntityType.Arc:
case EntityType.Circle:
case EntityType.Text:

And here is an Abstract of how I'm populating Arc from your DLL

case EntityType.Arc:
CADImport.CADArc MyArc = selEntity as CADImport.CADArc;
Rotation = 0.0f; // missing rotation
height = 0.0f; // not available through CAD
width = 0.0f; // missing thickness?
Center_Point = new DX.Vector3((float)MyArc.Point.X, (float)MyArc.Point.Y, 0.0f); // missing elevation
Radius = (float)MyArc.Radius;
Start_Angle = (float)MyArc.StartAngle * ConvertToPI;
Stop_Angle = (float)MyArc.EndAngle * ConvertToPI;
// Adjust for Quadrant IV to Quadrant I crossing
if (TempFVVArc.FVV_Stop_Angle < TempFVVArc.FVV_Start_Angle) { TempFVVArc.FVV_Stop_Angle += (float)(Math.PI * 2); }
Ratio = 1.0f; // not available on CAD arc?
break;

I am confident that you have a better way of getting to this entity data, my method is extremely slow (especially in debug mode). And as you can see, I am missing some important data points.

I look forward to showing you more once I have approval, perhaps we can knock out this arc issue in the mean time.
Thank you for the support.
Chris
3D Software Engineer

Chris
Posts: 17
Joined: 17 Jun 2008, 01:15

Re: Converting dwg to directx using C#

Post by Chris » 19 Jun 2008, 02:04

This is a test CAD file
Image

Here is how the DXF reader is showing it
Image

Here is how the DWG reader is showing it
Image

All arc in the second and fourth quadrants are wrong.
DXF ellipse are just failing all together.
DXF polyline are not showing up. ((CADImport.ObjPolyline MyPolyLines = propGrid.SelectedObject as CADImport.ObjPolyline;))

here are the AutoCAD 2004 saved files in both DXF and DWG format.
http://www.ausukusa.com/workstuff/Drawing1.dxf
http://www.ausukusa.com/workstuff/Drawing1.dwg

I have absolutely no need to save this information back once I've read it, it is being ported into our special DirectX compadible format.
I have no need to display this information in a property grid, or any other GUI for the end user.
I purely need to grab the vector data in an absolute WYSIWYG manor converting the bulky junk of AutoCAD into the streamline form.

Thank you, and please advise.
Chris.

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: Converting dwg to directx using C#

Post by support » 25 Jun 2008, 18:38

Hello Chris,

CAD Import .NET v. 6.3 views your files correctly. It is available at: http://www.cadsofttools.com/download/cadimportnet.zip
I am aware that the DXF file format has a number of locations where entities can inherit translations, and even a header value where entities can inherit rotations, and a number of places where it appears to be able to change the axis of orientation. I can ponder why they did it this way just in the DXF format, however it would be great if there was a WYSIWYG interface with your DLL. Regardless of whatever internal voodoo is required by CAD, if I get values for an Arc or Line, I need those values to be absolute. (I do not store any secondary translations or rotations in the groups or layers, slows down the render cycle)
We would like you to try ImportDemo in the ..\cadimportnet\bin\.. folder. It generates TXT file which contains entties data taking in account all inner rotations and transformations.

Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Chris
Posts: 17
Joined: 17 Jun 2008, 01:15

Re: Converting dwg to directx using C#

Post by Chris » 02 Jul 2008, 21:01

Thank you Sergey,

I will keep working on this. I would have never assumed a file called "TXTImport.cs" would actually contain code for exporting. I never even looked in it.
It will make my bosses happy to know that you have the tool we need.

Chris.

Chris
Posts: 17
Joined: 17 Jun 2008, 01:15

Re: Converting dwg to directx using C#

Post by Chris » 11 Jul 2008, 00:34

I am focusing on Arc right now, and trying to get a 100% conversion. Perhaps I am missing a step that provides the actual start/stop values.

Image

Code: Select all

private void ImportArc(CADArc sender)
{
	FVV.FVV_Arc TempArc = new FVV.FVV_Arc();
	DPoint p = cadParams.matrix.PtXMat(sender.Point);
	//textFile.Add(string.Format("Center of RoundArc: X = {0} Y = {1} Z = {2}", p.X, p.Y, p.Z));
	TempArc.FVV_Center_Point = new DX.Vector3((float)p.X, (float)p.Y, (float)p.Z);
	//textFile.Add(string.Format("Start Angle: {0}", sender.StartAngle));
	TempArc.FVV_Start_Angle = (float)(sender.StartAngle * 0.0174532925);
	//textFile.Add(string.Format("End Angle: {0}", sender.EndAngle));
	TempArc.FVV_Stop_Angle = (float)(sender.EndAngle * 0.0174532925);
	if (TempArc.FVV_Stop_Angle < TempArc.FVV_Start_Angle) // start angle is always less then stop angle
	{
		TempArc.FVV_Stop_Angle += (float)(Math.PI * 2.0);
	}
	//textFile.Add(string.Format("Rx: {0}", sender.Radius));
	TempArc.FVV_Radius = (float)sender.Radius;
	TempArc.FVV_Ratio = 1.0f; // cad arcs are always 1
	if (cadParams.angle != 0.0f && cadParams.angle != -180.0f && cadParams.angle != 180.0f)
	{
		TempArc.FVV_Rotation = (float)(cadParams.angle * 0.0174532925);  // this fixes the top chairs but why?
	}
	if (cadParams.xScale < 0.0)
	{
		// pi - theta, then swap start/stop
		float TempVal = TempArc.FVV_Start_Angle;
		TempArc.FVV_Start_Angle = (float)Math.PI - TempArc.FVV_Stop_Angle;
		TempArc.FVV_Stop_Angle = (float)Math.PI - TempVal;
		if (TempArc.FVV_Start_Angle < 0.0f) // positive coterminals
		{
			TempArc.FVV_Start_Angle += (float)(Math.PI * 2.0);
			TempArc.FVV_Stop_Angle += (float)(Math.PI * 2.0);
		}
		if (TempArc.FVV_Stop_Angle < 0.0f) // positive coterminals
		{
			TempArc.FVV_Start_Angle += (float)(Math.PI * 2.0);
			TempArc.FVV_Stop_Angle += (float)(Math.PI * 2.0);
		}
	}
	if (cadParams.yScale < 0.0) // nothing comes up negative yet
	{
		//TempArc.FVV_Start_Angle -= (float)(Math.PI / 2.0);
		//TempArc.FVV_Stop_Angle -= (float)(Math.PI / 2.0);
	}
	//TempArc.FVV_Rotation = (float)(cadParams.angle * 0.0174532925); // is this already included?
	if (sender.Extrusion.Z < 0.0) // fixes y-axis reflection of arc.
	{
		TempArc.FVV_Center_Point = new DX.Vector3(-(float)p.X, (float)p.Y, (float)p.Z);
		TempArc.FVV_Rotation = -TempArc.FVV_Rotation;
	}
	TempArc.Base.FVV_GroupID = GroupID;
	TempArc.Base.FVV_Inherit = true;
	TempFVVArc.Add(TempArc);
}
I have been working with a couple other interpretations to the values, and this is the closest I've gotten. Also, could you please send me a completed help file? the one I have does not have any content beyond the directory.

As you can see, most of the Arc are generating properly with the provided coordinates. The Ellipse on the earlier test are generated correctly now as well, however I have to add 1/2 PI to the provided Angle for no known reason.

Code: Select all

TempArc.FVV_Rotation = (float)sender.Angle + (float)(Math.PI / 2.0);
and I have to invert the rotation when Extrusion is negative.

Code: Select all

if (sender.Extrusion.Z < 0.0)
{
	TempArc.FVV_Center_Point = new DX.Vector3(-(float)p.X, (float)p.Y, (float)p.Z); // flip over the Y axis
	TempArc.FVV_Rotation = -TempArc.FVV_Rotation; // invert the rotation
}
the ellipse appear to be fine by doing this, but I want it done properly.

Thank you for your continued support.
Chris.

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: Converting dwg to directx using C#

Post by support » 11 Jul 2008, 16:48

Hello Chris,

DXF format some complicated rotations and transformations. That is why when worling with this format it is required to be very careful.

1. StartAngle and EndAngle for ellipses and elliptic arcs do not contain angles, they contain parameter. Please take a look at the image downwards.
2. It is necessary to work with extrusion very carefully. In common case it defines direction along Z axis. Here goes some text from the DXF Reference:

For a given Z axis (or extrusion) direction, there are an infinite number of coordinate systems, defined by translating the origin in 3D space and by rotating the X and Y axes around the Z axis. However, for the same Z axis direction, there is only one OCS. It has the following properties:
  • Its origin coincides with the WCS origin.
  • The orientation of the X and Y axes within the XY plane is calculated in an arbitrary but consistent manner. AutoCAD performs this calculation using the arbitrary axis algorithm (see “Arbitrary Axis Algorithm” ).
For some entities, the OCS is equivalent to the WCS, and all points (DXF groups 10-37) are expressed in world coordinates. See the following table.
-----------------------------------------------------------
Coordinate systems associated with an entity type
-----------------------------------------------------------

3D entities such as line, point, 3dface, 3D polyline, 3D vertex, 3D mesh, 3D mesh vertex:

These entities do not lie in a particular plane. All points are expressed in world coordinates. Of these entities, only lines and points can be extruded. Their extrusion direction can differ from the world Z axis
----------------------------------------------------------

2D entities such as circle, arc, solid, trace, text, attrib, attdef, shape, insert, 2D polyline, 2D vertex, lwpolyline, hatch, image:

These entities are planar in nature. All points are expressed in object coordinates. These entities can be extruded. Their extrusion direction can differ from the world Z axis
----------------------------------------------------------

Dimension:
Some of a dimension's points are expressed in WCS and some in OCS
----------------------------------------------------------

Viewport:
Expressed in world coordinates
---------------------------------------------------------

Sergey.
Attachments
SG_ellipse_definition.jpg
SG_ellipse_definition.jpg (29.04 KiB) Viewed 80029 times
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Chris
Posts: 17
Joined: 17 Jun 2008, 01:15

Re: Converting dwg to directx using C#

Post by Chris » 11 Jul 2008, 17:34

Sergey,

Thanks, that clears up the confusion with why ellipse behave the way they do. A few more questions in that regard.
Does the Z extrusion also act as an order of magnitude? I have seen values such as 1, -1, -34; I would assume the -34 would mean something different from -1?
The DXF reference states that all angles are CCW, is it safe to assume that the angle of 0(zero) is always aligned with the positive X axis?
Are all of the coordinates reported through the CADImport dll in WCS? or do I need to refer to your list above for OCS conditions?

~Chris

EDIT: cadParams.xScale and cadParams.yScale ... are these already accounted for in the position data? the radius data? is it just parenthetical information or do I need to apply this in some fashion?

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: Converting dwg to directx using C#

Post by support » 16 Jul 2008, 16:12

Hello Chris,
Does the Z extrusion also act as an order of magnitude?
Z extrusion influences on the place of entity in the CAD file space.
I have seen values such as 1, -1, -34; I would assume the -34 would mean something different from -1?
Cab you please send us example file for testing to support@cadsofttols.com? If possible, please make it clear of other, superfluous entities.
The DXF reference states that all angles are CCW, is it safe to assume that the angle of 0(zero) is always aligned with the positive X axis?
Yes. it is.
Are all of the coordinates reported through the CADImport dll in WCS? or do I need to refer to your list above for OCS conditions?
In common case if Extrusion exists for an entity, it must be taken into account. But some types of entities contain already recalculated points. For example:

CADPolyLine has a list of CADVertex objects which contain data in OCS. This list is available by the CADPolyLine.Entities method. CADVertex object data plus CADPolyLine.Extrusion must be used to recalculate new point in the WCS.

Also there is list of already made CADPoint objects. It is available by CADPolyLine.DottedSingPts method.
EDIT: cadParams.xScale and cadParams.yScale ... are these already accounted for in the position data? the radius data? is it just parenthetical information or do I need to apply this in some fashion?
xScale - Represents a text width scaling
yScale - Represents a text height scaling

Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Chris
Posts: 17
Joined: 17 Jun 2008, 01:15

Re: Converting dwg to directx using C#

Post by Chris » 16 Jul 2008, 19:03

Sergey,

Our CAD officer is stripping that particular file of customer specific information so that it can be viewed by your team. I will be emailing it to you shortly.

The file I am sending you represents a major portion of what we will be importing. I am also sending you an abstract of the source code for the conversion to our format. Any clarification you can provide regarding this would be greatly appreciated.

Post Reply