Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic Rule in Content Center Error

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
jtylerbc
1053 Views, 9 Replies

iLogic Rule in Content Center Error

We've been running into issues recently with the lengths of Content Center steel shapes not coming out correctly on drawings, since the G_L parameter doesn't update to account for all model changes.

 

To resolve this, I have written an iLogic rule that uses Measure.ExtentsHeight to measure the part in the Z direction, thus determining the final length regardless of how it came to be. It then writes that value to a user parameter (LENGTH_DESC), which is then exported and referenced in my part description.

 

The problem comes when I actually put this rule into Content Center (by replacing the Family Template).  The part publishes fine.  However, when subsequently placing a part from the family, if there are Event Triggers set for the rule, I get the following error.

 

 

iLogic Event-Driven Rule

Object reference not set to an instance of an object.

 

Following that error on initial placement, the rule functions properly.  However, you have to click through that error every time you place a steel shape.  I've poked at the problem with "On Error" and "Try/Catch" a bit, but haven't had any success.  Thus far, the only way I've found to get rid of it is by removing the triggers, which defeats the purpose of having the rule.

 

Any ideas?  Code is below.

 

' This rule uses the Measured Extents in the Z direction to develop a parameter which will be used in the material list description.

On Error Resume Next

oDoc = ThisDoc.Document

' Verify that the document is fully updated prior to taking measurements.
InventorVb.DocumentUpdate()

' Work features will be included in the extents if they are visible, which interferes with accurate measurement.
' Object visibility of work features and surfaces will be set to invisible before the measurements are taken, then returned to their previous state.


'toggle construction surface visibility off
oDoc.ObjectVisibility.AllWorkFeatures = False
oDoc.ObjectVisibility.ConstructionSurfaces = False
oDoc.ObjectVisibility.Sketches = False
oDoc.ObjectVisibility.Sketches3D = False


' Determine the extents of the part in Z direction
' Assign the measured value to the LENGTH_DESC user parameter
LENGTH_DESC = Measure.ExtentsHeight


'toggle construction surface visibility on
oDoc.ObjectVisibility.AllWorkFeatures = True
oDoc.ObjectVisibility.ConstructionSurfaces = True
oDoc.ObjectVisibility.Sketches = True
oDoc.ObjectVisibility.Sketches3D = True

' Update so changes are visible to the user
iLogicVb.UpdateWhenDone = True

 

9 REPLIES 9
Message 2 of 10
xiaodong_liang
in reply to: jtylerbc

Hi,

 

Could you elaborate how you set the trigger? It will be helpful to share a demo part. Thanks.

Message 3 of 10
jtylerbc
in reply to: jtylerbc

Originally, the trigger was set to "Any Model Parameter Change" and "Before Save Document."  This caused me to get the error messge multiple times for a single part insertion.  I found that if I turned off the "Parameter Change" trigger, that got it down to only showing the error message once.  This is the version of the triggers included in the attached file.

 

I don't think I made this totally clear in the original post, but the rule itself works.  The error only occurs when placing the part from Content Center - once you get past that, it gives correct results. 

Message 4 of 10
adam.nagy
in reply to: jtylerbc

Hi,

 

You could add some logging inside the rule to see which line causes that error.

e.g. writing to a file, or collecting info into a string and displaying a dialog with it at the end, etc

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 5 of 10
jtylerbc
in reply to: adam.nagy

Adam,

 

As a quick test (and because I wasn't sure how to go about the "logging to a file" method you proposed), I inserted message boxes after each action in the rule.  I then re-inserted the the family template into CC, and placed a part from the family.

 

The results were strange.  I was expecting the error to pop up between two of the message boxes, so I could narrow down the section of code triggering it.  Instead, the error did not appear until after the last message box, which is the very last line in the test code.

 

Is this an invalid way of testing for some reason, or is there something really strange going on here?  It seems very strange to me that the rule would actually process everything correctly, then suddenly error at the very end.  This error persists if I stack additional message boxes at the end of the code - it always seems to be after the very last line of code.

Message 6 of 10
jtylerbc
in reply to: jtylerbc

Did some more experimentation - this error doesn't happen on all rules, so there apparantly is something amiss with the code.  However, I have yet to find it.

 

I have found a possible alternate solution, but I don't really like it.  I found that I can have the Measured Length rule with all of its desired triggers, then suppress it. I then have a second rule with a "New Document" trigger, which unsuppresses the Measured Length rule.  This will actually work, but it seems silly to need a second rule to enable the first one.

 

Any ideas on what could be triggering the error, or more suggestions on how I could troubleshoot it?

Message 7 of 10
MjDeck
in reply to: jtylerbc

Please try replacing this line:

LENGTH_DESC = Measure.ExtentsHeight

with:

Parameter("LENGTH_DESC") = Measure.ExtentsHeight

Another thing to try would be to take out the line:
iLogicVb.UpdateWhenDone = True


Mike Deck
Software Developer
Autodesk, Inc.

Message 8 of 10
jtylerbc
in reply to: MjDeck

Changing the parameter line did nothing - the UpdateWhenDone seems to have been the culprit.

 

This solves the original problem.  However, now after the rule runs on save, the Update button is lit until you click it.  This is a minor annoyance and we might be able to just live with that.  However, it is a little goofy to save the file, click update, then save it again.

 

Is the UpdateWhenDone somehow incompatible with Content Center?  I'm curious why this happens in the first place, when the original rule functioned perfectly after the initial placement.

Message 9 of 10
MjDeck
in reply to: jtylerbc

It seems like UpdateWhenDone might be incompatible with Content Center.
Try replacing it with these lines, which will update the part immediately:

RuleParametersOutput()
InventorVb.DocumentUpdate()


Mike Deck
Software Developer
Autodesk, Inc.

Message 10 of 10
jtylerbc
in reply to: MjDeck

Thanks, that seems to have done it.  I had the "InventorVb.DocumentUpdate()" line in there to replace the "UpdateWhenDone", but didn't know about the RuleParametersOutput().

 

Seems to work perfectly now, no error message, no excessive updates, and no goofy two-rule system.

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

Post to forums  

Autodesk Design & Make Report