Find Top Level Assembly And Make It The Active Document

If a user navigates to a sub component or sub assembly and runs my macro I need SE to find the top level assembly that is currently open (in cache & check out) and change it to the active document.

Anybody have an example of doing this?  Thanks 

 

SEEC/ST2/TCE 7

 

Posted by: Stephen Lyda
Post date: 11/22/2010 9:27:09 AM

1 REPLY

RE: Find Top Level Assembly And Make It The Active Document

Here's a piece of code I used once to find the top-level document. It will need some updating for sync documents and could probably do with a bit of optimizing...

if (document.InPlaceActivated)
{
    /* Get the parent document */ 
    SolidEdgeDocument parent = document;
    while (parent.InPlaceActivated)
    {
        object temp = null;
        Array matrix = new double[] { };
        switch (parent.Type)
        {
        case DocumentTypeConstants.igAssemblyDocument:
        case DocumentTypeConstants.igWeldmentAssemblyDocument:
            ((AssemblyDocument)parent).GetContainerDocumentAndMatrixOfIPADoc(out temp, ref matrix);
            break;
        case DocumentTypeConstants.igPartDocument:
            ((PartDocument)parent).GetContainerDocumentAndMatrixOfIPADoc(out temp, ref matrix);
            break;
        case DocumentTypeConstants.igSheetMetalDocument: 
            ((SheetMetalDocument)parent).GetContainerDocumentAndMatrixOfIPADoc(out temp, ref matrix);
            break;
        case DocumentTypeConstants.igWeldmentDocument:
            ((WeldmentDocument)parent).GetContainerDocumentAndMatrixOfIPADoc(out temp, ref matrix);
            break;
        case DocumentTypeConstants.igUnknownDocument:
        case DocumentTypeConstants.igDraftDocument:
        default:
            break;
        }
        if (temp != null)
        {
            parent = (SolidEdgeDocument)temp; 
        }
        else
        {
            /* If we get here then we couldn't find the top-level document */
            throw new ApplicationException("Couldn't find the top-level document");
        }
    }
}

 

Posted by: Calum McLellan
Post date: 11/22/2010 9:30:11 PM