Just load the tool script once at the start of your main script, and then instantiate your tool in the UI handler the same way you were doing before.
Latest posts made by Diggsey
-
RE: Menus & Tools
-
RE: Update a WebDialog
Your first problem is very easy to solve, just make sure that your ruby script executes asynchronously.
I use this function in a couple of my scripts instead of the outer-most loop:def asyncLoop(range, &proc) from = range.min to = range.max iteration = lambda do |index| last = (index > to) proc.call(index, last) if !last then UI.start_timer(0.02, false) { iteration.call(index.succ) } end end iteration.call(from) return nil end
You can use it like this:
asyncLoop(0...16) do |i, last| if (!last) then # Perform ith iteration else # Put code to be run after this operation here instead of outside the loop end # Code here will run immediately, so leave it empty
-
[Plugin] Spritely v0.1
This plugin lets you create sprites from your models. It's primarily intended for tile-based games, so it uses an orthographic camera but you can choose the viewing angle and things like that.
How to use:
- Click the "Select Tile" tool and select the rectangle which would be the tile below your model.
- Click the "Capture Sprite" tool to generate the images.
Features:
- Supports transparency
- Images are antialiased
- Images from different angles are all aligned correctly
- Can generate a single image or images from all angles
It uses the default sketchup renderer, but you could theoretically plug-in any renderer which used sketchup's camera settings.
Example output (9 images from 32 generated):
-
RE: Absurd camera behaviour
@unknownuser said:
Ruby has ONLY 2 basic things. Objects and References that point at objects.
It does not really have variables, like BASIC or Pascal.
So all you did was define a reference cam1 that points at the current view object's camera object.
Later you made that same camera object's pointer (bypassing your cam1 reference,) point at the cam2 referenced camera object.So yes.. you need to save at the minimum the camera object's eye, target and up, in some way. Local references, a hash, an array.. etc.
I know how references work, and this strange behaviour is not simply a by-product of that:
- First I save a reference to the view's camera
- Next I create a NEW camera object, and set the view's camera reference to that object
- Now there should be two camera objects in existence, so modifying the properties of one should not affect the properties of the other, but it does.
I've tracked it down and the reason for the behaviour is this:
- Camera objects start off "empty", and simply store a set of parameters, and don't relate to an actual camera, so you can have many instances of them and change their properties independently.
- When a camera object is assigned to a view's camera, the camera object completely changes to become a wrapper around an actual camera - all its parameters are applied to the actual camera and then deleted, and instead the camera object has a pointer to the actual camera, so from now on when you set/get a parameter it goes straight through the wrapper to the actual camera.
In reality these two states should be separate classes, the first storing the properties of a camera, and the second wrapping an actual camera in sketchup, with methods to set/get a cameras properties as an object.
-
RE: Absurd camera behaviour
@unknownuser said:
clone() and dup() only work for standard Ruby classes (or those API classes that Google specifically overrode, ie, redefined the clone method that is inherited from class Object. [.. And there are only a few or these.])
I realise that, I was just making sure I tried every possibility I could think of.
@unknownuser said:
OK.. so when no args are given, what is eye, target and up ?
It doesn't really matter as long as they are valid (which they are, I've tested it). Either way it's not directly related to the problem, which still occurs in code which does everything "properly" and that code was just the simplest way I could demonstrate it.
-
RE: Absurd camera behaviour
The first one is a typo (fixed), and the second one is not true, both the API docs and ruby reflection clearly show that it can be called with no arguments.
-
Absurd camera behaviour
I have a situation where I need to take control of the camera temporarily, but I'd like to return it to its original position at the end. The API docs show that you can create new instances of the camera class, so I just saved the original camera, did my stuff with the new one and then restored the original camera at the end. The problem is that once a camera has been set as the camera for a view, it actually modifies the old camera instance!
Example:
cam1 = Sketchup.active_model.active_view.camera cam1.perspective = true cam2 = Sketchup;;Camera.new cam2.perspective = false cam1.perspective? # outputs true cam2.perspective? # outputs false Sketchup.active_model.active_view.camera = cam2 cam1.perspective? # outputs false cam2.perspective? # outputs false
Seemingly the only way to get this to work is to save all the properties of the curent camera individually at the start and then restore them at the end, but this means the script would break if any new properties are added to the camera class.
I've also tried using "clone" on the camera which seemed initially to work, but gives the strange error: "Error: #<TypeError: (eval):0:in `perspective?': reference to deleted Camera>" when I try to use it.
-
RE: [Plugin] SurfaceGen (0.9.0b) β 28 April 2012
I haven't posted in ages, but I just noticed that there was a way I could improve the speed of this plugin. The new version only calls "eval" once to create a proc object which it then calls repeatedly, so it shouldn't have to keep parsing the expression each time.
-
RE: [Plugin] SurfaceGen (0.9.0b) β 28 April 2012
Unfortunately, I don't think there's a way to give focus back to SketchUp from ruby. (Someone correct me if I'm wrong!)
-
RE: [Plugin] SurfaceGen (0.9.0b) β 28 April 2012
I've updated the first post with version 0.8.
@Pixero
What exactly do you mean by noise? Surely just adding (rand-0.5) will put noise on the graph?