From grzessnik at interia.pl Tue Jun 5 08:42:22 2007 From: grzessnik at interia.pl (grzessnik at interia.pl) Date: 05 Jun 2007 14:42:22 +0200 Subject: [Rb-appscript-discuss] rb-appscript, adobe and classes Message-ID: <20070605124222.A553A97A898@poczta.interia.pl> Hi I think about one thing and when I'try to make it, it's fail. I try to make rb script to draw figures in AI I want to work with Adobe Illustrator and make class f.e. Figur, and then child classes (Square, Triangle etc.). In this classes I need to define methods f.e. draw, move, color etc. Can I do this using ruby statement class and connect this with AI classes? Problem is because I must define document, then objects on page and I don't know how to transfer it to class level. I can define one figure normal in AI, but I do this on "page" level. I have no idea how to do this smart, and automatically draw f.e. 100 squares. Thanks for help, and sorry for unprecise writing, but I don't know how to write it better in english. Grzessnik ---------------------------------------------------------------------- Wicie, rozumicie.... Zobacz >>> http://link.interia.pl/f1a74 From hengist.podd at virgin.net Tue Jun 5 14:49:15 2007 From: hengist.podd at virgin.net (has) Date: Tue, 5 Jun 2007 19:49:15 +0100 Subject: [Rb-appscript-discuss] rb-appscript, adobe and classes In-Reply-To: <20070605124222.A553A97A898@poczta.interia.pl> References: <20070605124222.A553A97A898@poczta.interia.pl> Message-ID: <7109D75C-D20A-4DCE-9DB5-6AF571BB86BB@virgin.net> On 5 Jun 2007, at 13:42, grzessnik at interia.pl wrote: > I try to make rb script to draw figures in AI > > I want to work with Adobe Illustrator and make class f.e. Figur, > and then child classes (Square, Triangle etc.). In this classes I > need to define methods f.e. draw, move, color etc. > > Can I do this using ruby statement class and connect this with AI > classes? > Problem is because I must define document, then objects on page and > I don't know how to transfer it to class level. > > I can define one figure normal in AI, but I do this on "page" > level. I have no idea how to do this smart, and automatically draw > f.e. 100 squares. (Apologies in advance as I'm not really familiar with AI scripting...) Drawing basic shapes seems to be simple enough, e.g.: AI = app('Adobe Illustrator.app') def draw(x, y) AI.documents[1].make(:new=>:polygon, :with_properties=>{ :center_point=>[x, y], :radius=>20, :sides=>4, :stroke_width=>10, :fill_color=>{:black=>0, :magenta=>50, :cyan=>50, :yellow=>100}, }) end 10.times do |x| 10.times do |y| draw(x*50+50, y*50+50) end end It sounds like you're wanting either one of two things: 1. A convenient way to churn out lots of similar-looking objects while changing just one or two characteristics (e.g. their position) each time you create a new one. e.g.: o = Square.new(AI.documents[1]) o.width = 40 o.stroke_width = 2 o.stroke_color = [0, 0, 0, 100] o.fill_color = [50, 0, 0, 0] o.position = [400, 500] o.draw # draws a square o.position = [500, 500] o.draw # draws another square o.position = [500, 600] o.draw # etc. or: 2. To create a set of Ruby classes, each instance of which acts as a proxy for a *specific* object in an AI document. e.g.: sq1 = Square.new # draws a square in AI and returns a Ruby object which can be manipulated at any time later on, with those changes being automatically applied to the AI object simultaneously sq2 = Square.new # ditto c1 = Circle.new # ditto sq1.position = [400, 500] sq2.position = [900, 500] c1.position = [800, 100] #1 is easy enough to do; #2 presents a bit more of a challenge, but should be possible. However, I'm not clear yet which one you want. If you could clarify a bit further - say a bit more about what you're trying to achieve and why, and perhaps provide a pseudo-code example that shows how you intend to use these classes of yours - it'd be a help. Cheers, has -- http://appscript.sourceforge.net http://rb-appscript.rubyforge.org http://appscript.sourceforge.net/objc-appscript.html From hengist.podd at virgin.net Tue Jun 5 15:03:42 2007 From: hengist.podd at virgin.net (has) Date: Tue, 5 Jun 2007 20:03:42 +0100 Subject: [Rb-appscript-discuss] rb-appscript, adobe and classes In-Reply-To: <7109D75C-D20A-4DCE-9DB5-6AF571BB86BB@virgin.net> References: <20070605124222.A553A97A898@poczta.interia.pl> <7109D75C-D20A-4DCE-9DB5-6AF571BB86BB@virgin.net> Message-ID: <9129F473-8B06-4063-A4F9-E2B2DE10E2A8@virgin.net> On 5 Jun 2007, at 19:49, has wrote: To clarify a bit further: > 1. A convenient way to churn out lots of similar-looking objects > while changing just one or two characteristics (e.g. their position) > each time you create a new one. In other words, you're writing regular 'AppleScript-style' code, but would like to structure it so that you can specify size, position, colour, etc using separate method calls before calling the main 'draw' method rather than having to pass all these values as a really long list of arguments to the 'draw' call. > 2. To create a set of Ruby classes, each instance of which acts as a > proxy for a *specific* object in an AI document. e.g.: In other words, you want Apple events to behave more like COM. has -- http://appscript.sourceforge.net http://rb-appscript.rubyforge.org http://appscript.sourceforge.net/objc-appscript.html From grzessnik at interia.pl Tue Jun 5 17:48:15 2007 From: grzessnik at interia.pl (Grzegorz Laszczyk) Date: Tue, 05 Jun 2007 23:48:15 +0200 Subject: [Rb-appscript-discuss] rb-appscript, adobe and classes Message-ID: <4665DA1F.5080904@interia.pl> I'm thinking about a kind of automat, that can draw different geometrical patterns (as parameters I want to define f.e. rotation, scale factor, move etc.) To achieve this I need 1st way, you have described. Of course 2nd sounds great, but for now it is to difficult for me, I think. When I do this my next step will be to draw an object and define modifiers (such a rotate point etc.) by the mouse. But it's a future. Grzessnik ---------------------------------------------------------------------- Kasia Cichopek eksponuje biust >>> http://link.interia.pl/f1a6f From hengist.podd at virgin.net Wed Jun 6 07:03:13 2007 From: hengist.podd at virgin.net (has) Date: Wed, 6 Jun 2007 12:03:13 +0100 Subject: [Rb-appscript-discuss] rb-appscript, adobe and classes In-Reply-To: <4665DA1F.5080904@interia.pl> References: <4665DA1F.5080904@interia.pl> Message-ID: <0D6FDA67-AE6D-4BBB-B59D-334A029C006C@virgin.net> On 5 Jun 2007, at 22:48, Grzegorz Laszczyk wrote: > I'm thinking about a kind of automat, that can draw different > geometrical patterns (as parameters I want to define f.e. rotation, > scale factor, move etc.) > To achieve this I need 1st way, you have described. > Of course 2nd sounds great, but for now it is to difficult for me, > I think. > > When I do this my next step will be to draw an object and define > modifiers (such a rotate point etc.) by the mouse. But it's a future. Sounds like you want to do something like this: #!/usr/local/bin/ruby require 'appscript' include Appscript AI = app('Adobe Illustrator.app') class Shape attr_writer :position, :radius, :stroke_width, :stroke_color, :fill_colo r def initialize @position = [500, 500] @radius = 10 @stroke_width = 1 @stroke_color = [0, 0, 0, 100] @fill_color = [0, 0, 0, 0] end def _color(color) if color c, m, y, k = color return {:class_=>:CMYK_color_info, :cyan=>c, :magenta=>m, :yellow=>y, :black=>k } else return {:class_=>:no_color_info} end end def draw AI.documents[1].make(:new=>:polygon, :with_properties=>{ :center_point=>@position, :radius=>@radius, :sides=>self.class::Sides, :stroke_width=>@stroke_width, :stroke_color=>_color(@stroke_color), :fill_color=>_color(@fill_color), }) end def draw_at(x, y) @position = [x, y] draw end end class Triangle < Shape Sides = 3 end class Square < Shape Sides = 4 end # etc. # Example o = Square.new o.stroke_color = [100, 0, 100, 0] o.stroke_width = 4 o.fill_color = nil o.draw_at(200, 300) o.draw_at(300, 300) o.draw_at(400, 300) That said, depending on what you're doing, you may find it as easy just to draw the first object, then use AI's duplicate command to clone it: #!/usr/local/bin/ruby require 'appscript' include Appscript AI = app('Adobe Illustrator.app') o = AI.documents[1].make(:new=>:polygon, :with_properties=>{ :position=>[200, 500], :radius=>20, :sides=>5, :stroke_width=>1, # etc. }) o.duplicate(:with_properties=>{:position=>[300, 500]}) o.duplicate(:with_properties=>{:position=>[400, 500]}) # [1] o.duplicate(:with_properties=>{:position=>[500, 500]}) # [2] [1][2] Quick reminder re. Apple event semantics, since the way this code looks is subtly misleading as to how it works. Note that the references returned by AI identify page items by index (which is determined by stacking order), so while these lines looks like they're copying the object drawn by the 'make' command what they're really saying is 'copy the topmost - i.e. last drawn - object'. Not an issue in this example, but if you're making other adjustments between duplicating objects, it may catch you out. As far as I can tell, AI doesn't support the by-ID reference form (which is the only one that guarantees to identify the same object each time), although it does allow you to name objects which could provide an ersatz equivalent by using a unique name each time. (This is why I asked earlier if you were wanting COM-like behaviour as your shape classes would need to implement an automatic naming scheme to keep a permanent 'handle' on each object they create.) HTH has -- http://appscript.sourceforge.net http://rb-appscript.rubyforge.org http://appscript.sourceforge.net/objc-appscript.html From whitley at acm.org Tue Jun 12 20:09:06 2007 From: whitley at acm.org (John Whitley) Date: Tue, 12 Jun 2007 17:09:06 -0700 Subject: [Rb-appscript-discuss] Convert path into file reference? Message-ID: Hi all, Can anyone point me towards the most straightforward way to convert a path (Unix-style, not a Finder path) into a file reference (Finder path?) suitable for passing to the open() method of QuickTime Player? I'm trying to script QT Player, storing the path of an open movie, then reopening that same movie later. It seems that movie.path is a Unix-style path, while the QT open command accepts a "file", which is not a Unix path string. After some experimentation, I did discover that open() will accept a Finder path. Is there a "blessed" way to convert between Unix and Finder paths? Is there another kind of "file" (e.g. a Finder file class?) that open will accept that is more useful? I kicked around for a bit in the Finder.app terminology, but nothing's popped out at me as of yet. Thanks much! John Whitley From whitley at acm.org Wed Jun 13 00:46:52 2007 From: whitley at acm.org (John Whitley) Date: Tue, 12 Jun 2007 21:46:52 -0700 Subject: [Rb-appscript-discuss] Convert path into file reference? In-Reply-To: References: Message-ID: <61E9E504-CB75-4976-AF05-EDF548D164A4@acm.org> John Whitley wrote: > Can anyone point me towards the most straightforward way to convert a > path (Unix-style, not a Finder path) into a file reference (Finder > path?) Sigh. Time to answer my own question, from the rb-appscript examples no less (I was looking too far from home, it seems). The MacTypes module in rb-appscript "defines wrapper classes for Mac OS datatypes that don't have a suitable Ruby equivalent." This snippet from sample/Open_file_in_TextEdit.rb in the rb-appscript distribution says all: te = app('TextEdit') te.activate te.open(MacTypes::Alias.path('/Users/USERNAME/ReadMe.txt')) -- John