sketchucation logo sketchucation
    • Login
    1. Home
    2. johnwmcc
    3. Posts
    ⌛ Sale Ending | 30% Off Profile Builder 4 ends 30th September
    J
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 18
    • Posts 105
    • Groups 2

    Posts

    Recent Best Controversial
    • RE: How do I select the built-in Rotate Tool in a script?

      Many thanks for such a prompt and helpful reply. I'll try it later today - have to go out shortly now.

      As a more general question, how could I have found this out for myself? I'm not (I think) stupid, but I don't recall seeing anything anywhere I looked in Ruby tutorials, or examples, that would have pointed me to this solution. I suppose, with hindsight, I could have seen that there is a Sketchup class, send_action method, but how should I have known to look there?

      JohnMcC

      posted in Developers' Forum
      J
      johnwmcc
    • How do I select the built-in Rotate Tool in a script?

      I'm trying to adapt an existing script to add a step at the end, after it creates and inserts a component, leaving it selected. I want to allow the user to rotate the inserted component about the insertion point.

      I thought it ought to be possible to get the script to activate the built-in Rotate tool, locate it at the component insertion point, ensure is is rotating about the blue axis, then let the user rotate the component to a picked angle, or a value in the VCB.

      But I just can't find any tutorial or sample script that illustrates this - though I've hunted the forums for several hours looking. I'm having real difficulty in general getting into Ruby programming, for want of examples of how to USE the Class and Method definitions beyond the simple examples included in the Plugins/Examples, though I've used other object-oriented programming languages in the past. And other people's scripts are easy to adapt in some ways, but only if I understand how they work, which isn't always easy for me.

      Can anyone help please?

      I've got as far as identifying the selected component:

      model = Sketchup.active_model
      ss = model.selection
      

      Then what? I found that the name of the tool I want is RotateTool, by selecting it in the drawing area, then running the script line in the Ruby console

      name = Sketchup.active_model.tools.active_tool_name

      but I can't see how to activate it from the script.

      model.select_tool seems only to apply to user-defined tools - at least, model.select_tool RotateTool or RotateTool.new both give errors.

      tools=model.tools just returns a set of currently defined (?user) tools, but I can't see what to do with it. It doesn't have a method called RotateTool.

      Perhaps I'm on the wrong track altogether - do I need instead to apply a Geom::Transformation in some way to the selected object instead? If so, I then have to implement something to find the insertion point and pick the angle, and again, I can't find an example to show me the way.

      Any ideas for a rookie Ruby programmer gratefully received.

      JohnMcC

      posted in Developers' Forum
      J
      johnwmcc
    • Print quirks in Layout

      I'm just starting to use Layout to print SketchUp models, and hope this feedback is useful to improve the beta version I'm using (the latest available).

      I'm running Windows Vista (SP1), with a connection to a networked HP DeskJet 1200C printer (using A4 and A3 paper).

      Three comments (1 & 2 seem like bugs to me, 3. is a missing feature):

      1. Printing to A4 landscape paper seems to ignore any page margin set in the File/Page Setup menu, and doesn't print part of the 'top' of the landscape page. I've drawn a border on the page at the outer edge of the paper grid (which in turn is set to 'clip to printer margins' in Document Setup), but the 'top' border doesn't print and part of the drawing is missing too, though not a lot. Also, when I change the grid from metric to imperial, the grid displays outside the printed area.

      2. Print Preview only shows about 2/3 of the width of a landscape page. The right hand side is blank where the rest of the SketchUp model should be, and only part of a text label added in Layout is visible on this part of the page. This is often a symptom of lack of memory in other programs, but I've got 4GB in this machine, and an Intel Core 2 Quad 6600 processor, with no other major programs open, so it isn't a machine resource issue.

      3. There are no ISO A-size templates, only Letter and Tabloid US paper sizes, for American users. What about International users?

      Is there any workaround (other than 'printing' to PDF) for the missing print area, and/or the preview bug? I have an nVidia GeForce 9500 graphics card, with the latest available drivers as of a few weeks ago.

      Thanks for a great program, nonetheless.

      John McC

      posted in LayOut Discussions layout
      J
      johnwmcc
    • RE: Starting the CylTool in the sample linetool.rb script

      Well, it wouldn't have 'been clear in the morning' without your clarification, Jim, but it now is - THANKS.

      I now see that although the Class CylTool is defined, the function to create the tool is NOT 'def'ined.

      So my slightly modified code now works to provide Draw menu entries for 'Construction line' and 'Cylinder - on axis' with the addition of just these lines at the end of the linetool.rb script where only the first four lines were originally.

      These functions provide shortcuts for selecting the new tools

      def linetool
      Sketchup.active_model.select_tool LineTool.new
      end

      def cyltool
      Sketchup.active_model.select_tool CylTool.new
      end

      Add tools to Draw menu

      if( not file_loaded?("linetool.rb") )
      UI.menu("Draw").add_item("Construction line") { linetool }
      UI.menu("Draw").add_item("Cylinder - on axis") { cyltool }
      end

      file_loaded("linetool.rb")

      I now just want to add a few refinements, which I can see how to do (following the excellent examples elsewhere in this forum and in the script repositories), to:

      • specify the radius or diameter of the cylinder
      • make the drawn cylinder into a group or component automatically
      • design PNG graphics to indicate which tool is in use, instead of the generic white arrow.

      Thanks again for such a prompt and helpful response - much appreciated.

      John McC

      posted in Developers' Forum
      J
      johnwmcc
    • Starting the CylTool in the sample linetool.rb script

      I'm very new to Ruby programming for SketchUp (first started using it only two weeks ago), but have downloaded many of the generous selection of free sample tools, and modified some to do more closely what I want - for example, I've added a Sphere to the Shapes tool, and also added a couple of lines of code for each Shape to remember the previously used parameters. (I'd be happy to post this somewhere suitable for others, if that would be useful.)

      I'd like to be able to use the example CylTool in the linetool.rb script (which illustrates inheritance from the LineTool), but can't see how to call it or put it on a menu.

      I successfully added the 'standard' lines of code at the end of the LineTool to put the entry 'Construction line' on to the Draw menu, as below.

      Add LineTool to Draw menu

      if( not file_loaded?("linetool.rb") )
      UI.menu("Draw").add_item("Construction line") { linetool }
      end

      file_loaded("linetool.rb")

      But I can't see how to do the equivalent to start the CylTool - I've tried substituting CylTool for LineTool and changing "Construction line" to "Cylinder - pick axis" instead of the above lines at the end, but it doesn't work.

      And if I just type 'cyltool' in the Ruby console, with the linetool.rb script loaded and working, I get

      Error: #<NameError: (eval):298: undefined local variable or method `cyltool' for main:Object>
      (eval):298

      Any pointer to how to do this would be welcome, as I'd really like to use this script as the basis for a range of other tools, and have got stuck on using the 'inheritance' part. Is there something missing from the code to draw a cylinder this way?

      I'd also like to adapt the code at the start of the LineTool to modify the Shapes tool to allow you to pick a point to start the shape, not always have it at the origin. I can see in principle how to do that.

      Further, I'd like very much to be able not only to place the component or shape, but also to be able to place and rotate it about its origin (around the z-axis) in one go, without having manually to choose the Rotate tool, pick the rotation plane and origin, etc. I wrote something similar years ago in AutoLisp for AutoCad, but can't see how to go beyond the place_component method to include the rotation step. I guess I'd have to generate a selection set in code for the script-created group or component, then use the PickHelper or InputPoint class to pick the point at which to place the entry, then a second pick for the direction of the newly drawn group or component's x-axis.

      And a final 'wish' that I'd like to be able to code is a script 'Draw new component', to start a 'draw' operation, draw an object perhaps with several elements to it, then automatically select all its elements to make it into a component when the object is complete. Maybe I'm missing something obvious, but I have to go through contortions to select only the things I've just drawn in a complex scene, as they usually aren't still highlighted after I've finished drawing them.

      As a simple common example, take drawing a box with the Rectangle tool then PushPull. Easy to window select the result in a clear field, but not if it is surrounded by other previously draw objects.

      (Though on reflection, perhaps I could use instead the context menu 'Select->All connected' for this particular simple construction - I've only just discovered this. However, that wouldn't work for some more complex objects.)

      I've read what I can find on the Internet in forums like this one, and am quite prepared to work at it, and have learned a lot just from looking at a lot of sample scripts - but I just can't see quite how to get started on the CylTool.

      Thanks if anyone can offer a few pointers.

      John McC

      posted in Developers' Forum
      J
      johnwmcc
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 6 / 6