Rule not working as an External Rule

Rule not working as an External Rule

donaldleigh
Advocate Advocate
1,173 Views
9 Replies
Message 1 of 10

Rule not working as an External Rule

donaldleigh
Advocate
Advocate

Hi all

I have 3 custom iProperties, Job No. & Line No.Sheet No.

If Sheet No. has 2 digits then Part Number iProperty will equal "Job No.-Line No.-Sheet No.

but if Sheet No. has 1 or 3 and more digits then Part Number iProperty will equal only the Sheet No.

 

Now. I have the below code that work only if the rule is in the part. if I add this to the external rules all I get is the small thinking windows circle and then I have to close Inventor.

 

The rule will be set to trigger with iProperty change.

 

Can someone please let me know what I'm missing 

 

Donald

Inventor 2014 (Soon to be 2019)

 

SyntaxEditor Code Snippet

EJN = iProperties.Value("Custom", "Job No.")
ELN = iProperties.Value("Custom", "Line No.")
ESN = iProperties.Value("Custom", "Sheet No.")

SNL = Len(ESN)

If SNL = 1 Then
    iProperties.Value("Project", "Part Number") = iProperties.Value("Custom", "Sheet No.")
Else If SNL = 2 Then
    iProperties.Value("Project", "Part Number") = EJN & "-" & ELN & "-" & ESN
Else If SNL > 2 Then
    iProperties.Value("Project", "Part Number") = iProperties.Value("Custom", "Sheet No.")
End If

iLogicVb.UpdateWhenDone = True

 

0 Likes
Accepted solutions (1)
1,174 Views
9 Replies
Replies (9)
Message 2 of 10

bshbsh
Collaborator
Collaborator

@donaldleigh wrote:

The rule will be set to trigger with iProperty change.

 


I'm guessing a rule that changes iproperties and triggered on iproperty change would cause an infinite loop, probably that's what you are seeing.

0 Likes
Message 3 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support

@donaldleigh,

 

Actually, posted iLogic code is tested in Inventor 2019 and it is working fine.

 

Hoping that below iLogic code might help in Inventor 2014. Guessing that, referenced document is missing while running as external rule.

 

Dim oDoc As Document 
oDoc = ThisDoc.Document 


EJN = oDoc.PropertySets.Item(4).Item("Job No.").Value 
ELN = oDoc.PropertySets.Item(4).Item("Line No.").Value 
ESN = oDoc.PropertySets.Item(4).Item("Sheet No.").Value  

SNL = Len(ESN)

If SNL = 1 Then
	oDoc.PropertySets.Item(3).Item("Part Number").Value = oDoc.PropertySets.Item(4).Item("Sheet No.").Value 
Else If SNL = 2 Then	
	oDoc.PropertySets.Item(3).Item("Part Number").Value = EJN & "-" & ELN & "-" & ESN    
Else If SNL >2 Then 
    oDoc.PropertySets.Item(3).Item("Part Number").Value = oDoc.PropertySets.Item(4).Item("Sheet No.").Value 
End If

iLogicVb.UpdateWhenDone = True

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 10

donaldleigh
Advocate
Advocate

hi @bshbsh

 

That makes sense. but why would it do that as an external rule but not when the rule is in the part?

 

is there a way to stop the loop runing?

0 Likes
Message 5 of 10

donaldleigh
Advocate
Advocate

that didn't work

if it works in 2019 as you say maybe ill wait on this till we upgrade. this should be soon I'm told

 

0 Likes
Message 6 of 10

donaldleigh
Advocate
Advocate

@chandra.shekar.g

 

I have the rule working now as an external rule but when I set the event trigger to run on iProperty change that's when I have the crash. As @bshbsh suggested it must be looping though and not stopping.

 

I have had a similar rule work this way.

0 Likes
Message 7 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support

@donaldleigh,

 

Nice to hear that iLogic rule is working.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 10

donaldleigh
Advocate
Advocate

The rule is working thanks but

 

If I set the event trigger to "iProperty Change" with the external rule inventor chases.

but with set to the same rule but as an internal rule it all works fine

 

Any idea why this happens

0 Likes
Message 9 of 10

bshbsh
Collaborator
Collaborator
Accepted solution

@donaldleigh wrote:

is there a way to stop the loop runing?


Generally, you have very bad control over a lot of things with ilogic. For example, there is no easy way (that i know of) to disable and re-enable event triggers programamtically when you need to. There might be tricks to circumvent some of these flaws, but I'm not really into ilogic anymore.

However, in this case, a little good practice may help. Basically, you want to craft what your new iproperty value would have to be as a variable first (and NOT directly into the iproperty itself!), then compare this with the actual value of that iproperty, and only change it when they are different. I assume this would prevent the iprop change event firing unnecessarily causing the loop. Also, it would not make your file dirty and requiring save unnecessarily.

So something like this:

EJN = iProperties.Value("Custom", "Job No.")
ELN = iProperties.Value("Custom", "Line No.")
ESN = iProperties.Value("Custom", "Sheet No.")

SNL = Len(ESN)
Dim NewPN as String
If SNL = 2 Then
    NewPN = EJN & "-" & ELN & "-" & ESN
Else
    NewPN = ESN
End If
If iProperties.Value("Project", "Part Number") <> NewPN then
    iProperties.Value("Project", "Part Number") = NewPN
    iLogicVb.UpdateWhenDone = True
End if
0 Likes
Message 10 of 10

donaldleigh
Advocate
Advocate

@bshbsh

 

your are a genius.

 

That worked. I will keep testing it but thanks. Owe you a drink.

 

Donald

0 Likes