ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
  • [code] Split a long pathstring ~in half at the nearest '/'

    10
    0 Votes
    10 Posts
    2k Views
    Dan RathbunD
    Ok here's my current version: <span class="syntaxdefault">def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">path_knife</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">path</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">max</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">60</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  </span><span class="syntaxcomment"># make sure it's a Ruby path using '/'.<br /></span><span class="syntaxdefault">  path </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">expand_path</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">path</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  if path</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length </span><span class="syntaxkeyword">></span><span class="syntaxdefault"> max<br />    </span><span class="syntaxcomment"># cut the file path into 2 lines<br /></span><span class="syntaxdefault">    ok </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">((</span><span class="syntaxdefault">path</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">)*</span><span class="syntaxdefault">0.45</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">to_i<br />    cut </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> path</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxcomment">//).each_with_index { |e,i|<br /></span><span class="syntaxdefault">      break i if</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> e</span><span class="syntaxkeyword">==</span><span class="syntaxstring">'/'</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&&</span><span class="syntaxdefault"> i</span><span class="syntaxkeyword">>=</span><span class="syntaxdefault">ok </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault">    cut </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> 0 unless cut</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_a</span><span class="syntaxkeyword">?(Integer)<br /></span><span class="syntaxdefault">    return </span><span class="syntaxstring">"  #{path[0..cut]}   \n  #{path[(cut+1)..-1]}   "</span><span class="syntaxdefault"> if cut</span><span class="syntaxkeyword">></span><span class="syntaxdefault">0<br />  end<br />  </span><span class="syntaxcomment"># otherwise, leave it as one line<br /></span><span class="syntaxdefault">  return </span><span class="syntaxstring">"  #{path}   "<br /></span><span class="syntaxdefault">  </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault">end </span><span class="syntaxcomment"># def<br /></span><span class="syntaxdefault"> </span> **EDIT: Added test after iterator, to set cut to 0, if a string had no '/' characters (in which case each_with_index just returns the array characters.) Also removed frivolous line before iterator: cut = 0 EDIT 2:(2011-02-19) Simplified path substring references (line 11.) Removed frivolous else clause (were lines 12 and 13.)**
  • Webdialog Question on .show

    5
    0 Votes
    5 Posts
    660 Views
    Dan RathbunD
    Make sure to read WebDialogs - The Lost Manual (by ThomThom) The webdialog is an instance of your custom WebDialog class. When you .close() the window, the instance object still exists, and when you .show() it your only opening up the window again. On PC you can use the block argument to do something in the javascript. (It is bugged on the Mac.) <span class="syntaxdefault">webwin</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">show </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault">  webwin</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">execute_script</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"window.location='startpage.html';"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> <br /></span><span class="syntaxkeyword">}</span><span class="syntaxdefault"> </span>
  • Edges, angles on rectangle triangle

    8
    0 Votes
    8 Posts
    950 Views
    C
    Angles are only defined between two vectors, so finding the angle between a vector and a plane can vary depending on which vector in the plane you're interested in. Most of the time, the vector you're interested in is the angle between the vector and it's projection into the plane which can be calculated using the face.plane method and the Array.project_to_plane method. The only trick here is that vectors are not points, so you would have to either pick a point in the plane, then transform it by your vector or translating the plane to the origin and simply calling the vector3d.to_a method. As it turns out, the second method is much simpler since given a plane of of the form [x,y,z,c] then translating it to the origin is as easy as changing it to [x,y,z,0]. Here is the code def angle_between_vector_and_projection(vector,face) plane = face.plane plane[3] = 0 projection = Geom;;Vector3d.new(vector.to_a.project_to_plane(plane)) return vector.angle_between(projection) end
  • Commit working like undo command

    4
    0 Votes
    4 Posts
    246 Views
    thomthomT
    Note that start_operation cannot be nested. Doing a new start_operation after another will commit the first.
  • Get mouse x,y,z location other an with an Inputpoint?

    20
    0 Votes
    20 Posts
    1k Views
    Dan RathbunD
    @chris fullmer said: Well there you have it! Glad you can test if they have Hide Rest of Model on or off. Just be aware that Scene (Pages) can also have their own RendingOptions hash instance.
  • Few Quick Question for Tool

    4
    0 Votes
    4 Posts
    235 Views
    Dan RathbunD
    @kdasilva said: 2) ... How would you recommend saving the variables that keep track of the various inputs my users put in if they want to re-open Sketchup. If the variables are specific to a certain model.. then attributes attached to the model. If they are general to a plugin and will be used with more than one model, then look at Sketchup.read_default and Sketchup.write_default methods. (It's best to convert all data to strings that will be written into the Windows Registry.) Or you can use a Settings Hash convert it to a string with .inspect() and write it out to a file. An easy way is to use Marshal.dump() and Marshal.load() (but there are versioning issues.) It's not that hard to open a File object and use it's write() or puts() method to send the string to the file. That way you won't have marshaling version isssues, and as you need to open the file IO object in both cases, it's not much difference, either way. @kdasilva said: I can store variable information with attributes for entities...but if i wanted to say have arrays that hold different community visions for the model, I don't think I can assign attributes to the model can I? Any Entity subclass inherits the attribute methods. And also they are defined for Sketchup::Model class. So for instance you can attach attributes to a Layer or a (Scene) Page because they are Entity subclasses (not just to the Drawingelement subclasses.)
  • Replace components

    5
    0 Votes
    5 Posts
    581 Views
    liquid98L
    Hi Tig, Thanks I'll do some more study until I get what you suggested and come back here
  • How to identify buildings in Sketchup using ruby?

    2
    0 Votes
    2 Posts
    162 Views
    TIGT
    If you make them components you can find them by name, or attributes you might attached to the definition or instances etc... Using >=6 connected faces [as a 'solid'] could return almost anything from a box of paper-clips, through a TV set or Bed to a 20 storey office building ? Please be a bit more explicit with what is is you are trying to do...
  • Note to self: Array.to_a returns self

    7
    0 Votes
    7 Posts
    274 Views
    AdamBA
    @dan rathbun said: @tig said: a1=[1,2,3] both a2=a1 ### makes a new reference to the same array, 'a1' a2=a1.to_a ### makes 'a1' into an array [which it is already!] and then makes a new reference to the same array, 'a1' !! will still refer to a1, so consequently changing a2 changes a1 too ! BUT a2=a1.dup makes a separate copy of a1, as will a2=a1+[] as adding two arrays together produces a new array, even when the second one is empty; and now changing a2 leaves a1 alone To clarify, since "assignment creates references"...: a1=[1,2,3] ### creates a new array object referenced by a1 a2=a1 ### makes a new reference ( a2) to the same array object that a1 is pointing at. a2=a1.to_a ### a1.to_a returns *self* both references are pointing at the same array object, so consequently that object can be changed using either reference a2 or a1. BUT a2=a1.dup ### makes a new array object, (referenced by a2,) that is a copy of the array object that a1 is pointing at. Nice round-up.. But be aware #dup performs a shallow copy. So any proper objects (as opposed to simple numbers) in that array are copied by reference. So: a = [10, 20, [30,31,32]] c = a.dup a[2][0] = 'Tada!' c will print: [10, 20, ["Tada!", 31, 32]]
  • How to draw an edge with an angle and distance

    25
    0 Votes
    25 Posts
    1k Views
    M
    Mission accomplished Thanks to you all Geniuses
  • WebDialog.execute_script on OSX

    2
    0 Votes
    2 Posts
    367 Views
    thomthomT
    I use the jQuery .ready() event that loads when the DOM is ready to make a callback back to Ruby. Then I can 100% sure I can use execute_script. Works on both platforms. No need for sleep or timers. I've made a few notes about WebDialogs: http://forums.sketchucation.com/viewtopic.php?f=180&t=23445
  • I saw plugin for selecting objects with material

    9
    0 Votes
    9 Posts
    371 Views
    K
    @didier bur said: Besides all this, isn't it a built-in function ? This only captures elements in the currently active entities collection. My plugin also searches for that material in any sub-components or groups. EDIT: It also doesn't work on the default material. Karen
  • [Info] Transformation Matrix Link

    3
    0 Votes
    3 Posts
    474 Views
    thomthomT
    Cheers beans! Appreciate it.
  • [Code] Rantexpos

    9
    0 Votes
    9 Posts
    2k Views
    G
    figured it out. i just need to rotate my face/object to be oriented with the axis. then i can hit rantexpos and it aligns them in the other way. thanks again for your help. mo
  • [Code] New Material methods

    13
    0 Votes
    13 Posts
    3k Views
    TIGT
    Here's an update http://forums.sketchucation.com/viewtopic.php?p=293701#p293701 The MAC jar execution issues have been addressed.
  • How to set length units in code

    3
    0 Votes
    3 Posts
    172 Views
    TIGT
    If you are getting the x/y/z values as strings [perhaps from an imported text file] then ` z=z+'.m' 4.5.m ### as a string eval(z) 177.165354330709 ### in inches [SUp's base units and used to position the point]if they are as floats then z=z.m` will work to convert it...
  • [Code]Transformation_Extensions 20110209

    3
    0 Votes
    3 Posts
    2k Views
    TIGT
    I've updated this code as it was well out of date and new versions drifting around on the forums has typos etc - this is the definitive version [as of today at least ]
  • [code] intersect_with example

    6
    0 Votes
    6 Posts
    5k Views
    TIGT
    I suggest you trap for non-groups selection.each { |entity| ### next if not entity.class==Sketchup;;Group ### entity.entities.intersect_with(true, entity.transformation, entity.entities.parent, entity.transformation, true, entity.parent.entities.to_a) } Also shouldn't entity.entities.parent be entity.entities.parent.entities
  • Get Group Owner

    6
    0 Votes
    6 Posts
    332 Views
    thomthomT
    @cleverbeans said: I believe g3.parent.instances[0] gives you the correct group. Not if the group has instances, which it may have after copying a group and not editing it.
  • Google toolbar: get position

    4
    0 Votes
    4 Posts
    288 Views
    Dan RathbunD
    No.. you cannot intercept the call. It is hard-coded into the Sketchup application on the C++ side, not on the Ruby side.

Advertisement