Convert selected Entities to Line/Arc/PolyLine etc.

1 2    next >
SnTick
4/23/2021 1:29 PM

Hello

I am trying to get the length of all the selected entities in my model.
I would like to convert the selected Entity ex. DxfLine to a Line2d or Line3d so that i can make some calculations on that object.

Is this possible and how?
the same for all the other line types i have selected so that i can sum up the length of the selected lines.

Thx.

Wout
4/23/2021 2:13 PM

So you just need the lengths? You don't need the actual conversion, correct? Have a look at the GetCoordinates example, that converts entities to polylines, and then you can call GetLength() on the polylines.

- Wout

SnTick
4/23/2021 4:16 PM

Hello

Thanks a lot for the quick answere.
i have looked into the GetCoordinates examble project, but i cannot see how i can use this to convert a single selected entity into a polyline and then use GetLength on that.

Wout
4/23/2021 4:46 PM

What do you mean? The example just shows you how to go from entity -> polyline, and then you can get the length from that. It's pretty simple.

Edit: for example, for a single entity you'd do this:

C# Code:
model.Entities[0].Draw(drawContext, coordinatesCollector);

- Wout

SnTick
4/23/2021 5:34 PM

sorry for nok understanding this corectly. msybe i should try du explain it in another way.

i have a project where i have started with the WinFormsViewExample projekt. i load a DXF file that is viewed for the user.
Then when the user selects an entity i whhant to catch this selection in the SelectInteractor_SelectionChanged method and in here take the sum of all the lengths from the selected entities. and then view it for the user.

when i call model.Entities[0].Draw(drawContext, coordinatesCollector) i do not get the polyline returned so that i can use it afterwards. How do i achieve this?

hope its a bit more clear.

Wout
4/23/2021 6:10 PM

I just provided model.Entities[0] as an example, ofcourse you wouldn't just call Draw on the first entity only.

When you get RenderedEntityInfo object from the selection, property RenderedEntityInfo.Entity gives you the entity, you can use that instead of model.Entities[0].

- Wout

SnTick
4/23/2021 6:24 PM

i get that part.

But when i call Draw(drawContext, coordinatesCollector) on the entity i need, where do i then get the polyline from. the method Draw is void and do not return the polyline to where i call draw from.

i need the polyline and the calling position so that i can sum up the value og polyline lengths.

Wout
4/23/2021 6:34 PM

In the GetCoordinates example, file Program.cs, class CoordinatesCollector, in method WritePolylines it writes the output polylines. For dots and lines there are no polylines though, just dots and lines, just look in the CoordinatesCollector. Did you try running the GetCoordinates example? You should see output, and you can debug the program to get a better understanding.

- Wout

SnTick
4/23/2021 7:08 PM

Yes i have debugged it many times :P

i think i found a solution. i ended up making a list of polylines in the CoordinatesCollector class and adding all the polylines i find into that. then going though them afterwards and adding up the length.

But when will an Entity be a Line or a Dot?
In the DXF/DWG files we have loaded until now contains of Dxflines, and some arcs and other stuff. that converts to polyline with this new method.

Wout
4/23/2021 7:11 PM

Depends on the entity. All the methods in the CoordinatesCollector can get called potentially, depending on how the entity looks. a LINE entity will just result in a line for example, but there maybe be (parts of) other entities containing line segments.

- Wout

1 2    next >