C# Help Examples for Assemblies Occurences

Here is another section of VBA examples converted to C#. These functions are related to using occurrences in assemblies. This group was fairly easy to migrate compared to some of the other sections I did for previous posts. Also there were several C# examples already in the help file. I added them to the project for completeness.

image

This project has the following functions.

 Download InventorHelpExamples_Assembly_Occ

AddOccurrencesToFolder
Demote
Promote
ReplaceContentCenterPart
AssemblyCount
MoveOccurrence
AddOccurrence
AddiAssemblyOccurrence
AddiPartOccurrence
iMateDuringOccurrencePlacementSample
AddOccurrenceWithRepresentations

 

Here is the AddOccurrencesToFolder function:"

// Add assembly occurrences to a new folder API Sample

//Description 
//Demonstrates assembly occurrences to a new folder
//Have an assembly with at least one occurrence in it 
//and run the sample.
public void AddOccurrencesToFolder()
{
    AssemblyDocument oDoc =
             default(AssemblyDocument);
 
    oDoc = (AssemblyDocument)
                ThisApplication.ActiveDocument;
 
    AssemblyComponentDefinition oDef =
            default(AssemblyComponentDefinition);
                 oDef = oDoc.ComponentDefinition;
 
    BrowserPane oPane = default(BrowserPane);
    oPane = oDoc.BrowserPanes.ActivePane;
 
    ObjectCollection oOccurrenceNodes =
                      default(ObjectCollection);
    oOccurrenceNodes = (ObjectCollection)
        ThisApplication.TransientObjects.
                      CreateObjectCollection();
 
 
 foreach (ComponentOccurrence oOcc
                            in oDef.Occurrences)
    {
        BrowserNode oNode = default(BrowserNode);
    oNode = oPane.GetBrowserNodeFromObject(oOcc);
        oOccurrenceNodes.Add(oNode);
    }
 
    BrowserFolder oFolder = default(BrowserFolder);
        oFolder = oPane.AddBrowserFolder
        ("My Occurrence Folder", oOccurrenceNodes);
 
}

-Wayne


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading