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

    Topics

    • S

      Selection order

      Watching Ignoring Scheduled Pinned Locked Moved SketchUp Discussions sketchup
      3
      0 Votes
      3 Posts
      212 Views
      TIGT
      You cannot rely on the order of elements in a Selection. If you freeze it using es=selection.to_a then the order is frozen - but not much use. You can extract objects from a selection using grep, e.g. ... gs=selection.grep(Sketchup::Group) Gives you an array of all groups in the selection. You can make an array of their names [sorted] and then find their matching id - into an hash - which might then be in an order you want... But you haven't really explained why the selected-items' order is so important for you...
    • S

      Variable values in attribute dictionaries

      Watching Ignoring Scheduled Pinned Locked Moved Developers' Forum
      8
      0 Votes
      8 Posts
      812 Views
      Dan RathbunD
      @ssunderland said: ` n=0 i=0 Sketchup.active_model.selection[n].set_attribute("Bubble","id",i); n+=1; i+=1` You are missing some basic knowledge of Ruby. Most of the API collection classes have the library module Enumerable mixed into them. http://ruby-doc.org/core-2.0.0/Enumerable.html It is usually safer (to avoid fencepost errors, etc.) to use the built-in block form iterator methods. Sketchup.active_model.selection.each_with_index {|ent,idx| ent.set_attribute("SSU_Bubble","id",idx) } If you want to process in reverse order, make an array copy of the selection, using to_a and the Array#reverse method: Sketchup.active_model.selection.to_a.reverse.each_with_index {|ent,idx| ent.set_attribute("SSU_Bubble","id",idx) } However, there is one major rule. Do not delete collection members while iterating the collection. The loop will lose it's place, and strange results occur. In that case, always iterate an array copy of the collection, if your loop must remove or add collection members. This is most often seen while modifying Entities collections.
    • 1 / 1