Forum Archive

Help

Jozh

What do I add to this script so it output each element (date,text, width and, length ) on a separate lines of the open file? '\n' ? Thanks.

import dialogs


Dialog_List =[{'type':'date','title':'Date','key':'date'},{'type':'text','title':'description','key':'text'},{'type':'number','title':'Width','key':'wid'},{'type':'number','title':'Length','key':'len'},]

Form_Dialogs = dialogs.form_dialog('Form Dialog',Dialog_List)

date = Form_Dialogs['date']
text = Form_Dialogs['text']
width = Form_Dialogs['wid']
length = Form_Dialogs['len']
omz

You're almost there. You can use the editor module to insert text in the current document:

import dialogs
import editor

Dialog_List =[{'type':'date','title':'Date','key':'date'},{'type':'text','title':'description','key':'text'},{'type':'number','title':'Width','key':'wid'},{'type':'number','title':'Length','key':'len'},]

Form_Dialogs = dialogs.form_dialog('Form Dialog',Dialog_List)

if Form_Dialogs:
    date = Form_Dialogs['date']
    text = Form_Dialogs['text']
    width = Form_Dialogs['wid']
    length = Form_Dialogs['len']
    date_str = date.strftime('%Y-%m-%d')

    to_insert = '\n'.join([date_str, text, width, length])
    editor.insert_text(to_insert)

Note that I also converted the date to a string. You could customize the format by passing something else to strftime().

Jozh

Thank you