Updating a Python script; method defs seem to have chabged

David Friedman's Avatar

David Friedman

Mar 01, 2016 @ 03:43 AM

I am attaching a script I wrote to export selected transactions to a .csv file for generating a spreadsheet. The code loops through all accounts and takes each in turn. When attempting to run this script with Moneydance version 2015.6 build 1299, I got an error message that the method getHighestAccountNum() no longer exists. The existing code sequence is as follows:
 . . .
ra = moneydance.getRootAccount()
 . . .
accts = []
for i in range(0, ra.getHighestAccountNum()):
   acct = ra.getAccountById(i+1) # loop thru acct nums
   if acct == None: # not all are valid
      continue
          . . .
   accts.append(i+1) # build list of acct id's
for id in accts:
   acct = ra.getAccountById(id)
   acct_name = acct.getAccountName()
     . . .

I have looked through the current API and it appears that the "account number" is no longer valid. What is the current recommended approach to get a list of all accounts and loop through them? Thanks in advance for any useful help.

David Friedman
[email blocked]

  1. Support Staff 1 Posted by Sean Reilly on Mar 01, 2016 @ 09:28 PM

    Sean Reilly's Avatar

    Hi David,

    Yes, we've cleaned up quite a bit for Moneydance 2015, but to be honest, using getHighestAccountNum() isn't the most efficient way of doing it. I'll chalk this up to our documentation being bad :)

    The best way in Moneydance 2015 is using something like this:

    from com.infinitekind.moneydance.model import *
    
    book = moneydance.getCurrentAccountBook()
    for acct in AccountUtil.getAccountIterator(book):
        print acct.getFullAccountName()
    

    Thanks!

    Sean Reilly
    Developer, The Infinite Kind
    http://infinitekind.com

  2. Sean Reilly closed this discussion on Mar 01, 2016 @ 09:28 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac