Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Set Color of Sub-assembly Parts

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
420 Views, 6 Replies

Set Color of Sub-assembly Parts

The code below works fine for setting the top level occurrence colors. What can I do to make it also set the color of parts in sub-assemblies?
Thanks in advance!

Dim oDoc As AssemblyDocument
Set oDoc = invApp.ActiveDocument

Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = invApp.ActiveDocument.ComponentDefinition

' Get references to the two occurrences to constrain.
Dim oOcc1 As ComponentOccurrence
Set oOcc1 = oAsmCompDef.Occurrences.ItemByName(PartName)

Dim oRenderStyle As RenderStyle
Set oRenderStyle = oDoc.RenderStyles.Item(sColor)

oOcc1.SetRenderStyle kOverrideRenderStyle, oRenderStyle
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

This will depend on the behavior you want. Say there are 2 occurrences of a
sub-assembly in the top level assembly. Do you then want to set the part
occurrence color individually for each occurrence within those occurrences?
If so, you need to set the color on a ComponentOccurrenceProxy as shown in
the code below. If you want the color to apply to all instances of the
sub-assembly, you need to jump over to the sub-assembly document and apply
the color there.

Sanjay-

Dim oDoc As AssemblyDocument
Set oDoc = invApp.ActiveDocument

Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = invApp.ActiveDocument.ComponentDefinition

' Get references to the two occurrences to constrain.
Dim oOcc1 As ComponentOccurrence
Set oOcc1 = oAsmCompDef.Occurrences.ItemByName("Assembly1:1")

Dim oOccProxy1 As ComponentOccurrenceProxy
Set oOccProxy1 = oOcc1.SubOccurrences.Item(1)

Dim oRenderStyle As RenderStyle
Set oRenderStyle = oDoc.RenderStyles.Item(sColor)

oOccProxy1.SetRenderStyle kOverrideRenderStyle, oRenderStyle
Message 3 of 7
Anonymous
in reply to: Anonymous

I know the occurrence name even when it is a part of a sub-assembly. Ex: Part:2
I do not know the name of the sub-assembly that the part is in.
I want all part colors to be the same no matter what sub-assembly they are in.
Message 4 of 7
Anonymous
in reply to: Anonymous

So if you color a particular part occurrence as red, do you want it to show
as red even when the sub-assembly in which it lives is opened? Or do you
want to show it in red only in the context of the (current) top level
assembly?

Sanjay-
Message 5 of 7
Anonymous
in reply to: Anonymous

In the top level assembly.
Message 6 of 7
Anonymous
in reply to: Anonymous

The following code should do it. Note that this will change the color of
*all* occurrences of the specified part document at *all* levels in the
current assembly. The full file name of the part document is hardcoded -
you'll need to change that.

Sanjay-


Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.Documents.ItemByName("c:\temp\block.ipt")

Dim oOccs As ComponentOccurrencesEnumerator
Set oOccs = oAsmCompDef.Occurrences.AllReferencedOccurrences(oPartDoc)

Dim oRenderStyle As RenderStyle
Set oRenderStyle = oDoc.RenderStyles.Item(sColor)

Dim oOcc As ComponentOccurrence
For Each oOcc In oOccs
oOcc.SetRenderStyle kOverrideRenderStyle, oRenderStyle
Next
Message 7 of 7
Anonymous
in reply to: Anonymous

This is exactly what I wanted!
Thank you!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report