sketchucation logo sketchucation
    • Login
    1. Home
    2. Diggsey
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    D
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 5
    • Posts 37
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: Menus & Tools

      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.

      posted in Developers' Forum
      D
      Diggsey
    • 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
      
      
      posted in Developers' Forum
      D
      Diggsey
    • [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):

      http://forums.sketchucation.com/download/file.php?mode=view&id=87149&sid=3642022df9db93e60e165ff8e87ca727


      spritely.zip


      sprites.png

      posted in Plugins
      D
      Diggsey
    • 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.

      posted in Developers' Forum
      D
      Diggsey
    • 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.

      posted in Developers' Forum
      D
      Diggsey
    • 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.

      posted in Developers' Forum
      D
      Diggsey
    • 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.

      posted in Developers' Forum
      D
      Diggsey
    • 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.

      posted in Plugins
      D
      Diggsey
    • 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!)

      posted in Plugins
      D
      Diggsey
    • 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?

      posted in Plugins
      D
      Diggsey
    • RE: [Plugin] Autoloader

      Yes, of course. It doesn't affect the way the plugin is loaded, it just loads it.

      posted in Plugins
      D
      Diggsey
    • RE: [Plugin] SurfaceGen (0.9.0b) — 28 April 2012

      If you need to use the same settings as last time just copy and paste the graph, and then change the settings you need to. All the settings are stored as attributes of the graph so will be copied with it. If you need to change the size you can use the scale tool just as easily as creating a new graph.

      posted in Plugins
      D
      Diggsey
    • RE: [Plugin] SurfaceGen (0.9.0b) — 28 April 2012

      Just updated again fixing a small bug with the expression parser.

      Check out this graph:

      http://i59.photobucket.com/albums/g314/diggsey/th_face.jpg

      Equation = min(((max(abs(y)-(2sqrt(z+4)) ,(x+0.5abs((abs(y)+4)/3.5)/(1+(((abs(y)+4)/3.5)^2-2)^2)/2 2/(1+(z-2)^2)+abs(y/1.5)^3.5/7 ) )max( max( abs(x+0.15+(y/0.7)^2)+(z-1.3)/1.4,max(z-2.3, max( abs(x+0)/2.4 -1+2abs(1.5y)+(z+0.1)/2 , -z ))) ,x-0.8+z/2)-0.1 )*(abs(x+y^2/3)-0.2+abs(abs(z+1.8)-(0.5-(y/2)^2) )^1.2 )-0.1 ),( (x+1.2+abs(y)/10)^2+(abs(y)-1.1)^2/2.5+(z-2.3)^2/1.8-0.64))
      x: -3 to 1
      y: -4 to 4
      z: -4 to 5.4

      @TIG
      Yes you can use any built in ruby function;)

      @jim
      I can't make the window resizable because it is shown and hidden by resizing it to a fixed value and zero respectively, and there is no API function to get the size of the window to save it. However, you can easily change the height of the window. Open surfacegen.rb in notepad and change the line "WINDOW_HEIGHT = 320" to about "WINDOW_HEIGHT = 350". You can try different values until you get what you want.

      posted in Plugins
      D
      Diggsey
    • RE: [Plugin] SurfaceGen (0.9.0b) — 28 April 2012

      Ah, I knew I'd forgotten something 😄

      I've updated the first post. It shouldn't show those errors anymore.

      posted in Plugins
      D
      Diggsey
    • RE: [Plugin] Recurve

      I've fixed the bug. It happened when faces touched the curve at just a corner. The code needs to do something for each face touching the curve, and it used to find all the faces connected to all the edges in the curve. Now it finds all the faces connected to all the vertices in the curve instead.

      posted in Plugins
      D
      Diggsey
    • RE: [Plugin] SurfaceGen (0.9.0b) — 28 April 2012

      Just uploaded a fairly major update to the first post!

      @driven
      This should fix the issues with macs. It now uses cross-platform methods to locate and load resource, and uses show_modal rather than show on macs with the WebDialog.

      @notareal
      The axes now let you use an expression such as 2*pi

      @d12dozr
      Helpful error message are now shown when an expression is invalid.

      posted in Plugins
      D
      Diggsey
    • RE: [Plugin] Recurve

      I see what you mean. It seems that if you have two softened edges on the same side that it won't recurve properly. There is some code which divides the curve up if it intersects a hard edge, so maybe that's what's causing the problem. I'll have to look into it.

      posted in Plugins
      D
      Diggsey
    • RE: [Plugin] Recurve

      It uses an angle of 1 radian (~57 degrees) as the cut-off.

      posted in Plugins
      D
      Diggsey
    • RE: [Plugin] SurfaceGen (0.9.0b) — 28 April 2012

      @notareal
      That's really nice! What's the equation you used?

      @TIG
      Make sure you have the latest version of Recurve. I fixed that bug with the last update which is why I couldn't reproduce the error. If you ever get the SurfaceGen error again let me know.

      @Pilou
      Just re-select the group with the select tool. It seems that the SelectionObserver doesn't fire when the selection is changed in code.

      posted in Plugins
      D
      Diggsey
    • RE: [Plugin] SurfaceGen (0.9.0b) — 28 April 2012

      I've tried doing everything possible and can't seem to get any output in the ruby console from either plugin. Can you tell me exactly how to reproduce it?

      posted in Plugins
      D
      Diggsey
    • 1 / 1