Proper document update before sending data to Excel

Proper document update before sending data to Excel

adam_liska9KKD3
Participant Participant
471 Views
4 Replies
Message 1 of 5

Proper document update before sending data to Excel

adam_liska9KKD3
Participant
Participant

Hi guys. I have a simple rule for export and import data from Excel sheet. I need to update the document before data exchange occurs.

 

I run the rule through the Forms, but it works with an old data for the first try. I have to run it twice to get it updated properly. Am I missing something?

 

InventorVb.DocumentUpdate()

If P1_A>0 Then
	GoExcel.CellValue(P1__EXCEL + ".xlsx", "VYPOCET", "G31") = P1_A
	
End If

If P1_B>0 Then
	GoExcel.CellValue(P1__EXCEL + ".xlsx", "VYPOCET", "H31") = P1_B
	End If

P1__SsO = GoExcel.CellValue(P1__EXCEL + ".xlsx", "VYPOCET", "AA9")
P1__SsC = GoExcel.CellValue(P1__EXCEL + ".xlsx", "VYPOCET", "AA10")
GoExcel.Save

 

0 Likes
Accepted solutions (1)
472 Views
4 Replies
Replies (4)
Message 2 of 5

Andrii_Humeniuk
Advisor
Advisor

Hi @adam_liska9KKD3 . Try this code:

Dim oDoc As Document = ThisDoc.Document
oDoc.Rebuild()
oDoc.Update()

If P1_A>0 Then
	GoExcel.CellValue(P1__EXCEL + ".xlsx", "VYPOCET", "G31") = P1_A
	
End If

If P1_B>0 Then
	GoExcel.CellValue(P1__EXCEL + ".xlsx", "VYPOCET", "H31") = P1_B
	End If

P1__SsO = GoExcel.CellValue(P1__EXCEL + ".xlsx", "VYPOCET", "AA9")
P1__SsC = GoExcel.CellValue(P1__EXCEL + ".xlsx", "VYPOCET", "AA10")
GoExcel.Save

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 5

adam_liska9KKD3
Participant
Participant
No luck...
0 Likes
Message 4 of 5

adam_liska9KKD3
Participant
Participant
Accepted solution

@Andrii_Humeniuk  I´ve found a workaround. I split the rule into 2 rules:

1. document update "DocUpdate"

 

Dim oDoc As Document = ThisDoc.Document
oDoc.Rebuild()
oDoc.Update()

 

2. data exchange. "DataExchange"

If P1_A>0 Then
	GoExcel.CellValue(P1__EXCEL + ".xlsx", "VYPOCET", "G31") = P1_A
	
End If

If P1_B>0 Then
	GoExcel.CellValue(P1__EXCEL + ".xlsx", "VYPOCET", "H31") = P1_B
	End If

P1__SsO = GoExcel.CellValue(P1__EXCEL + ".xlsx", "VYPOCET", "AA9")
P1__SsC = GoExcel.CellValue(P1__EXCEL + ".xlsx", "VYPOCET", "AA10")
GoExcel.Save

 

And I combined them together in the third rule "Update":

iLogicVb.RunRule("DocUpdate")
iLogicVb.RunRule("DataExchange")

 

Message 5 of 5

A.Acheson
Mentor
Mentor

Hi @adam_liska9KKD3 

Try this using the Parameter function. 

Parameter.UpdateAfterChange = True
If P1_A>0 Then
	GoExcel.CellValue(P1__EXCEL + ".xlsx", "VYPOCET", "G31") = Parameter("P1_A")
	
End If

If P1_B>0 Then
	GoExcel.CellValue(P1__EXCEL + ".xlsx", "VYPOCET", "H31") = Parameter("P1_B")
	End If

Parameter("P1__SsO") = GoExcel.CellValue(P1__EXCEL + ".xlsx", "VYPOCET", "AA9")
Parameter("P1__SsC")= GoExcel.CellValue(P1__EXCEL + ".xlsx", "VYPOCET", "AA10")
GoExcel.Save

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes