Assembly pattern element appearance overrides

Assembly pattern element appearance overrides

blandb
Mentor Mentor
1,872 Views
19 Replies
Message 1 of 20

Assembly pattern element appearance overrides

blandb
Mentor
Mentor

Good afternoon. Please look at the code below, I have highlighted something in RED that I was hoping someone could assist with.  I have an assembly that I am using a multi-value set list to set basic names of paint to use. Then I have a Select case statement that states if I choose a selected basic color, then try and check to see if certain components exist, if so paint them the specific color. All works ok because my others rules that build this assembly place the components, then paints them, and then patterns the components. Where it fails, is when I just want to change the color without reconfiguring something. It will change all of the main parent elements of the pattern, but not the second, third, 4th and so on. Why not just select the entire pattern and change the color you might ask? Well, there are bolts, I dont want the bolts painted, just the main parts. So that is why I cannot just paint the entire pattern.

 

I also cannot just paint the main components at the part level because these are standard parts that can be any finish. I am just painting them the main 10 colors we have. We dont have a dedicated part number for the colored version of the component, so I am applying Assembly based appearance overrides at the assembly. As you can see in the image, when this is first configured, the post and panels are the correct color. But if I want to just change a color, now it only changes the parent component because i am not doing the entire pattern. Same concept if you place an part at the assembly level, color override it, then pattern it they will all be that color. But now, change the first element color to something else, all others stay as the original color. Hope this all makes sense 🙂

 

colors.JPG

 

Dim oDoc As AssemblyDocument
Dim oPattern As OccurrencePattern
Dim oElements As OccurrencePatternElements 
Dim oElement As OccurrencePatternElement

oDoc = ThisApplication.ActiveDocument
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("whatever my pattern name is")
oElements = oPattern.OccurrencePatternElements

Select Case PAINT
Case "MED. BRONZE"
Try 'try to set the component state
If Component.IsActive("RIGHT SIDE END POST") = True Then
Component.Color("RIGHT SIDE END POST") = "FNSH000510 (38/60060)"
End If
Catch 'catch error and assume the part does not exist
End Try

Try 'try to set the component state
If Component.IsActive("RIGHT SIDE END POST PATTERN") = True Then
Component.Color("RIGHT SIDE END POST PATTERN ELEMENTS excluding fasteners") = "FNSH000510 (38/60060)"
End If
Catch 'catch error and assume the part does not exist
End Try
case "SILVER"
"repeat info, just different color"
end Select

 

Autodesk Certified Professional
0 Likes
Accepted solutions (2)
1,873 Views
19 Replies
Replies (19)
Message 2 of 20

A.Acheson
Mentor
Mentor

@blandb 

My thoughts, untested and perhaps barking up a tree, would be to change the colour of all the patterns and then set the fasteners back to there default colour . I don't think there is a catch all for fasteners but they could be found either directly through part number or the occurance contains”Washer”,”Bolt”,Nut”, otherwise if you have there placement info like shown in the link that would work as well.

https://forums.autodesk.com/t5/inventor-customization/using-ilogic-to-enable-or-disable-hardware-in-...

 

Perhaps there is a way to isolate the fasteners and not include it in the colour override?

I can only assume if you were to repattern the original assembly after paint change this would have an effect on the drawing losing annotation references as the pattern would disappear and reappear ? 


Hope this helps 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 20

_dscholtes_
Advocate
Advocate

@A.Acheson wrote:

@blandb 

 I don't think there is a catch all for fasteners but they could be found either directly through part number or the occurance contains”Washer”,”Bolt”,Nut”, 


When fasteners are placed from ContentCenter, the <component definition>.IsContentMember property = True. So you could process all elements, check for this property and skip coloring them.

Another option could be to check if the fastener is defined as a purchase part, by looking at the <component definition>.BOMStructure = kPurchasedBOMStructure. Success depending on how you've defined your fasteners and components.

Message 4 of 20

dutt.thakar
Collaborator
Collaborator
Accepted solution

@blandb 

 

Are you looking for something like this? Make sure you change your pattern and appearance name before you test.

 

Dim oDoc As AssemblyDocument
Dim oPattern As OccurrencePattern
Dim oElements As OccurrencePatternElements 
Dim oElement As OccurrencePatternElement
Dim oProjectMgr As DesignProjectManager = ThisApplication.DesignProjectManager
Dim CCPath As String = oProjectMgr.ActiveDesignProject.ContentCenterPath

oDoc = ThisApplication.ActiveDocument
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("Your Pattern Name")
oElements = oPattern.OccurrencePatternElements


If Component.IsActive("Your Pattern Name") = True Then
	For Each oElement In oElements
		For Each oOcc As ComponentOccurrence In oElement.Occurrences
			If oOcc.Definition.Document.FullFileName.Contains(CCPath) = False	
      				 Component.Color(oOcc.Name) = "Appearance Name"
			End If
		Next
	Next
End If 

 

Hope this will be helpful.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
Message 5 of 20

blandb
Mentor
Mentor

@dutt.thakar 

 

Thank you! Once I figured out where to place this, it worked as expected.

 

Thanks again!

Autodesk Certified Professional
0 Likes
Message 6 of 20

_dscholtes_
Advocate
Advocate

@dutt.thakar wrote:

@blandb 

 

If oOcc.Definition.Document.FullFileName.Contains(CCPath) = False	

can be replaced with

 

If oOcc.Definition.IsContentMember = False

 

which is shorter, maybe a tiny bit faster and doesn't require the declarations of both oProjectMgr and CCPath

0 Likes
Message 7 of 20

blandb
Mentor
Mentor

One question, if I have (3) separate patterns that I have to do this with, can I add the names in the "oPattern" section like this: 

oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("Your Pattern Name", "Pattern Name 2", "Pattern Name 3")

 

or would I have to make 3 separate lines like this:

oPattern1 = oDoc.ComponentDefinition.OccurrencePatterns.Item("Your Pattern Name 1")
oElements1 = oPattern1.OccurrencesPatternElements
oPattern2 = oDoc.ComponentDefinition.OccurrencePatterns.Item("Your Pattern Name 2")
oElements2 = oPattern2.OccurrencesPatternElements
--------------same for the third pattern------------------

 

Autodesk Certified Professional
0 Likes
Message 8 of 20

blandb
Mentor
Mentor

tried this, but I get an error message

Autodesk Certified Professional
0 Likes
Message 9 of 20

_dscholtes_
Advocate
Advocate

Sorry, I have made a mistake. My earlier post is incorrect. The 'IsContentMember' property is only available from the <part document>.ComponentDefinition, not from an <Occurrence>.Definition. Same goes for the 'BOMStructure' property. 
That means the solution from dutt.thakar should be used unmodified.

Regarding your other question, you should have three separate lines.

0 Likes
Message 10 of 20

blandb
Mentor
Mentor

Does just the oPattern need to have (3) instances, or does the oElement and oElements need 3 lines as well.

 

Sorry, I'm not a programmer..lol

Autodesk Certified Professional
0 Likes
Message 11 of 20

dutt.thakar
Collaborator
Collaborator

@blandb 

If you only have three patterns and you want to do the same operation in all of them you do not need to define three times. You can use For Each loop.

 

As an example :

Dim oPattern As OccurrencePattern

For Each oPattern In oDef.OccurrencePatterns

 

and then the same code with little modifications where you will not have to specify explicitly pattern name because you are iterating to all patterns and not targeting a specific pattern.

 

Try and see if this is helpful or reply if you still struggle and I will be able to answer you tomorrow morning when I will be in front of Inventor.

 

Hope it helps.

 

 

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 12 of 20

_dscholtes_
Advocate
Advocate

@_dscholtes_ wrote:

Sorry, I have made a mistake. My earlier post is incorrect. The 'IsContentMember' property is only available from the <part document>.ComponentDefinition, not from an <Occurrence>.Definition. Same goes for the 'BOMStructure' property. 


Well, the above statements are based on the info I've found in the Object Browser of the VBA editor. However, I just tried the following code:

 

 

Dim oOcc As ComponentOccurrence
Set oOcc = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, "Select a component to test (or press ESC to quit)")

MsgBox oOcc.Definition.IsContentMember, vbInformation, "test"

 

 

and it works perfectly. It either goes True or False.

[Edit] @blandb Btw, with 170 solutions, you should be some kind of programmer 😛

0 Likes
Message 13 of 20

blandb
Mentor
Mentor

Most of my solutions are on the Inventor side of things, not iLogic. I can handle basic iLogic stuff, but this kind of stuff is over my head.

 

@dutt.thakar 

 

I tried this, but I get an error stating that oDef is not defined, which it isnt, and.....I dont know how lol

 

Dim oDoc As AssemblyDocument Dim oPattern As OccurrencePattern
Dim oElements As OccurrencePatternElements
Dim oElement As OccurrencePatternElement
Dim oProjectMgr As DesignProjectManager = ThisApplication.DesignProjectManager
Dim CCPath As String = oProjectMgr.ActiveDesignProject.ContentCenterPath

oDoc = ThisApplication.ActiveDocument
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("FRONT INTERMEDIATE POST PATTERN")
oElements = oPattern.OccurrencePatternElements

