Getting shape data from DxfModel

< previous    1 2 3    next >
TorbenVanAssche
4/21/2022 4:33 PM

This is not the case when I try your code with the same file on my device. When logging the amount of PolyLines my output is 564 after changing the WritePolyLines method to count the lines. There should indeed be 2 as you say, I don't knwo where those others are coming from...

Code:
 private static void WritePolylines(IList<Polyline4D> polylines)
        {
            foreach (Polyline4D polyline in polylines)
            {
                i++;
                Console.WriteLine("Polyline: {");
                foreach (Vector4D vector in polyline)
                {
                    Point3D point = (Point3D)vector;
                    Console.WriteLine("   {0}", point.ToString());
                }
                Console.WriteLine("}");
            }

            Console.Write("Total polylines is " + i);
        }

Wout
4/22/2022 7:59 AM

Ah yes, what's happening is that the evaluation version of CadLib is adding some extra entities (text denoting this is an evaluation version). You can filter out the text by adding an if statement and checking the entity type.

On the production version this would be the output:


Polyline: {
0, 0, 0
6.12323399573677E-16, 10, 0
5, 10, 0
}
Polyline: {
5, 10, 0
5, 0, 0
0, 0, 0
}


- Wout

TorbenVanAssche
4/22/2022 8:04 AM

Alright! With this information I will tell management we can achieve what we intend with your library and purchase a license!
Thank you for your help! :p

TorbenVanAssche
4/25/2022 10:10 AM

Slight follow-up question. Can I somehow do this on the level of Blocks instead of on DWG level? we have multiple Blocks on the same DWG file and the polylines should be separate per Block. The code you have provided seems to only check the entity type and disregards the parent / block info that is the parent?

Explicitly stating what I want to do is create a class that holds a list of polylines for each of the blocks in the DWG.

EDIT: Additionally, is there a limitation on the trial as well in regards to PolyLine analysis? We are getting a lot of PolyLines with only 2 coordinates. Though this could just as well be a case of user error from our side.

Wout
4/25/2022 12:50 PM

Hi,

You can find out the block context through property DrawContext.BlockContext. The DrawContext objects can be nested if inserts are nested multiple levels deep, you can navigate the parents through DrawContext.ParentContext.

But if you're just interested in the blocks, you should draw blocks from DxfModel.Blocks one by one. But this may also include blocks that are not currently inserted into the drawing. So it's up to you how you want to organize this.

There's no trial limitation on polyline reading.

- Wout

TorbenVanAssche
4/25/2022 1:50 PM

As we need to construct the template and format for the tool we are making, the second paragraph makes sense to me. The blocks we need are limited per hand-in of the template so we can properly process the information. All blocks that are in the DWG will be required as per the format of the template we are working with.

I assume there is a similar class that handles this for Blocks instead of reading directly from the ModelSpace with the BaseWireFrameGraphicsFactory? Is this a different way of applying this base class?

If there is no limitation on that, there is probably something wrong with the way our files are, or the way we are reading them. Which isn't unreasonable.

Wout
4/25/2022 2:04 PM

Yes, instead of model.Draw, you loop over the DxfBlock.Entities of a block from DxfModel.Blocks, and call DxfEntity.Draw for each entity.

- Wout

TorbenVanAssche
4/26/2022 9:04 AM

Alright, that worked. There is one thing that remains unclear to me. While I am now reading a single block's data. There appears to still be a discrepancy between the expected and delivered result. Or is the screenshotted format the expected output?

I was under the impression that the output would be a list of coordinates but I am receiving a List of 4 polyline objects each containing 2 Vector4D elements (= vertices). I have included the file to be sure we are not making a mistake here with the exported CAD model. I am drawing each entity from the first block (there is only 1 entity) and getting the screenshotted result.

The other blocks have the same result. In that they are always a List of PolyLines (which in turn are a list of Vector4D) in our case only containing 2 elements per polyline...

TorbenVanAssche
5/4/2022 9:25 AM

So after some further testing, I have found out that converting a polyline into a block acts strangely on the data. I have a shape with 8 vertices and 8 lines. But drawing the lines via what you provided gives me 10 elements of which 2-9 are correct. The first and last element are just vertices? I don't know if that is correct. Are you able to verify if that is the expected result?

EDIT: While it would be possible to filter out stuff that is just a point, I would rather understand what the issue is.

Wout
5/6/2022 8:43 AM

For your file Block_test4.5.dwg the output is:


Block Bovenprofiel
Polyline: {
-50, 150, 0
150, 150, 0
150, 200, 0
-50, 200, 0
-50, 150, 0
}
Polyline: {
-45, 155, 0
145, 155, 0
145, 195, 0
-45, 195, 0
-45, 155, 0
}
Block Onderprofiel
Polyline: {
0, 0, 0
6.12323399573677E-15, 100, 0
150, 100, 0
150, 0, 0
0, 0, 0
}
Polyline: {
5, 5, 0
5.00000000000001, 95, 0
145, 95, 0
145, 5, 0
5, 5.00000000000002, 0
}

And this is correct, each block above contain 2 LWPOLYLINE entities.

Code:

C# Code:
            DxfModel model = CadReader.Read(@"C:\support\torben\Block_test4.5.dwg");
            CoordinatesCollector coordinatesCollector = new CoordinatesCollector();
            DrawContext.Wireframe drawContext =
                new DrawContext.Wireframe.ModelSpace(
                    model,
                    GraphicsConfig.BlackBackground,
                    Matrix4D.Identity
                );

            foreach (var block in model.Blocks) {
                Console.WriteLine($"Block {block.Name}");
                foreach (var entity in block.Entities) {
                    entity.Draw(drawContext, coordinatesCollector);
                }
            }

- Wout

< previous    1 2 3    next >