sketchucation logo sketchucation
    • Login
    1. Home
    2. lbsswu
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 9
    • Posts 30
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: How to get the center of a ComponentDefinition array?

      @tig said:

      If you meant ComponentInstance then they each have bounds.
      Make a new empty bounding-box object [ bb], and then add each of the instance.bounds to that bb.add(instance.bounds).
      The center is bb.center.........

      Thanks for your tip. I will test the code.

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • RE: How to get the center of a ComponentDefinition array?

      @thomthom said:

      I don't understand the question. ComponentDefinitions doesn't exist in modelspace - so I do not see how you would get the centre of a collection of definitions.

      Can you describe the abstract of what you are trying to do?

      I'm sorry I made a mistake, the type is not ComponentDefinition, but a Group. I use the following code:
      model = Sketchup.active_model;
      groups = [];
      model.definitions.each{|d| groups << d if d.group? }
      name = "left_head"
      pgrp = [];
      groups.each{|d| pgrp << d.instances[0] if d.instances[0].name==name }
      the type of gprp is Sketchup::Group.

      Actually, I want to get the center of a group with the group name "left_head", but there are several groups with the name "left_head", so I have to find the union bounding box of them.

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • RE: How to get entities from selection?

      @thomthom said:

      You mean into an array? The Selection object is an Enumerable so you can iterate it as normal. It also have a .to_a method so it can often be mixed with arrays.

      How do you want to "get" the entities? Iterate them?

      I just want to inplement the following code:

      entities = selection.entities (this function is what I wanted, but not exist)
      group = entities.add_group
      group.add entities (this function is what I wanted, but not exist)
      bounds = group.bounds
      center = bounds.center

      Is there any way?

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • How to get the center of a ComponentDefinition array?

      I have an array of ComponentDefinition. I want to find the center of these ComponentDefinitions.

      Maybe I should find the union bounds of these ComponentDefinitions, but I did not find the way 😕 ... Could any one help me?

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • How to add an entity to entities?

      Is there a method to add an entity object to entities object? I searched the forum yesterday but did not find any way...

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • How to get entities from selection?

      I have a selection object with several entities, I am confused about how could I get all the entities from the selection object?

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • RE: How to import several models to designated positions

      @thomthom said:

      I had a look at model.import and found that it annoyingly didn't return the definition to the imported model. Instead it activates a tool for the user to place it.

      I created this little snippet that worked around that and placed the imported model at a given coordinate:

      <span class="syntaxdefault"><br />module Test<br /><br />  def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">import_3ds</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> file </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">'c;/cube.3ds'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> position </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> ORIGIN </span><span class="syntaxkeyword">)<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 />    </span><span class="syntaxcomment"># Cache camera position because model#import will change it.<br /></span><span class="syntaxdefault">    camera </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">camera<br />    eye </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> camera</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">eye<br />    target </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> camera</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">target<br />    up </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> camera</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">up<br />    </span><span class="syntaxcomment"># Begin import operation.<br /></span><span class="syntaxdefault">    model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start_operation</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxstring">'Import 3DS Model'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> false </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    </span><span class="syntaxcomment"># Cache existing list of definitions.<br /></span><span class="syntaxdefault">    cache </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definitions</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_a<br />    </span><span class="syntaxcomment"># Import model, this will attach it to the cursor.<br /></span><span class="syntaxdefault">    model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">import</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> file </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">select_tool</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> nil </span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Deactivate Place Model tool.<br /></span><span class="syntaxdefault">    </span><span class="syntaxcomment"># Find root definition because the import creates multiple definitions.<br /></span><span class="syntaxdefault">    </span><span class="syntaxcomment"># The sub-components are maked as #internal? - so we look for the one<br /></span><span class="syntaxdefault">    </span><span class="syntaxcomment"># without the mark.<br /></span><span class="syntaxdefault">    imported </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definitions</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_a </span><span class="syntaxkeyword">-</span><span class="syntaxdefault"> cache<br />    definition </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> imported</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">find </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">d</span><span class="syntaxkeyword">|</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">!</span><span class="syntaxdefault">d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">internal</span><span class="syntaxkeyword">?</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault">    </span><span class="syntaxcomment"># Place instance in current context.<br /></span><span class="syntaxdefault">    tr </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Transformation</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault"> position </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_instance</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> definition</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> tr </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    </span><span class="syntaxcomment"># Restore camera.<br /></span><span class="syntaxdefault">    camera</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">set</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> eye</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> target</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> up </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    </span><span class="syntaxcomment"># Finished! ;)<br /></span><span class="syntaxdefault">    model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">commit_operation<br />  rescue<br />    model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">abort_operation<br />    raise<br />  end<br /><br />end </span><span class="syntaxcomment"># module<br /></span><span class="syntaxdefault"> </span>
      

      I test the code, it works well. Thanks!

      But now I find a problem about the given coordinate which is designated by me. After importing the model, the position of the model may not be the one I designated. This is because of the file I want to import. Use the Bed.skp file as an example. Suppose I have two Bed models as these in the attachment, if I import them into sketchup with the same given coordinate, after importing, however, the positions of them are not same.

      I want to import model with its center at given coordinate in sketchup, no matter where the model is in the import file. Is there any way to implement it?


      first type of model I want to import


      second type of model I want to import

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • RE: How to import several models to designated positions

      @thomthom said:

      If the models are not SketchUp models, look at:

      Model.import
      https://developers.google.com/sketchup/docs/ourdoc/model#import

      My original models are .3ds. Thanks for your tip!

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • RE: How to import several models to designated positions

      @kwalkerman said:

      Take a look at entities.add_instance:

      https://developers.google.com/sketchup/docs/ourdoc/entities#add_instance

      and the DefinitionList, especially DefinitionList.load and DefinitionList.load_from_url:

      https://developers.google.com/sketchup/docs/ourdoc/definitionlist

      --
      Karen

      I got it. Thanks very much!

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • How to import several models to designated positions

      I want to import three car models to designated positions. These position are designated by 3D coordinates, e.g. [0,0,0], [0,200,0], [100,0,0]. I want to do this just by script, without mouse. Could any one help me?

      posted in Developers' Forum
      lbsswuL
      lbsswu
    • 1
    • 2
    • 2 / 2