how to use StartTransactionForDocumentOpen()?

how to use StartTransactionForDocumentOpen()?

robbeRtek
Advocate Advocate
444 Views
5 Replies
Message 1 of 6

how to use StartTransactionForDocumentOpen()?

robbeRtek
Advocate
Advocate

hi,

 

Can someone tell me how to use this ?

TransactionManager.StartTransactionForDocumentOpen( DisplayName As String ) As Transaction
https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=GUID-54D83CD1-1AF4-4817-B156-14E8718FF0D3

the discription is not clear, and try it, give strange results.
Case 1 the .StartTransactionForDocumentOpen : this is to add a new transaction for the document that is open/active.
Case 2the .StartTransactionForDocumentOpen : this is to create a transaction, where you want to add or open a new document.

testresults :
1, open inventor, add an new part doc, create and run  vba rule :

 

Public Sub trans()
MsgBox (ThisApplication.TransactionManager.CurrentTransaction.DisplayName & "-" & ThisApplication.TransactionManager.CurrentTransaction.Id)
End Sub

 

robbeRtek_0-1703166195238.png

CurrentTransaction, is never nothing, there is always an transaction called "Unidentified transaction"

But, you cann't end this :

robbeRtek_1-1703166559208.png

now we change the vba code to :

 

Public Sub trans()
MsgBox (ThisApplication.TransactionManager.CurrentTransaction.DisplayName & "-" & ThisApplication.TransactionManager.CurrentTransaction.Id)
Dim customtrans As Transaction
Set customtrans = ThisApplication.TransactionManager.StartTransactionForDocumentOpen("xxx")
MsgBox (ThisApplication.TransactionManager.CurrentTransaction.DisplayName & "-" & ThisApplication.TransactionManager.CurrentTransaction.Id)
customtrans.End
End Sub

 

robbeRtek_2-1703167010692.png

robbeRtek_3-1703167082627.png

 

The code runs to the end with no err; but you can see the code start an new transaction, but not use the string for displayname.
there is no action add on the undo button,...
so i gues this is not the way to use it, but there is no error and an new transaction that you can 'end'

-you can not be sure that you can use 'end' methode for 'current transaction', because they not use the string to give the new transaction an name. the name stays : 'Unidentified transaction'

test result case 2

 change code to :

 

Public Sub trans()
MsgBox (ThisApplication.TransactionManager.CurrentTransaction.DisplayName & "-" & ThisApplication.TransactionManager.CurrentTransaction.Id)
Dim oDrawDoc As DrawingDocument
Dim customtrans As Transaction
Set customtrans = ThisApplication.TransactionManager.StartTransactionForDocumentOpen("xxx")
MsgBox (ThisApplication.TransactionManager.CurrentTransaction.DisplayName & "-" & ThisApplication.TransactionManager.CurrentTransaction.Id)
Set oDrawDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, ThisApplication.FileOptions.TemplatesPath & "Metric\ISO.idw", True)
customtrans.End
End Sub

 


and run,
you can see there is an new transaction id, and the transaction 'end- methode' can be finished

but :
where is the name/discription from the transaction in the undo?

robbeRtek_4-1703169610295.png

you cann't find it.
so i gues i can not use 'StartTransactionForDocumentOpen-methode' for add the transaction to the undo list

the only way : 'StartTransaction'

Thanks to add some feedback.

 

 

0 Likes
445 Views
5 Replies
Replies (5)
Message 2 of 6

robbeRtek
Advocate
Advocate

Can some 'autodesk elite' add some feedback?
Thanks

@johnsonshiue 
@JelteDeJong 
or other members...

0 Likes
Message 3 of 6

robbeRtek
Advocate
Advocate

Still waiting on feedback.

0 Likes
Message 4 of 6

JelteDeJong
Mentor
Mentor

It's not clear what you are trying to do. But Some time ago I wrote a blog post about transactions.  Maybe it helps you:

http://www.hjalte.nl/65-undo

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 5 of 6

robbeRtek
Advocate
Advocate

Thank you for responding.

I am searching for a snippet that correctly utilizes the following:

 

TransactionManager.StartTransactionForDocumentOpenDisplayName As String ) As Transaction


In all the snippets I've come across (about transactions), they commonly utilize

 

TransactionManager.StartTransaction()

 

or

 

TransactionManager.StartGlobalTransaction()

 

 

Regards.

0 Likes
Message 6 of 6

Sonja_Schweitzer
Explorer
Explorer
Confronted with same issue right now and read your blogpost already. It is not anwering this question, so maybe a example why I would like to use this:
1. Start Inventor from external programm (no makro or iLogic)
2. At this point there is no document open and lets say our workspace folder is empty.
3. For the StartTransaction, you are using and which is documented as sample, is a Document needed to be previously open, but since I would like to use the transaction for wrapping this maybe not existing file on the first or second path, that would not be possible without needing the user to open a file himself. StartTransactionForDocumentOpen in my understandment would mean, provide the name for the Transaction, open a Document, close it, end the transaction, but you're save if its not existing and can close this document (openVisible = False, so the PDM system do not get it into the actual workspace if not saving it) so in case you would not have a activeDocument or one you know existing, Blank Inventor Application, but you want to do a open transaction with visible = false, how would you do this?
0 Likes