XojoScript to manipulate a graphics object

Is this possible? According to a forum post from way back when, they claim it is; however I can find nothing in the documentation to back this up.

I spend a lot of time “trying” to get my graphics code looking “perfect”, and I would like to use an application to do this, rather than code, save, compile, make notes, code, save, compile process that I currently use.

Being able to visually see graphics manipulations while I write them, would save me a lot of time (and reduce ware on the SSD).

not directly
you cannot pass a graphics object across the context object INTO the script code

BUT … you CAN set up a context with a property that it has and expose the graphics drawing operations via methods on the context object to XojoScript and then you can write script code to manipulate a graphics object via those methods


      Class MyContext 
               Sub Constructor(g as graphics)
                       self.g = g
               end sub 

               private property g as graphics // or maybe p as picture ?

               Sub DrawString(s as string, x as integer, y as integer)
                       g.drawstring s, x, y
               End Sub

               ... etc // expose other graphics drawing operations and properties via context methods

       End Class

       dim s as new XojoScript

       s.context = new myContext(g)
       s.source = ... whatever source code you want .....

Thank you Norman,
It’s not quite what I was expecting, I was hoping to be able to enter the same code as I would within Xojo.

Seems I am unable to get “g.” to work. Which immediately makes the code somewhat different, and while after a lot of work, it might help me with my goal, it also means that the code will have to be modified before I can use it in my project.


For the time being, I am using replaceAll( “g.” ) to keep as much consistent as possible.

Before Joe went to work for Xojo, we had this working. You passed a graphics object to the context. It relied on some Lib "" declares which no longer function, obviously. Unfortunately Norman is right, the only way now is to build up the context with the methods.

@Norman Palardy Thanks for your help mate. I managed to get something together before it was time to walk the dogs again.

You could always create a Graphics class in your Xojoscript code, reproduce the methods of the Xojo Graphics class, and get those methods communicating with the context methods. This will do away with the “g.” Issue.

This example also shows how to do some image processing using XojoScript: