Referenced Files refresh

Referenced Files refresh

brianA32ZM
Advocate Advocate
291 Views
3 Replies
Message 1 of 4

Referenced Files refresh

brianA32ZM
Advocate
Advocate

Is it possible to refresh the Referenced Files of an assembly after using Component.Add before exiting the rule?

I noticed that when I add a component and later in the same rule then try to find the same Component in Referenced Files it is not found.

0 Likes
292 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @brianA32ZM.  Maybe try including a line of code meant to update the document somewhere after your lines of code that add components, but before the later lines of code that try to find the added referenced files.  One of the popular iLogic snippets is the following:

InventorVb.DocumentUpdate()

...but there are other ways too, such as, if you already have a variable for the document you are targeting (the main assembly), you could use that like this:

oAsmDoc.Update

or

oAsmDoc.Update2(True)

...where oAsmDoc is the Document or AssemblyDocument type variable you are using to refer to the main assembly.

And if that does not work, maybe try the oAsmDoc.Rebuild or oAsmDoc.Rebuild2(True).  The rebuild command forces updates, even if they may not be needed.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

brianA32ZM
Advocate
Advocate

Thank you @WCrihfield. I tried each of your suggestions and I still have the same problem.   The only exception was in using oAsmDoc.Update, this resulted in the following error message:

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.AssemblyDocument.Rebuild()
at ThisRule.AddComponent() in external rule: Program Sub - Add Components - Find Adder:line 298
at ThisRule.Main() in external rule: Program Sub - Add Components - Find Adder:line 109
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

OK.  That error indicates that it encountered the first error at a line of code for rebuilding the assembly document.  Not sure why.  Then it indicates that it may have encountered a second error where it is trying to add another component.  This is just a guess, but this sounds a little bit like a timing related issue.  For instance, it may still be processing what the rebuild command told it to do when the code tries to add another component.  But pausing iLogic rules to wait for processes to finish is not something that the folks at Autodesk provide an iLogic snippet for, and it can be complicated to do correctly.  I have seen a few different ways of attempting to do it, but they are generally not 'smart' (they do not actually know when the processing is done), they usually just wait a specified amount of time.  One of the simplest ways to pause a rule is to launch a MsgBox, or MessageBox.Show.  Those pause the rule while they are showing, but things that are processing in the background will continue.  Then when you close the message dialog, the rule continues.  But showing a dialog is not always desirable for automation routines.  One of the other most popular tools is the following:

System.Threading.Thread.Sleep(1000) '1000 milliseconds = 1 second

However, I think that may also pause some of Inventor's background processing also, so it is not always ideal for every situation.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes