haplokuon / netDxf

.net dxf Reader-Writer
MIT License
966 stars 392 forks source link

Compatibility issue upgrading from version 2 to 3 #468

Closed xaotix closed 12 months ago

xaotix commented 12 months ago

I have those extensions that I use to copy all objects from a Document to another. But, after upgrading from 2 to version 3, the function doesn't return the same old object.

    public static DxfDocument CloneAll(this DxfDocument document, DxfDocument destiny)
    {
        var entities = document.Layouts.GetReferences(netDxf.Objects.Layout.ModelSpaceName);
        foreach (var obj in entities)
        {
            var entity = obj as EntityObject;
            var t1 = entity.Clone() as EntityObject;

            destiny.Entities.Add(t1);
        }
        return destiny;
    }
    public static List<EntityObject> CloneAll(this DxfDocument document)
    {
        var entities = document.Layouts.GetReferences(netDxf.Objects.Layout.ModelSpaceName);
        var list = new List<EntityObject>();
        foreach (var obj in entities)
        {
            var entity = obj as EntityObject;
            var t1 = entity.Clone() as EntityObject;

            list.Add(t1);
        }
        return list;
    }

Before was an 'EntityObject' now returns a 'DxfObjectReference'

How do I proceed to make this work again?

xaotix commented 12 months ago

I adjusted the functions. Plesae let me know if this is the right way.

    public static DxfDocument CloneAll(this DxfDocument document, DxfDocument destiny)
    {
        var entities = document.Layouts.GetReferences(netDxf.Objects.Layout.ModelSpaceName);
        foreach (var obj in document.Entities.All)
        {
            var entity = obj as EntityObject;
            var t1 = entity.Clone() as EntityObject;

            destiny.Entities.Add(t1);
        }
        return destiny;
    }
    public static List<EntityObject> CloneAll(this DxfDocument document)
    {
        var list = new List<EntityObject>();
        foreach (var obj in document.Entities.All)
        {
            var entity = obj as EntityObject;
            var t1 = entity.Clone() as EntityObject;

            list.Add(t1);
        }
        return list;
    }