GetSubOccurrenceByName

GetSubOccurrenceByName

Anonymous
Not applicable
548 Views
4 Replies
Message 1 of 5

GetSubOccurrenceByName

Anonymous
Not applicable

Hi guys,

 

I'm developing a tool that should receive an "occurence adress" from elsewhere in the program. (string compName). This is an adress in a way that there are parent - child indicators in the compname.

So for example this would be the component name:

 

upper_middle_stack_area/upper_middle_stack_refractory_GA/upper_middle_stack_ring_course_castable$1

or this:

bosh_area/bosh_mechanical_GA/bosh_plate_cooler_row$1/plate_cooler

 

The last would mean I'm looking for the component "plate cooler" which resides in the assembly "bosh_plate_coolre_row$1" which in turn resides in the assembly .. and so on.

 

The componentnames or the names of the occurrences in Inventor.

 

The first part of this address can be easily retrieved using this code since it resides in my ActiveDocument (allways assembly):

                Inventor.AssemblyComponentDefinition oAssyCompDef = (Inventor.AssemblyComponentDefinition)oAssy.ComponentDefinition;
                Inventor.ComponentOccurrence oOcc = oAssyCompDef.Occurrences.get_ItemByName(sParentName);

Notice the get_ItemByName above?

 

But when i need to go into the suboccurrences of this suboccurrence, I can only get it working by iterating through the SubOccurrences object.

(foreach (Inventor.ComponentOccurrence oSubOcc2 in oSubOcc.SubOccurrences). )

 

Since this action is done 2000+ times, and they are all assembies with lots of occurrences, it is a big performance issue for me. I would like to know if there is some way to go into the suboccurrences object and use some sort of "getitemByname" method.

Instead of iteration through all of them and then checking if the names match.

        private Inventor.ComponentOccurrence GetSubOccurrence(Inventor.ComponentOccurrence oSubOcc, string compName)
        { 
            string sParentName = "";
            if (compName.Contains("/"))
            {
                sParentName = compName.Substring(0, compName.IndexOf("/"));
                compName = compName.Substring(compName.IndexOf("/") + 1, compName.Length - compName.IndexOf("/") - 1);

                               foreach (Inventor.ComponentOccurrence oSubOcc2 in oSubOcc.SubOccurrences)
                {
                    
                    if (oSubOcc2.Name == sParentName)
                    {
                        Inventor.ComponentOccurrence oSubOcc3 = GetSubOccurrence(oSubOcc2, compName);
                        return oSubOcc3;
                    }
                }
            }
            else
            {
                foreach (Inventor.ComponentOccurrence oSubOcc2 in oSubOcc.SubOccurrences)
                {
                    if (oSubOcc2.Name == compName)
                    {
                       return oSubOcc2;
                    }
                }   
            }
            return null;
        }

 

I'm an engineer, not a programmer, so I hope this is understandable for you 🙂

I hope someone can help me with this! I'm using Visual Studio C# Express 2008 btw and Inventor 2010.

 

Best regards!

0 Likes
549 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Nobody?

0 Likes
Message 3 of 5

Anonymous
Not applicable

Should I place it somewhere else? Does anybody know someone who might be able to answer this? Is the question to vague?

0 Likes
Message 4 of 5

herrwolf1
Enthusiast
Enthusiast

Are you wanting to get an occurrence of a specific sub-assembly?

0 Likes
Message 5 of 5

Anonymous
Not applicable

Hi!

 

Everytime I enter this function, the subassemlies / assemblies are different.

 

best regards,

 

Klaas

0 Likes