Color pattern iLogic

Color pattern iLogic

e_jansonLT2PV
Explorer Explorer
1,837 Views
22 Replies
Message 1 of 23

Color pattern iLogic

e_jansonLT2PV
Explorer
Explorer

I have an asset of one solid body. There are patterns which consist of several extrusions. I want to color that extrusions differently, but I can only give the whole pattern one color if I use the Feature Properties. 

 

Is there a way to color different features of a pattern in different colors using ILogic?

0 Likes
Accepted solutions (1)
1,838 Views
22 Replies
Replies (22)
Message 2 of 23

Frederick_Law
Mentor
Mentor
Message 3 of 23

e_jansonLT2PV
Explorer
Explorer

Could you please post a syntax as an example? I get error messages I need to declare parameters? I'm quite new to Ilogic, so I appreciate your help.

0 Likes
Message 4 of 23

Frederick_Law
Mentor
Mentor

Attach your code here.

0 Likes
Message 5 of 23

e_jansonLT2PV
Explorer
Explorer
Load_SD.GetReferenceKey()
	Feature.Color("Load_SD") = "RAL 6024 Traffic Green"

Load_SD would be the extrusion I want to find in all patterns. Then I would like to set the color.

0 Likes
Message 6 of 23

_dscholtes_
Advocate
Advocate

You mean something like this?

Pattern Colored.png

 

iLogic (rule):

 

'Declare array list of appearances to use
Dim sColorList As New ArrayList

'Add appearances to list
sColorList.Add("Anodized - Blue")
sColorList.Add("Forest Green")
sColorList.Add("Magenta")
sColorList.Add("Yellow")
sColorList.Add("Dark Green")



'Set global references
Dim oDoc As PartDocument = ThisDoc.Document
Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition

'Set reference to first rectangular pattern
Dim oPattern As RectangularPatternFeature = oCompDef.Features.RectangularPatternFeatures(1)


'Declarations
Dim i As Long
Dim oPatElem As FeaturePatternElement
Dim oFace As Face
Dim oLibAsset As Asset
Dim oLocAsset As Asset
Dim oExtrFeat As PartFeature


'Iterate through each pattern element
For i = 1 To oPattern.PatternElements.Count

	'Set reference to asset in library based on name in list
	oLibAsset = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library").AppearanceAssets.Item(sColorList(i-1))

	'Copy asset to document
	Try
		oLocAsset = oLibAsset.CopyTo(oDoc)
	Catch
		oLocAsset = oDoc.AppearanceAssets.Item(sColorList(i-1))
	End Try


	'Set reference to specific pattern element
	oPatElem = oPattern.PatternElements(i)

	'Check if first pattern element is to be colored
	If oPatElem.Faces.Count = 0 Then

		'Get source extrude feature of pattern
		oExtrFeat = oCompDef.Features(oPattern.Definition.ParentFeatures(1).name)

		'Iterate through all faces of the pattern source feature and color them
		For Each oFace In oExtrFeat.Faces
			oFace.Appearance = oLocAsset		
		Next
		
	'Or if other pattern element is to be colored
	Else
		
		'Iterate through all faces of the selected pattern element and color them
		For Each oFace In oPatElem.Faces
			oFace.Appearance = oLocAsset
		Next
	End If
Next

 

Please note that:

  • I hard-coded the first (and only) pattern in my test model in line 18.
  • There's no error handling except for copying the asset to the document.
Message 7 of 23

e_jansonLT2PV
Explorer
Explorer

Rack.png

 Many thanks for your answer, but my problem is the following: 

I have an extrusion for the load and one for the pallet in the first row and also an extrusion for the load and one for the pallet in the second row. Then I have a pattern for one rack unit in the front (pattern 1) and one in the back (pattern 2). Then I have a pattern for the rack units (pattern 3). What I want to do is color all pallets in one color and all loads in another color. 

0 Likes
Message 8 of 23

