⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update
  • Collision Code Optimization

    5
    0 評價
    5 貼文
    575 瀏覽
    Dan RathbunD
    @adamb said: Dan: Its the other [way] around surely. The add_line is superfluous and added just to confirm the lines are sane. He wants to test the performance of the raytest you commented out.. Okie.. dokie. I didn't understand what he was trying for (it was late.) That was why I just commented out the lines and did not remove them. The gist of what I meant was to init references (vars,) outside the loop, and limit creation of new ones inside the loop unless they are actaully necessary (ie, to be used in some way.) Ruby takes time to create references.
  • Call align view

    4
    0 評價
    4 貼文
    236 瀏覽
    TIGT
    @bluetale said: thx But I receive an error if the faces normal is parallel to Z_AXIS. I have added the following lines and it seems to work, but is it the correct solution? if !vector.parallel?(Z_AXIS) then > up = Z_AXIS > else > up = Y_AXIS > end It's a good trap! PS you don't need the 'then' and perhaps more 'simply' put if vector.parallel?(Z_AXIS) up = Y_AXIS else up = Z_AXIS end
  • Ruby access to styles.

    8
    0 評價
    8 貼文
    428 瀏覽
    thomthomT
    @dan rathbun said: @al hart said: We want to write a routine to take a 360 degree spherical panoramic HDRi image ... These HDRi images are spherical? or cylindrical? Environment maps can be in many shapes - even cubical. HDRI image aren't always environment images.
  • Execute_script trouble

    6
    0 評價
    6 貼文
    306 瀏覽
    thomthomT
    @kdasilva said: So do those escapes keep the quotations around the word so JS knows its a string and not some undeclared variable? Yes. The string you send to execute_script is processed by JS eval() in the webdialog. So remember that all strings you send to execute_script is processed and evaluated twice, once in Ruby and once in JS. Though, the code will be easier to re4ad and understand if you avoid escaping quotes. js_update_command = "UpDateVisionList('#{updated_visions_div}')"
  • [code] Split a long pathstring ~in half at the nearest '/'

    10
    0 評價
    10 貼文
    2k 瀏覽
    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 評價
    5 貼文
    717 瀏覽
    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 評價
    8 貼文
    1k 瀏覽
    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 評價
    4 貼文
    287 瀏覽
    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 評價
    20 貼文
    1k 瀏覽
    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 評價
    4 貼文
    285 瀏覽
    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 評價
    5 貼文
    635 瀏覽
    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 評價
    2 貼文
    190 瀏覽
    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 評價
    7 貼文
    342 瀏覽
    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 評價
    25 貼文
    2k 瀏覽
    M
    Mission accomplished Thanks to you all Geniuses
  • WebDialog.execute_script on OSX

    2
    0 評價
    2 貼文
    396 瀏覽
    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 評價
    9 貼文
    458 瀏覽
    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 評價
    3 貼文
    507 瀏覽
    thomthomT
    Cheers beans! Appreciate it.
  • [Code] Rantexpos

    9
    0 評價
    9 貼文
    3k 瀏覽
    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 評價
    13 貼文
    3k 瀏覽
    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 評價
    3 貼文
    206 瀏覽
    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...

Advertisement