-
Hey, I am sorry for my dumb beginner question but i want to get the coordinates from an existing BoundaryPath. I easy get all the Entity Objects with something like this: foreach (var hatch in dxf.Hatches) but I am stuck how to cast the EntityObjects to the specific entity like a polyline =( Absolute awesome nugget by the way. Very cool and easy to use! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Casting an EntityObject to the specific type of entity is done like any other casting, there is nothing special about it as long as you are casting your object to the correct class that inherits from it. You cannot do what the question in your title suggest "How to Cast a EntityObject to an specific Entity like LwPolylineVertex?", the LwPolylineVertex class does not inherit from EntityObject. You can find more specific instructions on how casting is done in the documentation of the C# language. EntityObject entity;
LwPolyline p1 = (LwPolyline) entity; // this is not safe since multiple entity classes inherit from EntityObject
// perform a safe cast, there are several methods the syntax may depend on the C# language version you are working with
LwPolyline p2 = entity as LwPolyline;
if (entity != null)
{
// do something with p2
}
// or
if (entity is LwPolyline p3)
{
// do something with p3
}
// additionally, the EntityObject class contains a property called Type that will tell you which kind of entity the object represents.
if (entity.Type == EntityType.LwPolyline)
{
LwPolyline p4 = (LwPolyline) entity; // now you can safely cast the object "entity" since you know its type
// do something with p4
} Post a sample code pointing out which is the entity object you are trying to cast. And now a couple of comments on your post.
|
Beta Was this translation helpful? Give feedback.
Casting an EntityObject to the specific type of entity is done like any other casting, there is nothing special about it as long as you are casting your object to the correct class that inherits from it. You cannot do what the question in your title suggest "How to Cast a EntityObject to an specific Entity like LwPolylineVertex?", the LwPolylineVertex class does not inherit from EntityObject. You can find more specific instructions on how casting is done in the documentation of the C# language.