Replies: 4 comments 8 replies
-
I do not have the time to help you atm thoroughly, but this is exactly what you are looking for and is super fast and Daniel does a great job. No matter what you need to go through, W3 school, etc., get busy, have visual studio 2019 community edition installed (not sure about 21) and a working sample exe project made that can read and write a text file. Once you have that, you can then reference the netDXF runtime (not debug) dll, which is already compiled in the 4.5 release folder, and use that to do what you really want to do (knowing you have a vaild net application that you can compile and run. Once you have your project referencing that dll, you will then import netDXF libraries (see end of this list): There are a great many code examples included with netDXF for opening and reading a file's content. Look and try hard and do your due diligence. Read everything in the code and everything written here. netDXF is very very good and well worth trying hard, no matter what. more later....after hearing you have those things installed and a simple project working without netDXF. |
Beta Was this translation helpful? Give feedback.
-
The first place to start is the TestDxfDocument project that you will find with the source code. There you will find lots of samples that I use for testing. Start executing the console application, it calls a method called "Test" that shows on screen some information of the provided DXF file "sample.dxf", it will show you how to access some of the basic data of the DXF. Some knowledge of AutoCad is advisable, since the DXF is no more than a representation of its internal data structure, and I am maintaining the same nomenclature. The AutoCad documentation is available online. Here you have an example: // layer for all the lines
Layer baseLayer = new Layer("MyLayer")
{
Color = AciColor.Red
};
// create a DXF document, in this case as AutoCad2018 version
DxfDocument doc1 = new DxfDocument(DxfVersion.AutoCad2018);
// create 300 lines
for (int i = 0; i < 300; i++)
{
// create a line and add it to the document
Line line = new Line(new Vector3(0, i, 0), new Vector3(5, i, 0))
{
Layer = baseLayer // assign the line to a layer, by default it will be layer "0"
};
doc1.Entities.Add(line);
}
// save the document
doc1.Save("MyFile.dxf");
// load your own DXF file or use the one just created
DxfDocument doc2 = DxfDocument.Load("MyFile.dxf");
// array for the lines end points
List<Vector3> points = new List<Vector3>();
// iterate through all objects in the active layout "doc2.Entities.ActiveLayout", by default it is the ModelSpace
// if lines are all you want you can directly iterate through "doc2.Entities.Lines" instead of "All"
foreach (EntityObject entity in doc2.Entities.All)
{
// select lines, there are several ways to do this. This is just one of them
if (entity is Line line)
{
// read and store the end points
points.Add(line.StartPoint);
points.Add(line.EndPoint);
}
} |
Beta Was this translation helpful? Give feedback.
-
I have not thoroughly tested your code, but reading it I see a problem on how you are calculating your "ColorNumber" variable. It can be calculated as: But since, it seems, that you are trying to create a rainbow set of colors, it is much easier to use the "AciColor.FromHsl" method, just remember to re-download the code. I have added a fix that affects this method. Here there is an example: DxfDocument doc = new DxfDocument();
const int numColors = 255;
const double saturation = 1.0;
const double lightness = 0.5;
double step = 1.0 / numColors;
for (int i = 0; i < numColors; i++)
{
double hue = i * step;
AciColor color = AciColor.FromHsl(hue, saturation, lightness);
Layer layer = new Layer("Layer" + i.ToString("000"))
{
Color = color
};
doc.Layers.Add(layer);
}
doc.Save("test.dxf"); Another detail, The layer "0" is a default layer that must always be present in the document and it will take preference over any other layer "0" associated to an entity that you try to add to the document. All named objects, all classes that derive from TableObject, must be unique, there cannot be two with the same name. This is the case of layers, line types, styles,..., It is similar as when you copy an entity into another document, the named objects in the destination document will have preference over the ones on the original drawing, so any duplicates will have to be solved manually if necessary. |
Beta Was this translation helpful? Give feedback.
-
The AciColor is a 24 bit color since only requires the rgb channels; but the methods FromTrueColor and ToTrueColors methods use/returns 32 bit integer, and the byte for the alpha is not used whatever its value. That is how it is saved in the DXF, but you should not worry about those two methods, there is not even a reason for you to use them. If you want to manually calculate the rgb values, just initialize a new AciColor with those values, just use the constructor you prefer, passing 3 bytes or 3 doubles. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I think the netDXF Library looks very interesting for my application (laser processing research project). However, I am not only a beginner in using netDXF, but also in C# programming, so I could use some tips / examples on how to use the netDXF Library.
My task is comparatively simple:
That means concretely my questions are:
a) How do I search a loaded DXF file for specific elements (e.g. lines)?
b) How can I write the start and end points of ALL found line elements into an array?
Possibly the questions seem trivial, however I am still completely unclear how to work with the netDXF library.
Many thanks & greetings,
André.
Beta Was this translation helpful? Give feedback.
All reactions