Assembly.Component. Item property

Assembly.Component. Item property

Cris-Ideas
Advisor Advisor
1,142 Views
37 Replies
Message 1 of 38

Assembly.Component. Item property

Cris-Ideas
Advisor
Advisor

Hi,

I have found that Assembly components can be access by Item property Of ComponentOccurences.

 

My concern is if this can be used as ID of given component? Will by given Item value I will always get reference to the same instance (if exists).

 

So sing the example.

 I have an assembly with 8 parts.

in this state part8 will be referenced by Item 8 in the collection.

But if I delete part 5. Will item 8 be referencing the same part as before?

(Suppose not, but not sure).

 

Cris.

 

Cris,
https://simply.engineering
0 Likes
1,143 Views
37 Replies
Replies (37)
Message 21 of 38

Frederick_Law
Mentor
Mentor

How much programming you have done before?

0 Likes
Message 22 of 38

Cris-Ideas
Advisor
Advisor

have made this using Visual Studio.

 

but do not have any proper programming education. I taught everything my self.

 

Cris.

 

Cris,
https://simply.engineering
Message 23 of 38

Frederick_Law
Mentor
Mentor

Pretty good.

At least all DIM are together.

0 Likes
Message 24 of 38

Cris-Ideas
Advisor
Advisor

Best is that it works.

And it is being used on production.

 

Cris.

Cris,
https://simply.engineering
0 Likes
Message 25 of 38

Frederick_Law
Mentor
Mentor

Some thought.

Do you need to track every visibility change?

Can you just track one with associative turn on?  Change back to same DVR and turn associative on.

 

I didn't get around to check in inventor if changing visibility will change DVR in non-associated components.

The goal is to only "fix" things thats cause problem.  Not changing everything that's change.

 

You can start writing the program and try to detect visibility change and add the component name to a list or a text file.

Something you check that's its working.

Solving one problem at a time.

0 Likes
Message 26 of 38

Cris-Ideas
Advisor
Advisor

OK,

I propose to start doing it and solve problems in turn, than all will be clear.

I have peaty good vision how I will get the result.

 

- 1 thing to solve

I currently do not have a clue how to select a component and have reference to it.

I mean particular component of the instance of the assembly or part in top level assembly.

Hitch property of the component should I use so to precisely select exactly the one I need to refer to?

Here I found a list of properties of ComponentOccurence Object that probably is the object I need to reference.

ComponentOccurence Object

But I see nothing that would be usable for referencing a particular component within the assembly structure (like ID).

 

using example:

 

I do not have a clue how to approach this.

 

I am thinking that maybe SelectionSet object I could create and add component to this selection and just use SelectionSet Object to hold references to components.

 

 

Cris.

Cris,
https://simply.engineering
0 Likes
Message 27 of 38

Frederick_Law
Mentor
Mentor

Do you want user to select?  Or program to select by going through every component.

 

I thinking the program will monitor visibility change.

When a component get turn off, program add it to a list.

 

You can use the selection set to add components.

There is an example in API help.

 

0 Likes
Message 28 of 38

Cris-Ideas
Advisor
Advisor

First approach is I want user to select.

User selects first and than "uses button"

 

 

Cris.

Cris,
https://simply.engineering
0 Likes
Message 29 of 38

Cris-Ideas
Advisor
Advisor

Is the idea with selection set something that may work?

 

Cris.

Cris,
https://simply.engineering
0 Likes
Message 30 of 38

Frederick_Law
Mentor
Mentor

Ok.

Program will check if SelectionSet is empty.

Prompt user to select if empty, program end.

Else start process SelectionSet.

 

You don't need to code interactive selection in the program this way.

0 Likes
Message 31 of 38

Cris-Ideas
Advisor
Advisor

Thanks,

But your shortcuts are too big for me to follow. But do not wary I will catch up as we go.

 

I will do something and get back.

found some example will use this as base.

 

Cris.

Cris,
https://simply.engineering
0 Likes
Message 32 of 38

Frederick_Law
Mentor
Mentor

You can test the code in VBA inside Inventor first.

So you don't need to figure out how to install addin, make icon for ribbon, add icon to ribbon etc.

0 Likes
Message 33 of 38

Frederick_Law
Mentor
Mentor
0 Likes
Message 34 of 38

Cris-Ideas
Advisor
Advisor

Have made first step.

And stuck.

 

 

Cris.

 

Cris,
https://simply.engineering
0 Likes
Message 35 of 38

Frederick_Law
Mentor
Mentor

I think oComponentList is still Empty.

 

You just check if obj is assembly inside the for loop, if it is then add it to oComponentList.

 

Sorry if I missed anything.  No speaker on my work computer.

0 Likes
Message 36 of 38

Frederick_Law
Mentor
Mentor

Ok just checked API help and you are trying to add obj to oComponentList.

Don't know if it proper use of SelectSet.

Maybe you need to use array of object or assembly.

0 Likes
Message 37 of 38

Frederick_Law
Mentor
Mentor

You could set obj to the proper type, ComponentOccurance.

If you only add Assembly to your list, make it a list of assembly object.

This way VS can show properties and method.

0 Likes
Message 38 of 38

Frederick_Law
Mentor
Mentor

This example maybe better: http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-3C33DEB3-4441-4AB9-892A-262084072036

 

    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    ' Find all selected occurrences and add them to an ObjectCollection.
    Dim oSelectedOccs As ObjectCollection
    Set oSelectedOccs = ThisApplication.TransientObjects.CreateObjectCollection
    Dim i As Long
    For i = 1 To oDoc.SelectSet.Count
        If oDoc.SelectSet.Item(i).Type = kComponentOccurrenceObject Then
            oSelectedOccs.Add oDoc.SelectSet.Item(i)
        End If
    Next

You can change the kComponentOccurrenceObject to enum for assembly object.

0 Likes