This project has moved and is read-only. For the latest updates, please go here.

Need help getting started

May 14, 2016 at 4:42 PM
I'm new to .netDxf. Are there any examples of how to load in a file and loop through all the entities? I'm building an app to generate gcode so I can send the drawing to my laser machine to make small wooden parts.

For example, I need to find all the Lines in the drawings, then locate their X,Y data (I know how to do that if I can find the Line entities) and construct the gcode for those X,Y coordinates (I know how to do that too).

I just need to loop through and find all the Lines, Circles, Arcs and Text. My drawings won't use much more than those entities.

Thanks for any help...
May 15, 2016 at 4:36 PM
Get the source code and take a look at the TestDxfDocument project, there you will find a bunch of samples that I mainly use for testing purposes. They should help you but do not expect any kind of organization. Take a special look at the method
private static DxfDocument Test(string file, string output = null)
it will show you the basic operation of opening and accessing the entities contained in a dxf file.

May 15, 2016 at 5:14 PM
Edited May 15, 2016 at 5:47 PM
Ahhh OK, I see that now.

I copied the DLL file into my solution folder and got the DLL referenced.
I copied the .pdb file into my solution folder...I guess that's all I need to do with that one?

How should I handle the xml file as far as 'installing' it?

May 15, 2016 at 7:02 PM
Edited May 15, 2016 at 9:58 PM
I downloaded the source code and clicked on the VS 2013 solutions link and loaded it into my VS 2013 IDE.

I'm getting a compile error:

Error 1 The name 'nameof' does not exist in the current context C:\Users\fresh1011\Downloads\netdxf-6bc34eff3f17b98fd90f607e054173388b40fbee\netDxf\Entities\Polyline.cs 54 49 netDxf

Do you know what I need to do to remove this error?

Also, do you have a Paypal email address where I can make a donation?

May 16, 2016 at 7:06 PM
Note 1.
The only file you really need to distribute your application is the dll from the release folder. The .pdb of the debug folder contains debugging information, and the .xml contains the inline help for the netDxf classes that appear in the tooltips of your code. Under normal circumstances you will work with the files in the release folder. The main difference between the debug and the release is, that the debug dll will raise any exception occurred while parsing the dxf, while the release will just return null when calling the method DxfDocument.Load(). If you have checked that the file exists and that it is a supported dxf version there is not much you can do. If you have a file that loads correctly in other applications but netDxf returns null, you can check it with the debug dll or, better, send me the file and I will take a look at it, probably there is a bug in the DxfReader. The possible exceptions can be quite cryptic if you are not familiar with the dxf structure.

Note 2.
I should have deleted the old solutions. I have been using some characteristics that are new to the 2015 C# compiler (Roslyn) that will make the code incompatible with older ones, and I have not been keeping track of those changes. In your case the nameof(variableName) is the same as "variableName". You do not have to recompile the whole solution just use one of the compiled dlls, or upgrade your IDE to VisualStudio 2015, the Community Edition is what I use, it is free and it will work just fine.

No I do not have a Paypal account, or anything similar, but thanks anyway. You are the first one asking for it, and if there is more people willing to make donations I could come up with a solution.

May 16, 2016 at 7:42 PM
Thanks for the answers.

If you ever get a Paypal email address, let me know. I'd like to make a donation for your efforts. You should really set that up. Just my opinion.
May 17, 2016 at 6:40 AM
I installed VS Community 2015 and loaded in the VS 2013 .sln file and then loaded in the Program.cs file.

I pressed F5 to run the app and got this compiler error:

"Error Program does not contain a static 'Main' method suitable for an entry point."

But I see main() in Program.cs so I'm confused as to why I am seeing this error msg?
May 17, 2016 at 2:58 PM
If you have open a fresh copy of the source code and you didn't touch anything, the netDxf is set as your startup project and since it is a class library it has no entry point; but, you should have gotten a message box telling you so, instead of a compiler error.

In any case, check that TestDxfDocument is set as your startup project, you can do this selecting the TestDxfDocument and right click over it, then in the contextual menu select "Set as StartUp project". Also check that in the TestDxfDocument properties, in the Application tab, the "Startup object" is set to "TestDxfDcoument.Program".

You do not need to load the solution with the old solution "netDxf2013.sln" just use "netDxf.sln" it is the one that corresponds with VisualStudio 2015.

May 18, 2016 at 5:50 AM
OK, I did all that but am still getting some compile errors:

1.Error Program does not contain a static 'Main' method suitable for an entry point netDxf C:\Users\fresh1011\Downloads\netdxf-6bc34eff3f17b98fd90f607e054173388b40fbee\netDxf\CSC
  1. Error Metadata file 'C:\Users\fresh1011\Downloads\netdxf-6bc34eff3f17b98fd90f607e054173388b40fbee\netDxf\bin\Debug\netDxf.exe' could not be found TestDxfDocument C:\Users\fresh1011\Downloads\netdxf-6bc34eff3f17b98fd90f607e054173388b40fbee\TestDxfDocument\CSC
Thanks for your continued help...
May 19, 2016 at 2:30 AM
Since I can't at the present time run the demo code, I wanted to ask if there was any way to get the angle of a Line entity?

I looked at Line.cs but did not see a property for this.

Thank you...
May 19, 2016 at 6:39 PM
Note 1:
Start with a fresh copy of the source code and change the TestDxfDocument as your startup project, that all you have to do. It looks like you have changed the netDxf project Output type to an application, it is a Class Library.

Note 2:
To get the angle of a line you need to first decide which is your reference plane. If you are making this question, probably you are dealing with 2d drawings where all your entities are expressed in the XY plane. If this is your case all you have to do is take the X and Y components of the line direction and use the method "public static double Angle(Vector2 u)" of the Vector2 class.

May 26, 2016 at 4:18 AM
Thank you.

Another question: I'm starting off with reading Line entities into my drawing canvas. I made some rectangles and they didn't show up so obviously they are not Line entities. What kind of entity are they?
May 27, 2016 at 6:51 PM
Edited May 28, 2016 at 3:16 AM
That will depend on the program you use. But, since there is no rectangle entity in the dxf specification and your program does not export it as lines, I guess it does it as Polylines (3d polyline) or LwPolylines (lightweight polyline), probably the latter since it is a pure bidimensional entity as the rectangle.