ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
  • Retrieve the size of bounding box of selection

    23
    0 Votes
    23 Posts
    3k Views
    M
    Nice all this but, i am new in ruby, how can i retrieve the size of all component... including sub-component? ` mod = Sketchup.active_model # Open model ent = mod.active_entities # All entities in model message = "" ent.each { |e| n = e.name scale_x = ((Geom::Vector3d.new 1,0,0).transform! e.transformation).length scale_y = ((Geom::Vector3d.new 0,1,0).transform! e.transformation).length scale_z = ((Geom::Vector3d.new 0,0,1).transform! e.transformation).length bb = nil if e.is_a? Sketchup::Group bb = Geom::BoundingBox.new e.entities.each {|en| bb.add(en.bounds) } elsif e.is_a? Sketchup::ComponentInstance bb = e.definition.bounds end if bb dims = [ width = bb.depth * scale_x, height = bb.width * scale_y, depth = bb.height * scale_z ] message = message + "Cabinet: " + n + "\nHeight: #{dims[0].to_l}\tWidth: #{dims[1].to_l}\tDepth: #{dims[2].to_l}" end } UI.messagebox(message, MB_MULTILINE)` I would like to have dimensions of all pieces of the cabinet. I know Cutlist. But i only need name of piece and dimensions. And Cutlist script is to complicated for me. Someone can help me with this? PLZ
  • Round corners and CSS3

    15
    0 Votes
    15 Posts
    2k Views
    L
    More about CSS round corners....http://www.corelangs.com/css/box/round.html lynda
  • Selection !

    2
    0 Votes
    2 Posts
    241 Views
    A
    The simplest way is to allow the user to select any entities. Just care only about those selected entities that are edges: edges = Sketchup.active_model.selection.grep(Sketchup::Edge) Let's say you now need to be sure there is a minimum of edges: return UI.messagebox("You need to select two or more edges.") if edges.length < 2 The cleanest way would be to implement your own tool class for selecting entities. You would use a PickHelper to get whatever is below the point that the user clicked, and only if it is an edge you would add it to an array or selection (actually you do not really need to add it to the real selection), and then draw/highlight what is selected. Don't do this until you have enough experience. If something does not work, please give complete (and minimal!) examples and say what does not work. All I could say about Sketchup.active_model.selection.each is that it raises an error because it is an iterator method with missing block ("each" is not "edge").
  • Observer interface (best practices?)

    9
    0 Votes
    9 Posts
    1k Views
    A
    Hmm, thats a good example. Now, I won't have to use variables to tranfer data between two different class instances. Simply having 'em all in one class is good implementation. This is how I think Sketchup Observers work. <span class="syntaxdefault"><br />class Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Selection<br /><br />  def initialize<br />    </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">observers </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[]<br /></span><span class="syntaxdefault">  end<br /><br />  def add_observer</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">obj</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">observers </span><span class="syntaxkeyword"><<</span><span class="syntaxdefault"> obj<br />    true<br />  end<br /><br />  def remove_observer</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">obj</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">observers</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">delete</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">obj</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">?</span><span class="syntaxdefault"> true </span><span class="syntaxkeyword">;</span><span class="syntaxdefault"> false<br />  end<br /><br />  </span><span class="syntaxcomment"># Some method triggered by SketchUp private API.<br /></span><span class="syntaxdefault">  def _trigger_selection_added</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">sel</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> element</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">observers</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">obj</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault">      next unless obj</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">respond_to</span><span class="syntaxkeyword">?(;</span><span class="syntaxdefault">onSelectionAdded</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">      begin<br />        </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">obj</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">onSelectionAdded</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">sel</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> element</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">      rescue Exception </span><span class="syntaxkeyword">=></span><span class="syntaxdefault"> e<br />        puts </span><span class="syntaxstring">"#{e}\n#{e.backtrace.first}"<br /></span><span class="syntaxdefault">      end<br />    </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault">  end<br /><br />  </span><span class="syntaxcomment"># ...<br /></span><span class="syntaxdefault">end<br /></span> I think the event is called only if the tool contains that method. This might tell us that you tool isn't event supposed to be an instance. It may be a module as well. As long as the methods are accessible ( self.onSelectionAdded) your good to go.
  • A small &quot;entity to group&quot; problem

    4
    0 Votes
    4 Posts
    318 Views
    Dan RathbunD
    @artmusicstudio said: ..., is there a code for deliting an array of edges directly ? or do i have to iterate thru the array and erase one after another? use Entities.erase_entities() The argument can be a single entity, or an array of entities. ALSO... Ruby has an "accordian operator" the * that can be used to expand an array into a argument list, or compress arguments in an array. IF erase_entities also takes a list of multiple entities, you could convert the aray to a list like: my_ents.erase_entities( *my_edge_array )
  • Basic understanding of instances ???

    6
    0 Votes
    6 Posts
    595 Views
    tt_suT
    A couple of years ago I wrote an overview of definitions and instances in SketchUp: http://www.thomthom.net/thoughts/2012/02/definitions-and-instances-in-sketchup/
  • [plugin] xml parser

    2
    0 Votes
    2 Posts
    269 Views
    Dan RathbunD
    Export / Import DAE files are XML. You can select what you wish to save, and call: model.export( "some/path/filename.dae", optshash ) Create the options hash first with :selectionset_only => true Then import them using model.import
  • C API unresolved external symbol

    3
    0 Votes
    3 Posts
    705 Views
    G
    Thank you AdamB. I did add the path of the downloaded .dll and .lib to the VS library search path. Somewhere I read that character encoding differences could cause such error messages. So I also tried to change the project's encoding settings without any luck.... EDIT: Thank you. SUCCESS!!! (Well it was a missing reference to the lib... )
  • Drawing images to the SketchUp viewport

    9
    0 Votes
    9 Posts
    783 Views
    tt_suT
    And this is how it looks like on nVidia with AA enabled: [image: MGOD_2014-07-02_23h02_32.png] [image: hDJx_2014-07-02_23h04_12.png] [image: VzoD_2014-07-02_23h04_33.png]
  • Encode in 2014 again.

    12
    0 Votes
    12 Posts
    682 Views
    Q
    Thanks for all. The problem is done. The solution is to use ultraedit convert function(convert ascii to utf-8(unicode edition)). Originally, i use the notepad++ to convert utf-8 without BOM, and it seems not work as expected. Now, the split function can work correctly without any force_encoding, but the input from html should be converted using force_encoding("UTF-8"). Thanks again for TIG.
  • Array.uniq! for a 3d-point array ???

    6
    0 Votes
    6 Posts
    1k Views
    Dan RathbunD
    @aerilius said: Geom::Point3d.== method checks for example if all coordinates (x, y, z) are equal, and then says two points are equal. uniq appears to check for identity and not for equality. In Ruby 2.x (SketchUp 2014+,) where we now have a block form of the uniq method, that we can tailor to override C internals of the uniq! method, and tell it what and how to do the comparison. Ex: pts = roof.uniq {|a,b| a.==(b) } or: pts = roof.uniq {|pt| pt.to_a } In the future, perhaps, custom uniq methods could be added to a new PointArray subclass of Array., for the API. Of course any author could create such a custom class within their own namespace(s). ALSO.. the many od the API classes should have had their eql?() method aliased as the overridden ==() method. The uniq methods want to call eql?() instead of ==().
  • [solved] &quot;movin&quot; group into another group (in ruby)

    7
    0 Votes
    7 Posts
    517 Views
    artmusicstudioA
    hi, thanx! work like a dream, as soon as i found out, that a ng - group must be created before calling the method, then it moves both groups into it. fantastic! THANK YOU !!!!! stan result: g0 = @group_floors #COMES FROM ANOTHER METHOD g1 = @facade_group #COMES FROM ANOTHER METHOD ng = model.entities.add_group self.insert(ng, g0, g1) ##*************************************************************************** def self.insert(ng, g0, g1) ##*************************************************************************** ng.entities.add_instance(g0.entities.parent, g0.transformation) ng.entities.add_instance(g1.entities.parent, g1.transformation) g0.erase! g1.erase! #ng.name = "master house group created" count = 1 entities3 = ng.entities entities3.each { |entity| if entity.is_a?(Sketchup;;Group) entity.explode if count == 1 #SO GROUPS ELEMENTS ARE AGAIN AT LEVEL 1, as needed count = count + 1 end } end
  • [solved] submenue in a submenue ??

    4
    0 Votes
    4 Posts
    358 Views
    artmusicstudioA
    got it! thanx, works perfectly... stan
  • [solved] a simple UI.inputbox problem

    3
    0 Votes
    3 Posts
    354 Views
    artmusicstudioA
    hi tig, understood and done, works perfect, the combi-version is very nice and confortable and i can pass arguments to it from any method. you will then see it in the finished ruby! thanx a lot for the explanation. stan
  • Retrieve a value from status bar input box

    5
    0 Votes
    5 Posts
    351 Views
    TIGT
    You have to make a 'class'. SketchUp recognizes it as a 'Tool' from the way it is made into a command... Special 'Tool' methods can be used in that class... Go to the Extension-Warehouse and find the Examples - the 'draw box' example shows how to set up a Tool... https://extensions.sketchup.com/en/content/example-ruby-scripts
  • Modifying TIG's Archiver

    3
    0 Votes
    3 Posts
    230 Views
    M
    @tig said: ...an older version... BLAST! Thanks TIG. Started a while ago and completely forgot about the updates. Starting over LOL
  • How to get real position of vertex

    2
    0 Votes
    2 Posts
    329 Views
    TIGT
    Get the "container[s]" of the entities, get their "transformation[s]", then transform the vertex's point to match. Then you'll have the point in the model coordinate system, not the point in the container's coordinates system... This will give you the path through the nesting: http://www.sketchup.com/intl/en/developer/docs/ourdoc/model#active_path See these methods to get the 'accumulated' transformations of each container: http://www.sketchup.com/intl/en/developer/docs/ourdoc/transformation
  • Delete a mesh square diagonal edge (hidden) ?

    3
    0 Votes
    3 Posts
    247 Views
    artmusicstudioA
    hi tt_su, super, soft & smooth helps to identify. it works. the selected field of mesh is tranfered to a single face (i work with selection). thanx stan
  • Active_view.camera.get_center2d &amp; .get_scale2d

    3
    0 Votes
    3 Posts
    243 Views
    T
    get_center2d() and get_scale2d() C++ SDK functions return a camera shift and zoom-in factor for 2p perspective camera. You reply gave me idea, that maybe I could calculate the shift/zoom using InputPoint.position... This may work.
  • Moving a compo-instance by z

    2
    0 Votes
    2 Posts
    223 Views
    TIGT
    You have a component definition [ defn]. You have an instance of it [ inst1]. That instance has a transformation [ tr1=inst1.transformation]. That transformation has an origin [ org=tr1.origin] - i.e. its 'insertion point'. You make a new transformation based on that: tr2=Geom::Transformation.new([org.x, org.y, org.z+z_increment]) Where the ' z_increment' is the amount by which you want to move the copy upwards - either in inches or a Length. You add the copy thus: inst2=inst1.add_instance(defn, tr2)

Advertisement