[Pythonmac-SIG] get reference

Zhi Peng zhiyong_peng2003 at yahoo.com
Wed Oct 26 23:53:05 CEST 2005


Hi! "Has" 
I run the MacPython script, the only error is in the
set geometric_bounds as following where I used
appscript 1.1. It seems better than previous version. 
Thanks 

zhi-pengs-power-mac-g5:~/Documents/projects zpeng$
pythonw has.py >error.txt
Traceback (most recent call last):
  File "has.py", line 14, in ?
   
myTextFrame.geometric_bounds.set(["6p0","6p0","18p0","18p0"])
  File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/appscript/specifier.py",
line 179, in __call__
    raise CommandError(self, (args, kargs), e)
appscript.specifier.CommandError: Too many direct
arguments.
        Failed command: app(u'/Applications/Adobe
InDesign CS2/Adobe InDesign
CS2.app').documents[u'Untitled-1'].spreads.ID(146).pages.ID(151).text_frames.ID(179).geometric_bounds.set(['6p0',
'6p0', '18p0', '18p0'])
zhi-pengs-power-mac-g5:~/Documents/projects zpeng$ vi
error.txt


--- Zhi Peng <zhiyong_peng2003 at yahoo.com> wrote:

> Hi! 'Has" 
> 
> First of all, thank you very much for your help. 
> 
> tell application "Adobe InDesign CS2" 
>    set contents of text frame 1 of page 1 of
> document
> 1 to "Hello"
> end tell 
> 
> works well. (textframe -> text frame in adobe)
> 
> But Corresponding MacPython code does not work well
> where I used appscript 1.1 (3.7 MB). Should I use
> other version of Appscript? 
> 
> Following is the information I used debug. 
> 
> 
> >
>
/Users/zpeng/Documents/projects/set_text_frame.py(44)?()
> ->
>
cs.documents[1].pages[1].text_frames[1].contents.set("set
> the frame")
> (Pdb) n
> CommandError:
> appscript.CommandError(app(u'/Applications/Adobe
> InDesign CS2/Adobe InDesign
> CS2.app').documents[1...ext_frames[1].contents.set,
> (('set the frame',), {}), <exceptions.TypeError
> instance at 0x13fd0d0>)
> >
>
/Users/zpeng/Documents/projects/set_text_frame.py(44)?()
> ->
>
cs.documents[1].pages[1].text_frames[1].contents.set("set
> the frame")
> (Pdb)
>
cs.documents[1].pages[1].text_frames[1].contents.get()
> (Pdb) print
>
cs.documents[1].pages[1].text_frames[1].contents.get()
> None
> 
> 
> 
> 
> ================
> 
> But it is much better than that before. 
> 
> 
> Regards 
> 
> Zhi 
> 
> 
> 
> 
> 
> 
> --- has <hengist.podd at virgin.net> wrote:
> 
> > Zhi Peng wrote:
> > 
> > >But with app('Adobe InDesign CS2'), it
> > >does not work well. All application can accept
> the
> > >commands but not the reference such as
> > >
> > >cs = app("Adobe InDesign CS2")
> > >cs.activate()   ----------------- works
> > >cs.open("filepath_with_name")   ------- works
> > >doc = cs.documents[0]             -------- works
> > 
> > Shouldn't work, because elements of application
> > objects are always 1-indexed. (It's not impossible
> > that a scriptable app might try to 'helpfully'
> > interpret a 0 index rather than just flagging it
> as
> > an error, but I'm not aware of any that do.)
> > However, note that a bad reference won't raise an
> > error until you actually use it in a command, at
> > which point the application will raise an Apple
> > event error of [usually] type -1728 which
> appscript
> > reports as a CommandError.
> > 
> > 
> > >page = doc[1]                          --------
> > works
> > 
> > I think you meant 'page = doc.pages[1]'
> > 
> > 
> > >textframe.contents="HELLO"      ------ not work
> > 
> > Not supported.
> > 
> > 
> > The following should work, assuming it's
> > semantically correct and identifies an existing
> > object:
> > 
> >
>
cs.documents[1].pages[1].textframes[1].contents.set("HELLO")
> > 
> > If it doesn't, check the AppleScript equivalent
> just
> > to make sure that it works:
> > 
> > tell application "Adobe InDesign CS2"
> > 	set contents of textframe 1 of page 1 of document
> 1
> > to "HELLO"
> > end tell
> > 
> > Then tell me what version of appscript you're
> using
> > and post a traceback so I can see what the error
> > actually is. Like I say, it may just be that you
> > need to upgrade to the latest version of
> appscript,
> > though I'd like to make sure it's not something
> > else.
> > 
> > 
> > >I wonder if I missed something since I get only a
> > >small __init__.py file while I used pythonw
> > >getsuitmodule.py for Adobe InDesign CS2. But same
> > >command applied to TextEdit and Finder, iTune, I
> > get a
> > >few big file include __init__.py.
> > 
> > I wouldn't know about that. gensuitemodule has
> > always been rather flaky and clumsy; however,
> > appscript has no connection to it or
> > aetools/aepack/aetypes.
> > 
> > has
> > -- 
> > http://freespace.virgin.net/hamish.sanderson/
> > _______________________________________________
> > Pythonmac-SIG maillist  - 
> Pythonmac-SIG at python.org
> >
>
http://mail.python.org/mailman/listinfo/pythonmac-sig
> > 
> 
> 
> 
> 	
> 		
> __________________________________ 
> Yahoo! Mail - PC Magazine Editors' Choice 2005 
> http://mail.yahoo.com
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG at python.org
>
http://mail.python.org/mailman/listinfo/pythonmac-sig
> 



	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com


More information about the Pythonmac-SIG mailing list