Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ILogic Rule to look for iLogic Rules and iProperty expressions

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
-ianf-
1392 Views, 6 Replies

ILogic Rule to look for iLogic Rules and iProperty expressions

Hi all,

 

Our models currently have a mix of 3 distictive parts;

some parts have ilogic rules in them that write parameters back to the iProperties (length, width, etc)

some parts have expressions within the iProperties that autofill from the parameters.

some parts are a bit dumb and have manually typed iProperties.

 

I am looking for a new rule at assembly level that will look at all the parts in that assembly and return a list of parts that have no rules or expressions within them. Is this even possible? It would be a massive time saving tool if it was.

 

Many thanks in anticipation!

 

 

Ian Farmery
Inventor & Vault 2023

Dell 7550 Xeon E-2276M, 2.80Ghz 64GB RAM
Nvidia Quadro RTX 4000
6 REPLIES 6
Message 2 of 7
mrattray
in reply to: -ianf-

This should be doable. I'll write up some code later if I get the time. This is what I plan to do:
I'm thinking we'll loop through all of the components to gather up all of the parts in an assembly. Am I right in assuming that we don't need sub assemblies themselves, but that we do need to drill into them to find their parts? We'll then check for the presence of iLogic rules. Can I assume that we're looking for a specific rule by name? What is that name? We can then check through the parts that didn't have the rule we're looking for for the presence of certain properties. What are the names of the properties we're interested in? We'll then check the value of the expression property (of the property) and see if the left most character is an "=" sign. Then we'll know that this property is an expression and not a dumb property. From there it should be pretty trivial to present a list of parts in a message box that are either missing the properties in question or are filled in with dumb values.
Mike (not Matt) Rattray

Message 3 of 7
-ianf-
in reply to: mrattray

Superb Mike,

 

No need to interrogate the sub assemblies themselves but the parts beneath will need looking at. The rule name in question is "Iprops" other rules may exist in the parts but it is the "Iprops" rule that extracts info and populates the iProperties.

As for the iProperties, we populate the "Subject" field with our part dimensions. These expressions read the custom fields as normal.

 

I can see your plan with searching for the left most character being "="  nice, simple and effective. 

 

Many thanks Mike.

 

 

Ian Farmery
Inventor & Vault 2023

Dell 7550 Xeon E-2276M, 2.80Ghz 64GB RAM
Nvidia Quadro RTX 4000
Message 4 of 7
mrattray
in reply to: -ianf-

While I'm busy here with "real work", you may want to look around for a tool called "Code Injector" developed by another forum contributor, MegaJerk. This may cover your needs.
Mike (not Matt) Rattray

Message 5 of 7
mrattray
in reply to: -ianf-

This proved to be more challenging than I expected, but try this:

 

Option Explicit

Sub Main()

Dim oComp, oSubComp As ComponentOccurrence
Dim oComps, oSubComps As ComponentOccurrences
Dim oCompDoc, oSubCompDoc As Document
Dim msg As Long
Dim oProp As String
Dim oPropSet As PropertySet

oComps = ThisDoc.Document.ComponentDefinition.Occurrences

For Each oComp In oComps
	If oComp.Suppressed = False Then
		If oComp.ReferencedDocumentDescriptor.ReferencedDocumentType = kAssemblyDocumentObject Then
			oSubComps = oComp.Definition.Occurrences
			For Each oSubComp In oSubComps
				If oSubComp.Suppressed = False Then
					If oSubComp.ReferencedDocumentDescriptor.ReferencedDocumentType = kAssemblyDocumentObject Then
						msg = MsgBox("This rule does not look at sub assemblies of sub assemblies. They will need to be checked seperately. Proceed?",vbOKCancel,"Property checker")
						If msg = vbCancel Then Exit Sub
					Else
						If checkRules(oSubComp) = False Then
							oSubCompDoc = oSubComp.Definition.Document
							oPropSet = oSubCompDoc.PropertySets.Item("Summary Information")
							oProp = oPropSet.Item("Subject").Expression
							If Left(oProp,1) <> "=" Then
								MsgBox("This component needs to be updated: " & oSubComp.Name, vbOKOnly, "Property checker")
							End If
						End If
					End If
				End If
			Next
		Else
			If checkRules(oComp) = False Then
				oCompDoc = oComp.Definition.Document
				oPropSet = oCompDoc.PropertySets.Item("Summary Information")
				oProp = oPropSet.Item("Subject").Expression
				If Left(oProp,1) <> "=" Then
					MsgBox("This component needs to be updated: " & oComp.Name, vbOKOnly, "Property checker")
				End If
			End If
		End If
	End If
Next

End Sub

Function checkRules(oComp As ComponentOccurrence) As Boolean
'returns true if the rule in question is found
Dim oAutomation As Object
Dim oRule As Object
Dim oRules As Object

oAutomation = iLogicVb.Automation
oRules = oAutomation.Rules(oComp.Definition.Document)

If oRules Is Nothing Then Exit Function

For Each oRule In oRules
	If oRule.Name = "Iprops" Then Return True
Next

End Function

 

 This wont work for subs of subs. You'll have to run this on any "sub-subs" directly.

Mike (not Matt) Rattray

Tags (1)
Message 6 of 7
-ianf-
in reply to: mrattray

First of all, Thank you. Your time and effort is very much appreciated. 

 

Code works well. Looking through what you have done I can grasp most of it. One part I am struggling to understand are the lines where you are asking to search the subject field for "=" 

 

Forgive my limited understanding of iLogic but If I were wanting to change the search location in the iProps from "Summary", "Subject" to "Project", "Description" how do I do this?  I can't work out how or why you defined "Summary Information".  This is the Summary tab on the iprops right?

 

 

 

If checkRules(oSubComp) = False Then
							oSubCompDoc = oSubComp.Definition.Document
							oPropSet = oSubCompDoc.PropertySets.Item("Summary Information")
							oProp = oPropSet.Item("Subject").Expression
							If Left(oProp,1) <> "=" Then
								MsgBox("This component needs to be updated: " & oSubComp.Name, vbOKOnly, "Property checker")
							End
Ian Farmery
Inventor & Vault 2023

Dell 7550 Xeon E-2276M, 2.80Ghz 64GB RAM
Nvidia Quadro RTX 4000
Message 7 of 7
mrattray
in reply to: -ianf-

"Summary Information" refers to the property set which contains the "Subject" field. Unfortunately, prop sets don't equate directly to the tabs on your property browser. These prop sets are super-secret double classified. For example, if you wanted to change to the "Description" property, you would have to reference the "Design Tracking Properties" prop set.

 

The only way I know of to figure out the property system is using this macro (it runs in the API, not iLogic):

(Make sure you open the immediate window to view the results [press ctrl+g].)

 

Private Sub ReadCustomProps()
Dim oPropSet As PropertySet
Dim oProp As Property
Dim count As Integer
count = 0

On Error Resume Next
For Each oPropSet In ThisApplication.ActiveDocument.PropertySets
Debug.Print oPropSet.DisplayName & "  Count: " & oPropSet.count
For Each oProp In oPropSet
count = count + 1
Debug.Print count & "  '" & oProp.Name & "' = '" & oProp.value & "'"
Next
Next
Exit Sub
Debug.Print Error
End Sub

 

 

Mike (not Matt) Rattray

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

Post to forums  

Autodesk Design & Make Report