Global update model in Ilogic before going on with rest of script

Global update model in Ilogic before going on with rest of script

peterd123
Participant Participant
2,273 Views
6 Replies
Message 1 of 7

Global update model in Ilogic before going on with rest of script

peterd123
Participant
Participant

I am having trouble getting this to work. 

I have VBA running in Excel that cycles through many iterations of an assembly changing the parameters in each cycle.

Simplified, on the excel side it changes the parameters, saves the file and then waits for 30 sec before repeating.

 

Inventor is detecting the change via a trigger (set in excel with a NOW()).  Then it should update model, and then save as dwg and obj (with name brought in from excel).

 

PROBLEM:

What I am realizing is that it is not saving them with the current model, but rather the model of the previous iteration.

 

Below is the ilogic script, with ' comments of things I have tried to no avail.  Any suggestions on how to force update before proceeding with rest of script?

trigger = ExcelTrigger

brand = GoExcel.CellValue("dimensions.xlsm", "Sheet2", "B7")
family = GoExcel.CellValue("dimensions.xlsm", "Sheet2", "B8")
full_name = GoExcel.CellValue("dimensions.xlsm", "Sheet2", "B9")
part_num = GoExcel.CellValue("dimensions.xlsm", "Sheet2", "B10")
file_name = GoExcel.CellValue("dimensions.xlsm", "INPUT", "B2")
file_directory = GoExcel.CellValue("dimensions.xlsm", "INPUT", "G2")

'RuleParametersOutput()
'InventorVb.DocumentUpdate()

Call ThisApplication.CommandManager.ControlDefinitions.Item("AppLocalUpdateCmd").Execute
Call ThisApplication.CommandManager.ControlDefinitions.Item("AppGlobalUpdateWrapperCmd").Execute
System.Threading.Thread.CurrentThread.Sleep(15000)

'iLogicVb.UpdateWhenDone = True
'iLogicVb.UpdateWhenDone = True
'ThisApplication.DocumentUpdate = True
'iLogicVb.UpdateWhenDone = True
'Parameter.UpdateAfterChange = True
'ThisApplication.ActiveDocument.Update2
'Application.Wait (Now + TimeValue("0:00:12"))
' didnt work ThisApplication.ActiveView.Update()
' didnt work ThisApplication.ActiveDocument.Rebuild
' didnt work ThisApplication.ActiveDocument.Update() 
'Save .igs in new file path
ThisDoc.Document.SaveAs(ThisDoc.Path + file_directory + file_name + ".obj", True) 
ThisDoc.Document.SaveAs(ThisDoc.Path + file_directory + file_name + ".dwg", True) 
 
GoExcel.DisplayAlerts = False

GoExcel.Close
 
'iLogicVb.UpdateWhenDone = True

 

0 Likes
Accepted solutions (1)
2,274 Views
6 Replies
Replies (6)
Message 2 of 7

gcoombridge
Advisor
Advisor

How about a rebuild-all prior to the save? This may slow things down but might force an update..

 

ThisDoc.Document.Rebuild()

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399
0 Likes
Message 3 of 7

bradeneuropeArthur
Mentor
Mentor
Dim a As Inventor.Application = ThisApplication

Dim b As Inventor.Document = a.ActiveDocument

b.Rebuild2(True)
If b.RequiresUpdate = True Then
	
b.Update2(True)
b.Save2(True)

End If

 

With this it should work!

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 4 of 7

peterd123
Participant
Participant

I tried this out.  I notice that the output files are being created about 5 sec before the model updates.

0 Likes
Message 5 of 7

greggeorgi
Contributor
Contributor
Accepted solution

Your thread.sleep might not be helping anything. Worst case, it is actually pausing the command manager execution.

You can try using Execute2 and/or DoEvents.

 

Execute2(True) might be the same as regular Execute, not sure, I only use Execute2. (Executes synchronously if true, asynchronously if false)

 

DoEvents will essentially pause the iLogic thread, process inventor stuff, then return. Some might say its not good practice to use it, but the way Inventor is programmed, it is basically required in certain cases. This may be your best bet after running the commands. (maybe a DoEvents after each execute)

 

Call ThisApplication.CommandManager.ControlDefinitions.Item("CMD").Execute2(True)
Call ThisApplication.UserInterfaceManager.DoEvents

 

If there is some sort of flag that can be set, you can also use DoEvents to wait for the process to definitely finish

 

dim flag as boolean = false

While not flag

    'check if flag should be set to true, or use an event?

    Call ThisApplication.UserInterfaceManager.DoEvents

End While

0 Likes
Message 6 of 7

peterd123
Participant
Participant

Adding this after the model update and before the saves seems to have done the trick:

Call ThisApplication.UserInterfaceManager.DoEvents

 

Thanks!

0 Likes
Message 7 of 7

maxim.teleguz
Advocate
Advocate



ThisApplication.ScreenUpdating = True
iLogicVb.Automation.RulesOnEventsEnabled = True
ThisApplication.SilentOperation = False
UpdateRevBlockOnSyncProp = 1
'https://knowledge.autodesk.com/support/vault-products/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/Vault/files/GUID-DFE2BDB7-4A6D-49D7-9083-18DCB20B7505-htm.html

'activecmd = ThisApplication.CommandManager
'If activecmd.ActiveCommand = activecmd.ActiveCommand Then
'MsgBox(activecmd.ActiveCommand)
'End If
SendKeys.SendWait("{ESC}")
AppActivate(ThisApplication.Caption)

On Error Resume Next
Dim selectCmd As ControlDefinition
    selectCmd = ThisApplication.CommandManager.ControlDefinitions.Item("AppContextual_CancelCmd")
    selectCmd.Execute

ThisApplication.CommandManager.ControlDefinitions.Item("VaultRevisionBlockTableNode").Execute2(False)

a = iProperties.Value("Project", "Revision Number")
iProperties.Value("Custom", "REV") = a

InventorVb.DocumentUpdate()

here is code updating the revision block. This works really well in canceling out any commands that are running first.  

0 Likes