For Each oPattern In oDef.OccurrencePatterns For Each oOcc As ComponentOccurrence In oElement.Occurrences If oOcc.Definition.Document.FullFileName.Contains(CCPath) = False Component.Color(oOcc.Name) = "FNSH000510 (38/60060)" End If Next Next

 

Autodesk Certified Professional
0 Likes
Message 14 of 20

A.Acheson
Mentor
Mentor

@blandb 

 

It is actually used  previously but not referenced as oDef.

 

oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("Your Pattern Name")

 

  • If you back track  oPattern and remove "Item("Your Pattern Name") "you will be able to reference all patterns in your document.

 

oPatterns = oDoc.ComponentDefinition.OccurrencePatterns
  • Back track again and remove ".OccurrencePatterns." This will get reference to components in your Document

'Declaration

oDef  As AssemblyComponentDefinition

'Declaration
oDef As AssemblyComponentDefinition
oDef
oDoc.ComponentDefinition

 

You can also  declare it by using below or replace oAsmCompDef with oDef , Sometimes it is useful to use more descriptive declarations. 

Dim oAsmCompDef As AssemblyComponentDefinition

https://www.augi.com/articles/detail/inventor-ilogic-notes-for-assembly-drawings

 

Like wise  you could display what your looking for as 

For Each oPattern In oDoc.ComponentDefinition.OccurrencePatterns

 Hope this helps. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 15 of 20

blandb
Mentor
Mentor

Sorry, just don't get it.

Autodesk Certified Professional
0 Likes
Message 16 of 20

A.Acheson
Mentor
Mentor

@blandb 

 

I changed oDef out and put in oDoc.ComponentDefinition. The rest I managed to sort with a For loop to count how many patterns in the document then loop through .

 

I couldn't get  below lines to function. So the other for Loop  was used.

Dim oPattern As OccurrencePattern

For Each oPattern In oDef.OccurrencePatterns

 

I am sure there is an easier way to accomplish this I am just not sure how. Below is working anyhow

 

 

Dim oDoc As AssemblyDocument
Dim oPattern As OccurrencePattern
Dim oElements As OccurrencePatternElements 
Dim oElement As OccurrencePatternElement
Dim oProjectMgr As DesignProjectManager = ThisApplication.DesignProjectManager
Dim CCPath As String = oProjectMgr.ActiveDesignProject.ContentCenterPath

oDoc = ThisApplication.ActiveDocument

' Counts the amount of patterns in the Document
Dim oPatternCount As Integer = oDoc.ComponentDefinition.OccurrencePatterns.Count
'Shows how many patterns in the assembly
MessageBox.Show(oPatternCount, "iLogic")

Dim i As Integer
For i = 1 To oPatternCount
	oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item(i)

	oElements = oPattern.OccurrencePatternElements
		
		If Component.IsActive(oPattern.Name) = True Then
			MessageBox.Show(oPattern.Name, "iLogic")
			For Each oElement In oElements
					For Each oOcc As ComponentOccurrence In oElement.Occurrences
							If oOcc.Definition.Document.FullFileName.Contains(CCPath) = False	
				      				 Component.Color(oOcc.Name) = "Beech"
							End If
					Next
				Next
		End If 
	Next  

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 17 of 20

dutt.thakar
Collaborator
Collaborator
Accepted solution

@blandb 

 The code written by @A.Acheson  is also another way to accomplish, but as I was mentioning you can iterate through each pattern and check if it is suppressed it won't go in it and change the color but, you do not need to specify differently each pattern if you want to iterate through all of them and change the color. See below code, where I am not using any counter and iterating through each pattern in an assembly and checking if it is suppressed or not, and if not then only it will iterate through all the elements and change the color of non-content center parts.

 

Dim oDoc As AssemblyDocument 
Dim oPattern As OccurrencePattern
Dim oElements As OccurrencePatternElements
Dim oElement As OccurrencePatternElement
Dim oProjectMgr As DesignProjectManager = ThisApplication.DesignProjectManager
Dim CCPath As String = oProjectMgr.ActiveDesignProject.ContentCenterPath


oDoc = ThisApplication.ActiveDocument


			For Each oPattern In oDoc.ComponentDefinition.OccurrencePatterns
				If Component.IsActive(oPattern.Name)= True
				For Each oElement In oPattern.OccurrencePatternElements
				For Each oOcc As ComponentOccurrence In oElement.Occurrences
					If oOcc.Definition.Document.FullFileName.Contains(CCPath) = False	
		      				 Component.Color(oOcc.Name) = "Yellow"
					End If
				Next
				Next
			End If
			Next

Hope this will be a help.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
Message 18 of 20

A.Acheson
Mentor
Mentor

@dutt.thakar 

 

I had attempted that method but had not removed the variable referencing the named pattern and the elements within that pattern. 

oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item(”Enter Pattern Name Here”)

	oElements = oPattern.OccurrencePatternElements

Every day a school day. Need to spend more time studying 🙈

Thank you for showing the way.

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 19 of 20

blandb
Mentor
Mentor

Thanks everyone for you help. To circle back around to this point, if I DID want 3 separate patterns to be different color, what is the syntax..is it what I have shown here??

 

Dim oDoc As AssemblyDocument
Dim oPattern As OccurrencePattern
Dim oElements As OccurrencePatternElements 
Dim oElement As OccurrencePatternElement
Dim oProjectMgr As DesignProjectManager = ThisApplication.DesignProjectManager
Dim CCPath As String = oProjectMgr.ActiveDesignProject.ContentCenterPath

oDoc = ThisApplication.ActiveDocument

oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("pattern 1 description")
oElements = oPattern.OccurrencePatternElements
oPattern2 = oDoc.ComponentDefinition.OccurrencePatterns.Item("pattern 2 description")
oElements2 = oPattern2.OccurrencePatternElements
oPattern3 = oDoc.ComponentDefinition.OccurrencePatterns.Item("pattern 3 description")
oElements3 = oPattern3.OccurrencePatternElements

If Component.IsActive("pattern 1 description") = True Then
	For Each oElement In oElements
		For Each oOcc As ComponentOccurrence In oElement.Occurrences
			If oOcc.Definition.Document.FullFileName.Contains(CCPath) = False	
      				 Component.Color(oOcc.Name) = "Appearance Name"
			End If
		Next
	Next
End If 

If Component.IsActive("pattern 2 description") = True Then
	For Each oElement2 In oElements2
		For Each oOcc As ComponentOccurrence In oElement2.Occurrences
			If oOcc.Definition.Document.FullFileName.Contains(CCPath) = False	
      				 Component.Color(oOcc.Name) = "Appearance Name"
			End If
		Next
	Next
End If

If Component.IsActive("pattern 3 description") = True Then
	For Each oElement3 In oElements3
		For Each oOcc As ComponentOccurrence In oElement3.Occurrences
			If oOcc.Definition.Document.FullFileName.Contains(CCPath) = False	
      				 Component.Color(oOcc.Name) = "Appearance Name"
			End If
		Next
	Next
End If
Autodesk Certified Professional
0 Likes
Message 20 of 20

dutt.thakar
Collaborator
Collaborator

@blandb 

 

If the above code works for you, that's great and you can proceed with it, Another solution I have is, try the below code, in which you do not need to define three patterns (i.e. oPattern1, oPattern2, oPattern3 etc. ) separately.

 

Dim oDoc As AssemblyDocument 
Dim oPattern As OccurrencePattern
Dim oElements As OccurrencePatternElements
Dim oElement As OccurrencePatternElement
Dim oProjectMgr As DesignProjectManager = ThisApplication.DesignProjectManager
Dim CCPath As String = oProjectMgr.ActiveDesignProject.ContentCenterPath


oDoc = ThisApplication.ActiveDocument

For Each oPattern In oDoc.ComponentDefinition.OccurrencePatterns
		If Component.IsActive(oPattern.Name)= True And oPattern.Name ="Pattern 1 Name"
		For Each oElement In oPattern.OccurrencePatternElements
		For Each oOcc As ComponentOccurrence In oElement.Occurrences
			If oOcc.Definition.Document.FullFileName.Contains(CCPath) = False	
		      		Component.Color(oOcc.Name) = "Yellow"
			End If
		Next
		Next
	End If
				
	If Component.IsActive(oPattern.Name)= True And oPattern.Name ="Pattern 2 Name"
	     For Each oElement In oPattern.OccurrencePatternElements
	     For Each oOcc As ComponentOccurrence In oElement.Occurrences
		If oOcc.Definition.Document.FullFileName.Contains(CCPath) = False	
		       Component.Color(oOcc.Name) = "Red"
		End If
	     Next
	     Next
	End If
				
	If Component.IsActive(oPattern.Name)= True And oPattern.Name ="Pattern 3 Name"
	For Each oElement In oPattern.OccurrencePatternElements
	For Each oOcc As ComponentOccurrence In oElement.Occurrences
		If oOcc.Definition.Document.FullFileName.Contains(CCPath) = False	
		    Component.Color(oOcc.Name) = "Blue"
		End If
	Next
	Next
	End If

Next

 

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes