Inventor General

Reply
Active Contributor
Posts: 28
Registered: ‎01-07-2010
Message 1 of 7 (333 Views)
Accepted Solution

ILogic Rule to look for iLogic Rules and iProperty expressions

333 Views, 6 Replies
04-30-2013 02:00 AM

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 2010 Pro SP4, Vault Collaboration 2010
HP Z820 Xeon E5-2643 0 @ 3.3Ghz 16.0GB RAM
Nvidia Quadro 5000
*Expert Elite*
mrattray
Posts: 2,241
Registered: ‎09-13-2011
Message 2 of 7 (320 Views)

Re: ILogic Rule to look for iLogic Rules and iProperty expressions

04-30-2013 04:20 AM 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

Active Contributor
Posts: 28
Registered: ‎01-07-2010
Message 3 of 7 (315 Views)

Re: ILogic Rule to look for iLogic Rules and iProperty expressions

04-30-2013 05:36 AM 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 2010 Pro SP4, Vault Collaboration 2010
HP Z820 Xeon E5-2643 0 @ 3.3Ghz 16.0GB RAM
Nvidia Quadro 5000
*Expert Elite*
mrattray
Posts: 2,241
Registered: ‎09-13-2011
Message 4 of 7 (308 Views)

Re: ILogic Rule to look for iLogic Rules and iProperty expressions

04-30-2013 05:48 AM 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

*Expert Elite*
mrattray
Posts: 2,241
Registered: ‎09-13-2011
Message 5 of 7 (295 Views)

Re: ILogic Rule to look for iLogic Rules and iProperty expressions

04-30-2013 10:40 AM 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

Active Contributor
Posts: 28
Registered: ‎01-07-2010
Message 6 of 7 (286 Views)

Re: ILogic Rule to look for iLogic Rules and iProperty expressions

05-01-2013 01:29 AM 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 2010 Pro SP4, Vault Collaboration 2010
HP Z820 Xeon E5-2643 0 @ 3.3Ghz 16.0GB RAM
Nvidia Quadro 5000
*Expert Elite*
mrattray
Posts: 2,241
Registered: ‎09-13-2011
Message 7 of 7 (280 Views)

Re: ILogic Rule to look for iLogic Rules and iProperty expressions

05-01-2013 04:19 AM 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you interested in helping shape the Autodesk Community?
We’re looking at a few different ways to improve the “All Forums” landing page and need your feedback! If interested, please take a few minutes to fill out the following Usability Study. Thank you for your time!

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube