How to get ComponentOccurrences(s) from known ComponentDefinition in assembly

How to get ComponentOccurrences(s) from known ComponentDefinition in assembly

Anonymous
Not applicable
2,115 Views
11 Replies
Message 1 of 12

How to get ComponentOccurrences(s) from known ComponentDefinition in assembly

Anonymous
Not applicable

I am trying to get all component occurrences in assembly per given ComponentDefinition.

What is the quickest way to do this?

0 Likes
2,116 Views
11 Replies
Replies (11)
Message 2 of 12

philip1009
Advisor
Advisor

It's directly under Component Definition as "ComponentDefinition.Occurrences".

0 Likes
Message 3 of 12

Anonymous
Not applicable

Thank you for reply.

I am not looking for occurrences when compdef is an assembly. I am looking for occurrence(s) where definition is parent. For example:

"oCompOcc.Definition" --> oCompOcc is made from Definition (which is ComponentDefinition object). I am looking to get oCompDef from Definition.

0 Likes
Message 4 of 12

ianteneth
Advocate
Advocate

Hi! This is a very confusing statement. Do you want to get the AssemblyComponentDefinition from any given ComponentOccurrence? The parent of a ComponentOccurrence is the AssemblyComponentDefinition?

 

ComponentOccurrence.Parent ' Returns AssemblyComponentDefinition

 

Sorry if this isn't what you are looking for, but it is hard to understand your question.

0 Likes
Message 5 of 12

Anonymous
Not applicable

Reverse from what you are saying. Get all occurrences that are made from compdef.

CompDef is one. Occurrences are one or many. But they are all based on CompDef.

For example: CompOccs = GetAllOccFrom(CompDef)

0 Likes
Message 6 of 12

ianteneth
Advocate
Advocate

Here is an example browser tree.Capture.JPG

 

Still trying to understand . So for this example, the method you are looking for would return this?

var CompDef = Assembly3.iam

GetAllOccFrom(CompDef) ' Returns: ' 22990002:1, ' 29990001:2, ' 29990002:2, ' Assembly11:1, ' TEST0269:1, ' TEST0280:1

 

 

Message 7 of 12

philip1009
Advisor
Advisor

I'm sorry it's still not quite clear to me.  When you say oCompDef, you mean a component definition of an existing occurrence inside an assembly.  So when you say get all occurrences made from that oCompDef, do you mean derived parts, is it an iPart, a multi-body part?  Is there an example assembly to show us what you would normally do that you're now trying to automate with iLogic?

0 Likes
Message 8 of 12

Anonymous
Not applicable

22990002 is occurrence. There are two 22990002 occurrences. Each of these two occurrences have same ComponentDefinition object.

So in this example:

Dim oCompOcc As ComponentOccurrence '22990002 occurrence
Dim oCompDef As ComponentDefinition
oCompDef = oCompOcc.Definition 'Get CompDef object for given occurrence

I can get ComponentDefinition object from occurrence in the above example.

 

What I need is to find all occurrences (22990002:1, 22990002:2) for oCompDef object.

For example:

Dim oCompDef as ComponentDefinition
Dim oCompOccEnum as ComponentOccurrencesEnumerator
set oCompOccEnum = oCompDef.GetAllOccurrences '(NOT oCompDef.Occurrences)

oCompOccEnum would have occurrences 22990002:1 and 22990002:2

I hope this clears confusion.

Message 9 of 12

philip1009
Advisor
Advisor

Okay, so you're just looking for quantity of matching parts based on their component definition.  I'm not sure if it's possible since trying to compare component definitions with an "=" inside an If Then statement results in an error.  If you're just looking for quantity of matching parts, there are easier ways such as looking for the same part number:

iProperties.Value("part1:1", "Project", "Part Number")

Would that work, or is there some reason I'm not aware of that you need to use the component definition?

0 Likes
Message 10 of 12

Anonymous
Not applicable

Currently, I am using:

oAsmDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oCompDef)

but I have to go back all the way to the main assembly (in our example: Assembly3.iam) to get what I want. I was just wondering if there is a "shortcut" from oCompDef object that I am not aware of.

0 Likes
Message 11 of 12

philip1009
Advisor
Advisor

Sorry I missed the last line on your previous post.  I found the API Property you're looking at, ComponentOccurrences.AllReferencedOccurrences:

Input DocumentDescriptor, ComponentDefinition or a Document object. All occurrences that reference the given object are returned.

 

I don't think it means it returns all matching component definitions, I think it means it returns all occurrences that reference that component definition or document such as geometric projections or parameter links.

 

The only other possible shortcut I see is ComponentOccurrences.AllLeafOccurrences([LeafDefinition] As Variant) As ComponentOccurrencesEnumerator:

Occurence to be used as the basis for filtering the leaf space for a given leaf occurence.  This is an optional argument whose default value is null.

 

But the description for that is more confusing than AllReferencedOccurrences.  Other than that, I don't see a quick way to build a collection of matching occurrences.  It looks like you'll have to build the collection yourself using a simple For loop to find all matching parts in some way.  The example below makes an object collection of component occurrences with the part number 22990002:

 

Dim oCompOccs As Collection
For Each oCompOcc As ComponentOccurrence In ThisDoc.Document.ComponentDefinition.Occurrences
	If iProperties.Value(oCompOcc.Name, "Project", "Part Number") = "22990002" Then oCompOccs.Add(oCompOcc)
Next

 Good luck with your project.

Message 12 of 12

Anonymous
Not applicable

Philip,

I hoped there is a "shortcut" to get what I wanted, instead of looping through object collection or any other collection.

Now, I know there is none.

I heard that 2030 version will have this option available ... 😉