ilogic Rule in part runs from assembly.

ilogic Rule in part runs from assembly.

m_rubach
Explorer Explorer
138 Views
2 Replies
Message 1 of 3

ilogic Rule in part runs from assembly.

m_rubach
Explorer
Explorer

Hi, at the begining I would like to say that I am beginer in iLogic.

I have written ilogic rules which changes color surfaces depends which value is in custom properties.

i added attribute name for surface which i want to change.

The trigger of rule is set after any change iProperties in part.

 

When I am in the part, the rule works well, but when I change the custom property from the assembly level, which triggers rules in the part, that rule doesn't work.

 

I suppose that issues with

ThisApplication.ActiveEditDocument

I get an error (unfortunately not english language):

m_rubach_1-1755495807061.png

 

 

 

m_rubach_0-1755495262356.png

 

 

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveEditDocument
Dim oCompDef As ComponentDefinition
oCompDef = oPartDoc.ComponentDefinition



Dim oFaces As Faces
Dim oFace As Face
Dim oSurfBodies As SurfaceBodies
Dim oSurfBody As SurfaceBody
Dim oStyle As RenderStyle
	oStyle = oPartDoc.RenderStyles.Item("Green") 
	 oSurfBodies = oCompDef.SurfaceBodies

oFaces = oSurfBodies.Item(1).Faces
For Each oSurfBody In oSurfBodies
oFaces = oSurfBody.Faces
	For Each oFace In oFaces
		For i = 1 To 2
			Try			
			If oFace.AttributeSets.Item(i).Item(1).Value = "Long1" Then
				If iProperties.Value("Custom", "Long1") = "1" Or iProperties.Value("Custom", "Long1") = "2" Then
				Call oFace.SetRenderStyle(kOverrideRenderStyle, oStyle)
				Else
				Call oFace.SetRenderStyle(kPartRenderStyle)
				End If 
			End If
			
			If oFace.AttributeSets.Item(i).Item(1).Value = "Long2" Then
				If iProperties.Value("Custom", "Long2") = "1" Or iProperties.Value("Custom", "Long2") = "2" Then
				Call oFace.SetRenderStyle(kOverrideRenderStyle, oStyle)
				Else
				Call oFace.SetRenderStyle(kPartRenderStyle)
				End If 
			End If
			
			If oFace.AttributeSets.Item(i).Item(1).Value = "Short1" Then
				If iProperties.Value("Custom", "Short1") = "1" Or iProperties.Value("Custom", "Short1") = "2" Then
				Call oFace.SetRenderStyle(kOverrideRenderStyle, oStyle)
				Else
				Call oFace.SetRenderStyle(kPartRenderStyle)
				End If 
			End If
			
			If oFace.AttributeSets.Item(i).Item(1).Value = "Skort2" Then
				If iProperties.Value("Custom", "Short2") = "1" Or iProperties.Value("Custom", "Short2") = "2" Then
				Call oFace.SetRenderStyle(kOverrideRenderStyle, oStyle)
				Else
				Call oFace.SetRenderStyle(kPartRenderStyle)
				End If 
			End If
			Catch	
			End Try
		Next		
	Next
Next

 

0 Likes
Accepted solutions (1)
139 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @m_rubach.  Any time an iLogic rule may get triggered to run while the Document it is intended to be working on may not be the 'active' document, that rule should not be trying to get the 'active' document.  I think in this case, you could just replace:

oPartDoc = ThisApplication.ActiveEditDocument

...with this:

oPartDoc = ThisDoc.Document

...to fix that initial error/problem.  However, I also see other issues in that code.  Namely the use of very outdated object types and methods (RenderStyles).  See the following online help page on this topic:

Consistent Materials (Materials and Appearances) 

Try using the following properties & methods instead:

PartDocument.ActiveAppearance 

PartDocument.ActiveMaterial 

PartDocument.AppearanceAssets 

PartDocument.Assets 

PartDocument.MaterialAssets 

Application.ActiveAppearanceLibrary 

Application.ActiveMaterialLibrary 

Application.AssetLibraries 

AssetLibraries 

AssetLibrary 

Asset 

MaterialAsset 

Face.Appearance 

Face.AppearanceSourceType 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

m_rubach
Explorer
Explorer

@WCrihfield Thanks! Works well.

 

As you suggested, I change method to change appearance.

 

Dim oPartDoc As PartDocument
oPartDoc = ThisDoc.Document
Dim oCompDef As ComponentDefinition
oCompDef = oPartDoc.ComponentDefinition

Dim oFaces As Faces
Dim oFace As Face
Dim oSurfBodies As SurfaceBodies = oCompDef.SurfaceBodies
Dim oSurfBody As SurfaceBody	

Dim localAsset As Asset = oPartDoc.Assets.Item("Green")
Dim localAssetDefault As Asset = oPartDoc.Assets.Item("White")
 

For Each oSurfBody In oSurfBodies
	oFaces = oSurfBody.Faces
	For Each oFace In oFaces
		For i = 1 To 2
			Try			
			If oFace.AttributeSets.Item(i).Item(1).Value = "Long1" Then
				If iProperties.Value("Custom", "Long1") = "1" Or iProperties.Value("Custom", "Long1") = "2" Then
				oFace.Appearance = localAsset
				Else
				oFace.Appearance = localAssetDefault
				End If 
			End If
			
			If oFace.AttributeSets.Item(i).Item(1).Value = "Long2" Then
				If iProperties.Value("Custom", "Long2") = "1" Or iProperties.Value("Custom", "Long2") = "2" Then
				oFace.Appearance = localAsset
				Else
				oFace.Appearance = localAssetDefault
				End If 
			End If
			
			If oFace.AttributeSets.Item(i).Item(1).Value = "Short1" Then
				If iProperties.Value("Custom", "Short1") = "1" Or iProperties.Value("Custom", "Short1") = "2" Then
				oFace.Appearance = localAsset
				Else
				oFace.Appearance = localAssetDefault
				End If 
			End If
			
			If oFace.AttributeSets.Item(i).Item(1).Value = "Short2" Then
				If iProperties.Value("Custom", "Short2") = "1" Or iProperties.Value("Custom", "Short2") = "2" Then
				oFace.Appearance = localAsset
				Else
				oFace.Appearance = localAssetDefault
				End If
			End If
			Catch	
			End Try
		Next		
	Next
Next

 

0 Likes