suppress and un-suppress using VB codes

suppress and un-suppress using VB codes

Anonymous
Not applicable
646 Views
5 Replies
Message 1 of 6

suppress and un-suppress using VB codes

Anonymous
Not applicable
Would anyone know the code to “suppress” and “un-supress” a part (.ipt) or a sub-assembly (.iam) from a main assembly (.iam) using Visual Basic please?
This may be possible using “include” and/or “exclude”, however I would need the VB code.

Please don't hesitate to suggest anything, as this may lead to the answer.
Thank you very much.
0 Likes
647 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
If you want to suppress a piece of an assembly, you need to do the following.

1) Cast the main assembly Document object into an AssemblyDocument
2) In the AssemblyDocument.ComponentDefinition object, you'll find an Occurrences property. This is a collection of ComponentOccurrence objects that match up to all the components of the assembly
3) If you know the name of the part you want to suppress (which is what appears in the Model Browser), you can use the Occurrences.ItemByName method. Otherwise, you'll have to loop through the occurrences until you find the one you want. So if you want to suppress the occurrence for "Part1.ipt", do something like this:
{code}
For each objOccurrence as Inventor.ComponentOccurrence in objAssemblyDocument.ComponentDefinition.Occurrences
If Ctype(objOccurrence.Definition.Document, Inventor.Document).DisplayName= "Part1.ipt" Then
objOccurrence.Suppressed = True
Exit For
End If
Next
{code}

A quick note: If you've got any Virtual Components, then the definition's Document property is going to return the Assembly document of the virtual component's parent. You'd want to cast the Definition into a VirtualComponentDefinition object and check its name property instead. You can use "typeof objOccurrence.Definition Is VirtualComponentDefintion" to find this out.
0 Likes
Message 3 of 6

Anonymous
Not applicable
Thank you peter,

I will try the codes this weekend and will report the outcome.

With Many Thanks

Siamak
0 Likes
Message 4 of 6

Anonymous
Not applicable
Hello Peter,

Thank you for your last reply, very good. It’s working.
I have hit a small problem with "Component patterns". All the elements can be suppressed individually but not the pattern itself. This can be done in inventor manually, so there must be a way within vb. It seems like inventor treats pattern different to "ComponentOccurrence".
Would you know what I need to dimension and subsequently suppress pattern?

With Many Thanks
Siamak Sharifi
0 Likes
Message 5 of 6

Anonymous
Not applicable
The suppression of a pattern thru the UI is simply a shortcut to suppressing
all occurrences within the pattern. The API equivalent would be to iterate
over all elements, nd for each element iterate over all occurrences
(OccurrencePatternElement.Occurrences) and suppress each occurrence.

Sanjay-
0 Likes
Message 6 of 6

Anonymous
Not applicable
What Sanjay said. The code I posted is from a little addin I wrote for a coworker that suppresses and makes transparent occurrences. You can toggle them all on/off, the one you've selected, or all but the one you've selected. Part of the fun in writing it was discovering what happens with the occurrence patterns.

In order to determine what it was I clicked on, I run the contents of the active document's SelectSet through some typeof statements. You'll want to check that it is of type ComponentOccurrence, OccurrencePattern, or OccurrencePatternElement. From each of them, you can grab all the occurrences you want to suppress or whatever.
0 Likes