iLogic exit rule on failed Assembly update

iLogic exit rule on failed Assembly update

daniel.puchta
Enthusiast Enthusiast
2,164 Views
10 Replies
Message 1 of 11

iLogic exit rule on failed Assembly update

daniel.puchta
Enthusiast
Enthusiast

Is there possibility to exit the ilogic rule when InventorVb.DocumentUpdate() fails?

I am working on large assembly file. There are points of base component, to which I am constraining Parts. Part has two points and I am constraining it to two points of base component. Then I move to another part and constrain it to another two points of base component.

I am able to do this via iLogic Rule using For Each Item In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef) where oAsmCompDef is ThisApplication.ActiveDocument.ComponentDefinition. In for cycle there are created constraints to one part.

After constraints are created inside this cycle I update assembly via InventorVb.DocumentUpdate(). However if there is error because of wrong point definition in base component, the rule continues and in next component there is error too. When errors are cumulating, it is painfully slow. Also if I update assembly not in rule but after the rule runs, it is also painfully slow. Is there possibility to exit the rule vhen InventorVb.DocumentUpdate() fails?

0 Likes
2,165 Views
10 Replies
Replies (10)
Message 2 of 11

JhoelForshav
Mentor
Mentor

Hi @daniel.puchta 

I'm thinking maybe check if the design doctor has any warnings or errors. (The red plus sign lights up), I'm guessing this is what you mean by "InventorVb.DocumentUpdate() fails". Because the rule doesn't crash, right?

 

Try this after the update:

'Update document
InventorVb.DocumentUpdate()
'Exit if any error or warning occurs.
If ThisApplication.ErrorManager.HasErrors Or ThisApplication.ErrorManager.HasWarnings Then Exit Sub

After some testing I see that it behaves as expected if you use ThisDoc.Document.Update, but not if you use InventorVB.DocumentUpdate() for some reason...

So like this insted maybe?

ThisDoc.Document.Update
'Exit if any error or warning occurs.
If ThisApplication.ErrorManager.HasErrors Or ThisApplication.ErrorManager.HasWarnings Then Exit Sub
0 Likes
Message 3 of 11

daniel.puchta
Enthusiast
Enthusiast

Right, the rule itself does not crash. I tried to add lines in your answer but Inventor just freezes and I have to kill it via task manager. 

The problem is that when I add constraint by rule that is in conflict with another constraint, I need the iLogic rule somehow determine that and immediately exit the rule.

The document update itself takes too long if there is problem with constraint (I think that it tries to resolve all the constraints and now I have more than 1500 of them).

So is there any method how to determine if newly added constraint is in conflict with another? Or just some quicker way than document update? Maybe to check just newly added component or constraint rather than updating the whole assembly?

0 Likes
Message 4 of 11

JhoelForshav
Mentor
Mentor

Hi @daniel.puchta 

You could try checking the healthstatus of the constraint:

Dim oConstraint As AssemblyConstraint = 'Your recently added constraint
If oConstraint.HealthStatus = HealthStatusEnum.kInconsistentHealth Then Exit Sub

Maybe it'll work, but maybe the healthstatus will be kOutOfDateHealth until you've updated the assembly. You'll just have to try to find out 🙂

Message 5 of 11

daniel.puchta
Enthusiast
Enthusiast

Thank you for your answer.

I tried it but to determine whether constraint is in InconsistentHealth status, I need to update document. And so this is not working for me because the update freezes Inventor and I have to kill it.

Without update the result was for both cases the same

0 Likes
Message 6 of 11

JhoelForshav
Mentor
Mentor

yeah... I suspected that would be the case...

Then I'm sorry to say that I don't think there's a solution for this. Inventor need to recalculate the relationships in order to know wehter or not the constraint is inconsistent with another constraint and I'm pretty sure that can only be achieved through update/rebuild.

I can't say I'm 100% sure though, because when adding a constraint, if it works, the component will jump in place as a preview before you hit apply. So Inventor must have some way of analyzing this before the constraint even exist. I don't think any functionality like that is exposed through the API though... Even if it did was, I'd guess the assembly would have to be up to date for it to work, so I don't think adding multiple constraints without updating the assembly before each one would work either way.

Message 7 of 11

daniel.puchta
Enthusiast
Enthusiast
JhoelForshav,

 thanks a lot. What I am doing right now is that after component is constrained I update the document. And if the update fails Inventor freezes so I am seeing where the problem is. Then I kill inventor via task manager, reopen assembly and repair the problematic place.

But it would be better to do this without having to kill Inventor. It would be great to chek constraint error before creating it, because the way I am doing it now, the assembly is always up to date before new constraint creation.

0 Likes
Message 8 of 11

JhoelForshav
Mentor
Mentor

Ok... As I said I'm fairly sure that there is no functionality exposed through the API to examine a constraint before it has been placed. I don't really know how this constraint preview you get while setting constriants manually works, but I'm thinking that probably this would be very slow in your case as well...

 

Maybe it wouldn't be as slow if you performed the update "silently" (don't update the view)

InventorVb.DocumentUpdate(False)

And then check the health status of the constraint? 🤔

Message 9 of 11

daniel.puchta
Enthusiast
Enthusiast

I found another quicker way. In base component in which I have defined points to which I am constraining, i run this rule:

Dim bod1 As WorkPoint
Dim bod2 As WorkPoint
Dim vzdalenost As Double
Dim maxpolozka = 0
For Each Item In ThisApplication.ActiveDocument.ComponentDefinition.WorkPoints
maxpolozka = maxpolozka + 1
Next
'MessageBox.Show(Cstr(maxpolozka),"index max bodu")
'MessageBox.Show(ThisApplication.ActiveDocument.ComponentDefinition.WorkPoints(maxpolozka), "index max bodu")

For i = 1738 To maxpolozka
bod1 = ThisApplication.ActiveDocument.ComponentDefinition.WorkPoints(i)
i = i+1
bod2 = ThisApplication.ActiveDocument.ComponentDefinition.WorkPoints(i)
'i = i + 1
'MessageBox.Show(bod1.Name,bod2.Name)
vzdalenost = Measure.MinimumDistance(bod1.Name, bod2.Name)

If vzdalenost > 283.1 Or vzdalenost < 283
MessageBox.Show(bod1.Name,CStr(vzdalenost))
Exit Sub
End If
Next

The distance between two neighboring points must be in some tolerance. So i firstly check this in part in which points are defined and after that I run rule for contraint creation in assembly. It is much more quicker than updating the assembly (even with silent operation)

Thank you a lot for your help 🙂

0 Likes
Message 10 of 11

daniel.puchta
Enthusiast
Enthusiast

Hi Jhoel,

I noticed that when inventor tries to show the preview, it freezes in large assembly. So even if this functionality would be usable by VBA or iLogic, it would not solved my problem.

The solution really is to check the distance before creating constrain. Anyway thanks a lot for your help.

Dan

0 Likes
Message 11 of 11

WCrihfield
Mentor
Mentor

Just a thought:  I wander if changing the following application options before starting, then setting them back at the end might help your performance out any with your large assembly:

- Application Options > Assembly tab > Defer update

- Application Options > Assembly tab > Enable relationship redundancy analysis

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)