_dscholtes_
Advocate
Advocate

I'm having trouble understanding the image and your story, probably because I don't speack 'rack building' fluently 😛

Anyway, am I correct when I say:

  1. You created an extrusion to create a box shape (what you call 'load').
  2. You created an extrusion for a pallet under the box / load (3x small rectangular shapes per box).
  3. Item 1 and 2 are located at 'first row' / 'in the front'
  4. You created item 1 and 2 again, but then located at 'second row' / 'in the back'
  5. Pattern1 creates 9 boxes with pallets at 'first row' / 'in the front' (3x3).
  6. Pattern2 creates 9 boxes with pallets at 'second row' / 'in the back' (3x3).
  7. Pattern3 creates 3 sets of pattern 1 and 2 (2x (3x9)).

 

Would it be possible to share your model (v2023 ipt, stripped of any confidential information of course)?

Message 9 of 23

e_jansonLT2PV
Explorer
Explorer

You are correct with your assumptions 🙂 All patterns can be changed with parameters, so a lot of combinations are possible. 

I am currently working on the assets with Inventor 2024, so I can't give you a model for Inventor 2023. A step file wouldn't help you much I think?

0 Likes
Message 10 of 23

Frederick_Law
Mentor
Mentor

Colour it the way you want and screen shot.

2 or 3 different size patterns so we can see the "color pattern".

 

There are 3 directions: X, Y, Z.

You want different color on all 3?  So 3x3 array has 9 color?

0 Likes
Message 11 of 23

e_jansonLT2PV
Explorer
Explorer

Rack_Color.png

 That's the way I would need it: All loads have one color (for instance green) and all pallets have one color (for instance brown). The whole extrusion should have the color, I only colored the big visible surfaces.

0 Likes
Message 12 of 23

Frederick_Law
Mentor
Mentor

If they're same colour, just set colour in the part/assembly.

0 Likes
Message 13 of 23

e_jansonLT2PV
Explorer
Explorer

The pallet and the load are two different extrusions (not solids, because I need to mirror and remove the original)

Rack_Pattern.png

Rack_Pallet.png

If I color the pattern, pallet and load always have the same color, but they should be different.

  

0 Likes
Message 14 of 23

Frederick_Law
Mentor
Mentor

Try colour the feature before pattern.

Colour can apply to: face, body, feature.

You could extrude the box and "wood support" as new body.

This can be done in the model without code.

0 Likes
Message 15 of 23

e_jansonLT2PV
Explorer
Explorer

I can color the first instance of box and "wood support", but the rest of the occurences in the pattern will be "asBody". 

If I extrude the box and the "wood support" as a new body, I can't mirror and remove the original. This is important for me, as I need to display the rack of the other side of the aisle as well.

0 Likes
Message 16 of 23

Frederick_Law
Mentor
Mentor

If box and support are body, you can mirror rack and pattern box and support.

Maybe easier if you make them assembly.

Message 17 of 23

Curtis_Waguespack
Consultant
Consultant

.

 

 

 

EESignature

0 Likes
Message 18 of 23

Frederick_Law
Mentor
Mentor

Ok it is a bit tricky.  Need to pattern as solid, not feature.

Feature will make them same colour.

ColourArray-01.jpg

 

Message 19 of 23

Curtis_Waguespack
Consultant
Consultant

.

 

EESignature

0 Likes
Message 20 of 23

Curtis_Waguespack
Consultant
Consultant

@e_jansonLT2PV 

 

I seem to be one step behind @Frederick_Law  every time on this one 😀

 

But I think he is correct, in that if you set the color overide on the features to be patterned, then the pattern picks up the colors and you don't need ilogic for this

 

Here my original solids are colored as shown, and then the patterns are made so that they create new solids ( so I end up with  48) , and each new solid follows the original color of the feature.

 

Curtis_Waguespack_0-1716568190225.png

 

 

EESignature