⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update
  • Fixed container position in html web dialog

    3
    0 Votes
    3 Posts
    554 Views
    H
    Thank you very much, it's works fine.
  • Shortcuts 2 letters

    2
    0 Votes
    2 Posts
    446 Views
    J
    One was written back in 2008 named Event Relay. It received little attention and the author last visited SketchUcation in 2009. The code for is hosted here: https://code.google.com/p/eventrelay/wiki/EventRelay Maybe the code could be updated. If this were my goal and I was using Windows, I would try to create an Autohotkey script.
  • Linear Algebra & Analytic Geometry

    4
    0 Votes
    4 Posts
    663 Views
    M
    @bomastudio said: Hi Guys, I have an agony-problem with a 3D rotation. The transform that TIG suggested (rotation) works for your need. The docs on transformations aren’t very clear, especially for people who aren’t familiar with 3D transforms or linear algebra. They’re also a little quirky, as the trans.to_a method returns a matrix that is the transpose of what I would expect. FWIW, I had a lot of linear algebra (long time ago)... Anyway, the rotation method returns a transformation based on a rotation in a plane, which is defined by the ‘axis’ parameter, which should be the normal to the plane of rotation. If the start and end vectors are parallel, they do not define a unique plane, hence, both my original ‘linear algebra’ algorithm and the rotation method fail. The code below accounts for that – Greg module SUMath def self.transVector2Vector(vStart, vEnd, pt = nil) ptRot = pt || [0,0,0] if vStart.samedirection?(vEnd) # return identity transformation, vectors are in the same direction Geom;;Transformation.new elsif vStart.parallel?(vEnd) #return 180 transformation, vStart and vEnd in opposite direction Geom;;Transformation.axes(ptRot, [-1,0,0], [0,-1,0], [0,0,-1] ) else # return rotation transform based on vStart and vEnd # vCross is normal to plane of rotation vCross = vStart.cross(vEnd) ang = vStart.angle_between(vEnd) Geom;;Transformation.rotation(ptRot, vCross, ang) end end def self.rotateFace(face, vector_end, pt = nil) # for demo purposes, the next 2 statements chose an arbitrary face # if no face passed unless face entities = Sketchup.active_model.entities faces = entities.grep(Sketchup;;Face) face = faces[0] end face_normal = face.normal t = transVector2Vector(face_normal, vector_end, pt) entities.transform_entities(t, face) # below is just for a demo confirmation sd = face.normal.samedirection?(vector_end) sVEnd = "[#{vector_end.join(",")}]" puts "face.normal.samedirection?(#{sVEnd}) = #{sd}" end end # load module thru console # type SUMath.rotateFace(nil, [0,0,1]) into console with whatever vector # you want, it can be typed as often as you'd like. # As a demo, best done with one face in the model
  • [Code] wrapping operations

    5
    0 Votes
    5 Posts
    2k Views
    M
    One can also wrap Dan's code in a method def self.operation(opName, procElse = nil, procEnsure = nil) if (block_given? && String === opName) am = Sketchup.active_model begin am.start_operation(opName, true) yield am.commit_operation rescue => e am.abort_operation puts("Error operation block #<#{e.class.name};#{e.message}.>") puts(e.backtrace) if $VERBOSE else procElse.call() if (Proc === procElse) ensure procEnsure.call() if (Proc === procEnsure) end else raise "Error operation parameters - No block given or opName not a String!" end end # call by # operation("My operation") { operation block } Note that if either procElse and procEnsure are used, they should probably be lambdas. One should also be careful about return statements in the block passed to the method. BTW, I'll use snake case for methods, maybe not variables... Greg
  • Accessing File Locations defined in Preferences from Ruby

    8
    0 Votes
    8 Posts
    1k Views
    D
    I would use something like steve suggests... %x(defaults read ~/Library/Preferences/com.sketchup.SketchUp.20#{Sketchup.version.to_i} "SketchUp.DefaultFolder.Models") BUT, it always returns the last Folder used for a Save...
  • Web Dialogs: cancelling at onclose

    7
    0 Votes
    7 Posts
    655 Views
    fredo6F
    Anton, Thanks. It's a pity that there is no built-in mechanism (such as the return value of the callback defined in set_on_close). We can also understand that SU wants to preserve a way to close the web dialog 'whatever' in case of trouble. Anyway, reloading the HTML works fine. I just noticed that redoing just a show() create this delay in capturing mouse events. Fredo
  • A *new* plugin for scattering objects

    10
    0 Votes
    10 Posts
    2k Views
    M
    @unearthed said: I haven't tried this yet as I'm on the road but have been hoping poisson distribution would get scripted for SU. A while ago ago I posted this query http://sketchucation.com/forums/viewtopic.php?f=323%26amp;t=55779%26amp;hilit=+poisson . Did not see your post, distributing plants is certainly something I also thought of before! Not sure about Poisson Sampling with ruby, was thinking going the other way - a more performant solution using OpenCL or CUDA - because sampling is quite numerically intensive. @unearthed said: Currently when I want these (for 'random' planting layouts) I run them in R and export to dxf - Your method offers possibility of saving two steps and keeping everything 'in house'. One extra though - would you be able to add a ratio for each different component so as to get an effect as in the link's first image? Right, the percentage of the total samples for each component? I could certainly do this, perhaps I will make an update this weekend if there is time. As with regards to using different radii (for each sample/plant to have a different minimum radius), as also mentioned in your other post - I will see how quickly it can be done, perhaps if it takes more than a few hours (if done efficiently!) I'll think of releasing a commercial plugin. Greetings
  • Backgrounds in images in 3D warehouse

    4
    0 Votes
    4 Posts
    608 Views
    Dan RathbunD
    @al hart said: I "fixed" it be downloading the 3D Warehouse models, turning off the ground plane, setting the background color to white, and then re-uploading them. Well, you never said they were YOUR models. Of course you are responsible, if you left the ground plane turned on. LOL
  • Area class messing up .volume

    6
    0 Votes
    6 Posts
    626 Views
    Al HartA
    It turns out the the other developer had defined a override to Length which returned a value of class Area when 2 lengths were multiplied. We were multiplying the bounding box extrema to try to calculate an approximate volume if volume was not defined. if (entity.respond_to?(:volume)) rval = entity.volume else rval = bwidth * bdepth * bheight end#if They plan to fix it, but I think I can coerce each "length" to a float before multiplying them: if (entity.respond_to?(:volume)) rval = entity.volume else rval = bwidth.to_f * bdepthto_f * bheightto_f end#if Actually I will do this earlier when I get width from the bounding box
  • Edit group by ruby-code instead of a right mouse click

    16
    0 Votes
    16 Posts
    3k Views
    TIGT
    To set up a shortcut that is context-sensitive you must be in that selection-context. So to shortcut 'Edit Group' you first need to select a group to get that possibility in the context-menu and you must then open SketchUp's Preferences > Shortcuts and filter for 'Group'... - then set up the shortcut on that tool's command... then of course you'll need to mimic some key-presses etc in some third party code executed by Ruby - all as outlined earlier [PC only]... PS: This 'context' issue when making shortcuts applies to many selection-sensitive commands - like Reverse and Orient, which both need a face to be selected before they appear in the context-menu list...
  • Adding input parameter to simple code

    5
    0 Votes
    5 Posts
    674 Views
    TIGT
    Assuming you wrap all of your code in a method inside your own module... @x = 1.m unless @x @y = 1.m unless @y @z = 0.m unless @z results = inputbox(['X: ', 'Y: ', 'Z: '], [@x, @y, @z], 'Slicing Rectangle Dims') return nil unless results @x, @y, @z = results BUT then you need to decide the values for each point... If all of the slices are in plan then only the Z value is important. Can I suggest you use: bb = model.bounds min = bb.min max = bb.max then a single input for the Z thus: @z = 0.m unless @z results = inputbox(['Z: '], [@z], 'Slicing Height') return nil unless results @z = results[0] Extract the x/y/z values from min and max and make the points for the face from those... p1 = [min.x, min.y, @z] p2 = [max.x, min.y, @z] p3 = [max.x, max.y, @z] p4 = [min.x, max.y, @z] later entities_b.add_face(p1, p2, p3, p4) Note how whe adding a face you only need the points for each vertex, if you were adding edges you need to add the extra 'p5' to close the loop.
  • Code correction

    5
    0 Votes
    5 Posts
    880 Views
    H
    Thank you for giving me advices. The problem has been partly fixed by myself. Maybe, I have to pay attention to studying ruby more
  • SU2013 on tablet : right click ?

    4
    0 Votes
    4 Posts
    730 Views
    P
    yes ! ok with touchmousepointer ! thanks
  • Outliner selection not in Order

    11
    0 Votes
    11 Posts
    2k Views
    Dan RathbunD
    You do not need sorted = [], as grep makes a new array, then sort makes another new array. Save yourself some grief. Use puts or pp output to the console, rather than UI.messagebox, for testing. ( UI.messagebox can fail silently if the C WinAPI functions do not like the string passed to them.)
  • Error: Reference to deleted entities

    5
    0 Votes
    5 Posts
    2k Views
    Dan RathbunD
    @dubai_skyscraper said: The initialization in line 930 + 931 looks like this: def_screw_thread = def_list.add ("Screw thread") ent_screw_thread = def_screw_thread.entities I really thought that looked like a space, between the .add and the ("Screw thread"),... It could be a "vacuum" character though. P.S.are brackets, { } are braces, ( ) are parenthesis.
  • Removing duplicat Component Instances from an array

    5
    0 Votes
    5 Posts
    757 Views
    K
    Thanks for the help I just got to part of the program where this is needed. I visulized 6 to10 lines of code knowing that unique would work directly. Keith
  • Automatic Export Scenes to .dwg/.dxf

    8
    0 Votes
    8 Posts
    3k Views
    C
    I am an avid sketchup promoter and user and have follow and use many extensions created by the authors from this thread i am very interested in being able to export all scenes to layout, does anyone know how you can import all the scenes from your sketchup model into individual viewports in layout, i usually have to create over 50 individual pages and individually select each scene for each viewport, is there any way to do this automatically I would be very grateful to pick your brains let me know if you have anyway of accomplishing this, writing a macro, or anything Please let me know any thoughts you might have cheers!
  • Setting dynamic attributes to expressions?

    9
    0 Votes
    9 Posts
    5k Views
    Dan RathbunD
    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>
  • Webdialog and ActiveXObject

    11
    0 Votes
    11 Posts
    1k Views
    D
    Thread Highjack... @aerilius said: ...I have been working for some months on making the one I use in my plugins standalone and re-usable (soon released). shoot me a copy if you want any mac testing, i'm not too fond of SKUI, as I prefer a more the native look and feel... john
  • Error Drawing Lines

    8
    0 Votes
    8 Posts
    648 Views
    ppoublanP
    Better understand. Thanks slb for these explanation. I Cant use scaling in this case as the points are the result of crossing lines, so at any scale the resulting point of two lines crossing can be very close to any other point in the model. This gave me an idea for a very bad workaround. Do not like it, but it works. this way SU does not seem to try sharing same vertex... pt1 = Geom::Point3d.new(0.98787,0.926013,0) pt2 = Geom::Point3d.new(0.988135,0.925025,0) pt3 = Geom::Point3d.new(0.977696,0.924673,0) grp1 = Sketchup.active_model.entities.add_group grp1.entities.add_line(pt3,pt2) grp2 = Sketchup.active_model.entities.add_group grp2.entities.add_line(pt2,pt1) grp1.explode grp2.explode Thks again Pascal

Advertisement