[Pythonmac-SIG] get reference

Zhi Peng zhiyong_peng2003 at yahoo.com
Wed Oct 26 22:37:08 CEST 2005


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


More information about the Pythonmac-SIG mailing list