sketchucation logo sketchucation
    • Login
    1. Home
    2. Dan Rathbun
    3. Posts
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    Check out Febhouse | New extensions for Shadow Analysis in SketchUp Download
    Dan RathbunD Offline
    • Profile
    • Following 0
    • Followers 1
    • Topics 92
    • Posts 4,904
    • Groups 2

    Posts

    Recent Best Controversial
    • RE: Error: Reference to deleted entities

      Also do not put a space between the method name and the parenthesis surrounding it's arguments. It is no longer allowed in Ruby 2.x.

      Also it is now convention to always use parenthesis around method call argument lists, except for global methods (those defined in module Kernel or class Object, and any added "legally" to them such as those in "sketchp.rb", RubyGems or standard library gems.)
      They are said to have "keyword status".

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Outliner selection not in Order

      .
      I need to point out again that Steve gave the correct answer

      @slbaumgartner said:

      How about this: you need to tell sort that you want to compare the names to determine order.

      sorted = sel.grep(Sketchup;;ComponentInstance).sort {|a,b| a.name <=> b.name}
      

      If you want to use the definition names, just insert .definition between a,b and .name

      So following the last sentence (in Steve's post,) you insert the .definition into the block twice, thus:

      sorted = sel.grep(Sketchup;;ComponentInstance).sort {|a,b|
        a.definition.name <=> b.definition.name
      }
      

      The block uses <=>, which is the Ruby comparison method.

      This means that the expressions on each side of the <=> must be comparable, which means that at the least, their class must define a <=> method (and might also mixin in the Comparable module.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Setting dynamic attributes to expressions?

      You want the facecopy to intersect with the glued_to face ?

      This might work, untested.

      <span class="syntaxdefault">def get_glued_bounds_facegroup</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">ci</span><span class="syntaxkeyword">)<br /></span><span class="syntaxcomment"># Arg; ci, a component instance<br /># Return nil if ci is not glued;<br />#  or a group with new face you can explode.<br /></span><span class="syntaxdefault">  </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault">  return nil if ci</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">glued_to</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">nil</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault">  </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault">  model </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">active_model<br />  cd </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> ci</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definition<br />  db </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> cd</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">bounds<br />  </span><span class="syntaxcomment"># get pts in counter-clockwise order;<br /></span><span class="syntaxdefault">  pt0 </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> db</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">corner</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># left front bottom<br /></span><span class="syntaxdefault">  pt1 </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> db</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">corner</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># right front bottom<br /></span><span class="syntaxdefault">  pt2 </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> db</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">corner</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">3</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># right back bottom<br /></span><span class="syntaxdefault">  pt3 </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> db</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">corner</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">2</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># left back bottom<br /></span><span class="syntaxdefault">  </span><span class="syntaxcomment"># get transform of ci;<br /></span><span class="syntaxdefault">  tr </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> ci</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">transformation<br />  </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault">  par </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> ci</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">parent<br />  ents </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> par</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities rescue model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities<br />  grp </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> ents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_group</span><span class="syntaxkeyword">()<br /></span><span class="syntaxdefault">  grp</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">pt0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">pt1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">pt2</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">pt3</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  grp</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">transform</span><span class="syntaxkeyword">!(</span><span class="syntaxdefault">tr</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault">end</span>
      

      💭

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Removing duplicat Component Instances from an array

      Or use Enumerable#grep ...

      defns = selection.grep(Sketchup::ComponentInstance){|i| i.definition }.uniq

      But, if you've already got the instances filtered then:

      defns = iarray.map{|i| i.definition }.uniq

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Code correction

      Do NOT put spaces between method names and parameter lists:

      group.transform! (pos)
      should be:
      group.transform!(pos)

      Read up on how to define a class, including use of the built-in initialize method, that automatically gets called by the new constructor.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Compute Rotation and Scale from Transform Object

      @ruts said:

      ...when you call the method euler_angle you create an empty array under variable xyz as parameter.

      The secret is that Ruby does not really "have" variables, even though the books use that name. Ruby has references that point at objects, and a reference can be made to point at any class of object, and then later be re-assigned to point at any other object of any class, at any time.
      This is referred to as "weakly typed", but really Ruby references are not type locked at all.

      @ruts said:

      Then nothing happens with the array for the whole piece of code.

      Because it (the argument) is just being used as a switch to tell the method what the coder wants as an output. An empty array object is simply the default, which tells the method the calling code expects an array as a return object.

      @ruts said:

      At the end the array can be ==0 (contains one element which is equal to zero), ==1, ==2 or still empty. How can it be that the array can contain elements?

      It cannot. You mis-understand. The method is not testing an array, it is testing a reference to the method argument to see if is pointing at integers 0 or 1 or 2, or still pointing at [] (the default empty array object,) and then returning either the indicated values, or an array of all three.

      IF you call the method with no arguments, or like euler_angle([]) you will get an array of 3 values.
      IF you call the method thus: euler_angle(0) you will get the x value returned.
      IF you call the method thus: euler_angle(1) you will get the y value returned.
      IF you call the method thus: euler_angle(2) you will get the z value returned.

      The 0, 1 and 2 subscripts come from the SketchUp API's extension of the Array class, where 3 element arrays can act like points and vectors.

      Still have not read the book, I see.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Compute Rotation and Scale from Transform Object

      Words in ALLCAPS are reserved for constants.
      Words in Titlecase are for Class and Module Identifiers, (which are also constants. Any word the starts with a capital character is a constant.)

      Bad:
      Selection = Sketchup.active_model.selection[0] Rotation = Selection.transformation.rotXYZ

      Good for variables:
      selection = Sketchup.active_model.selection[0] rotation = selection.transformation.rotXYZ
      😉

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Webdialog and ActiveXObject

      @bomastudio said:

      Does .get_element_value works with every DOM elements or only with input-type?

      It should work with any DOM element that supports id and value properties.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Webdialog and ActiveXObject

      It's a URI like the address in the browser. There is a limit to the length of the parameters.

      Why would you possibly want to pass all that HTML tag junk into Ruby ?

      Pass just the data.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Error Drawing Lines

      @ppoublan said:

      Sorry but do not think this is the reason cause :

      • pt1/pt2 distance is 0.0010229217956422459 inches, so equal or above 0.001 inches

      It is not the distance between points, it is the position of the vertices in the model.
      Note that the model has Sketchup::Vertex objects, not Geom::Point3d objects.

      Geom::Point3d objects are only virtual helper objects.

      ` xd = 0.988135 - 0.98787
      0.0002649999999999597

      yd = 0.926013 - 0.925025
      0.0009879999999999889

      pt1.x == pt2.x
      true

      pt1.y == pt2.y
      true`

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: [New scripter] Will need help on my project (now and then)

      @ruts said:

      This raises a new question:
      If my project exists out of multiple scripts, with one main script that requires the other scripts. If I reload the main script, does it also reload the other scripts?

      You are asking basic Ruby questions that are covered in most Ruby books.

      You need to learn Ruby, before you can use an API that extends Ruby (like the SketchUp API.)

      At the very least read the files (except the "rake" files,) at the top of this page:
      http://ruby-doc.org/core-2.0.0/index.html

      You will save yourself hours of frustration if you read this book:
      [doc] Programming Ruby (The "Pick-Axe" Book)


      The answer is that your main loader file (in your plugin sub-folder,) uses require statements to load the other files that make up your extension.
      http://ruby-doc.org/core-2.0.0/Kernel.html#method-i-require

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: [New scripter] Will need help on my project (now and then)

      Ruby knows nothing about SketchUp directory hierarchy.

      All it knows is to check for scripts by prepending the paths that are in the $LOAD_PATH array. (Also aliased as $:)

      So the SketchUp "Plugins" path is in $:. Therefore you need to enter relative path:
      load "tr_VISIPLAN/tr_VISIPLAN.rb"

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Webdialog and ActiveXObject

      Use WebDialog.get_element_value() to retrieve the contents of the table cells, and store them in a nested array on the ruby side.

      So you will need to assign Js IDs to each table cell, perhaps "row#-col#", like id="3-4".

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Webdialog and ActiveXObject

      Do not use UI.messagebox for debugging. They can fail silently if the string is invalid.

      Use puts "test string" or puts object.inspect and read output in the Ruby Console.


      You cannot send such large data via the URL protocol.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: [Question] Switch of model and Interactive Plugins on Mac

      New for SketchUp 2015 is a callback in the AppObserver:
      onActivateModel
      It only applies to Mac.

      Commands, MenuItems and Toolbars, should always act upon the active model. Or more specifically, check the active model states when deciding what to return for their validation proc, status bar text and tooltips. (Use commands for both menus and toolbars, and it becomes easier.)

      Tools should always act upon the active model, and it is best if each model gets it's own tool instances, so there will not be any cross-contamination of data. More importantly, when a model is switched, the tool in the "from" model might be deactivated, or might not. It may be left in the same state, but don't count on it. Expect it to be suspended, so implement suspend() and resume() callbacks in your Tool class.

      Each model has it's own toolstack collection, therefore each model has it's own active tool object. These objects may not be instances of the same tool class, and even if they are, they might not be at the same step state. (One may have not done anything, another may have chosen the 1st point, still another the 2nd point, etc.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Webdialog and ActiveXObject

      ActiveX has been deprecated AFAIK. It has too many security issues. Some browsers even on PC refuse to load ActiveX objects.

      Besides the window object is not exposed in web browser control on PC.

      What are you trying to do ?

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: [New scripter] Will need help on my project (now and then)

      🤓

      Additional WIN32OLE Samples that were distributed with the Ruby 1.8.6 packages ...

      ... are posted in the Ruby Resources thread:

      WIN32OLE Sample Scripts

      💭

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: SketchUp-Ruby Resources

      WIN32OLE Sample scripts from the Ruby 1.8.6-p287 distribution:

      win32ole_samples.zip

      💭

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: [New scripter] Will need help on my project (now and then)

      @ruts said:

      Once the 3D environment is created the user needs to start the "translation" script. It will detect all the primitive shapes (which are groups) and what shape they are.

      You'll make the job easier if the user tags the groups either with Classifications (you create a custom XML schema for Visiplan Shapes,) or a simple AttributeDictionary that corresponds to the Access "Take" tables within Visiplan.

      @ruts said:

      Then it extracts the information it needs to translate it to the parameters the database needs. (TIG's export vertices to CSV seems interesting)

      As, visiplan is using Access 2000 MDB, you may be able to use the Ruby WIN32OLE class to write directly into database tables.

      There is an example of writing to an Excel spreadsheet, on the WIN32OLE class page.

      The machine using the extension would likely need MS Office Runtime libraries installed.
      Access 2007 Download: Access Runtime (Released before Windows 7.)

      There is also Access 2010 Runtime and Access 2013 Runtime libraries in both 32-bit and 64-bit, as well as service packs for them. (The links are too numerous to post here. Search the Microsoft website for the various downloads. Pay attention to the platforms supported.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: [New scripter] Will need help on my project (now and then)

      🤓

      In my opinion, the end use (of such an extension,) will be an obvious commercial use of the SketchUp software, that would require a SketchUp Pro license. But your development of the extension may not be.

      Review the SketchUp Software Terms and Conditions
      and pay close attention to clause 11(d).:
      @unknownuser said:

      11. DISCLAIMER OF WARRANTIES

      d) NONE OF THE SOFTWARE IS INTENDED FOR USE IN THE OPERATION OF NUCLEAR FACILITIES, LIFE SUPPORT SYSTEMS, EMERGENCY COMMUNICATIONS, AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL SYSTEMS, OR ANY OTHER SUCH ACTIVITIES IN WHICH CASE THE FAILURE OF THE SOFTWARE COULD LEAD TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE.

      Therefore the critical calculations should still be done within the VISIPLAN application.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • 1 / 1