70000549 A method to get all references objects of a vdLayer that belongs to a specific vdLayout

Article 70000549
Type Wish
Product Engine
Version 7005
Date Added 9/8/2015
Fixed 7.7006.0.1 (9/8/2015)
Submitted by Adam White

Summary

A method to get all references objects of a vdLayer that belongs to a specific vdLayout

Solution

In version 7006.0.1 a new override method GetReferenceObjects(vdLayout layoutOwner) was added in vdLayer object.

This new method returns a copy of the collection that contains all entities reference this object and owns to a specific vdLayout.
If passed layoutOwner is null then all objects that reference this layer object are returned. Same as vdLayer.GetReferenceObjects()

Example 1 :Setting the drawing order by Layer

doc.OnDrawScene += new vdDocument.DrawSceneEventHandler(doc_OnDrawScene);
void doc_OnDrawScene(object sender, vdRender render, vdEntities entities, vdSectionClips sections, vdLights lights, bool FireMeterProgress, ref vdRender.DrawStatus status, ref bool cancel)
{
   
    vdLayout owner = entities.Owner as vdLayout;
    if (owner == null) return;
    foreach (vdLayer  item in doc.Layers)
    {
        if (item.Frozen) continue;
        vdEntities ents = item.GetReferenceObjects(owner);
        status = ents.Draw(render, sections, lights, FireMeterProgress);

    }
    cancel = true;
}


Example 2 :Setting the drawing order by Layer keeping the entities drawing order inside their layout collection

doc.OnDrawScene += new vdDocument.DrawSceneEventHandler(doc_OnDrawScene);
void doc_OnDrawScene(object sender, vdRender render, vdEntities entities, vdSectionClips sections, vdLights lights, bool FireMeterProgress, ref vdRender.DrawStatus status, ref bool cancel)
{
    vdLayout owner = entities.Owner as vdLayout;
    if (owner == null) return;
    //create a dictionary where the key is the object reference and the value is the object position in the list.
    System.Collections.Generic.Dictionary indexdictionary = new Dictionary();
    for (int i = 0; i < entities.Count; i++) indexdictionary.Add(entities[i], i);
    //group the draw oreder by layer
    foreach (vdLayer item in doc.Layers)
    {
        if (item.Frozen) continue;
        //get the layer references figures that belongs to the drawing layout.
        vdEntities ents = item.GetReferenceObjects(owner);
        //sort the layer references using the order that they added in the layout entities collection
        StringArray keys = new StringArray();
        foreach (vdFigure fig in ents) keys.AddItem(indexdictionary[fig].ToString());
        ents.SortByKeys(keys);
        //draw the layer refernces
        status = ents.Draw(render, sections, lights, FireMeterProgress);
    }
    cancel = true;
}

Send comments on this topic.