sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [help]Group component instances

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 193 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      sm4rt
      last edited by

      Hi,

      I'm beginner in SketchUp Ruby coding and in fact I've never code into Ruby... (only C++ PHP JavaScript skills)

      Well I load and place some components using a "for" loop

        for i in 1..numberP
          point = Geom;;Point3d.new x0,y0,z0
          transform = Geom;;Transformation.new point
          model = Sketchup.active_model
          entities = model.active_entities
          path = Sketchup.find_support_file "mymodel.skp" ,"Components/"
          definitions = model.definitions
          componentdefinition = definitions.load path
          instance = entities.add_instance componentdefinition, transform
          # Calculate next panel corner for next loop.
          numinraw = num % numbyraw
          if (numinraw==0)
            x0 = abscisseRaw * rawNum
            y0 = ordonneeRaw * rawNum
            rawNum += 1
          else
            x0 = x0 + abscisse
            y0 = y0 + ordonnee
          end
          num += 1
      end
      
      

      And after that I want to group theses componentdefinition in order to apply them some other transformation...

      I imagine placing a line like "group = model.active_entities.add_group" just after the instance declaration or selecting all instances after the loop...

      But it does not work certainly due to the group declaration and the way I want to add components inside after

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        Before the loop set up an empty array

        instances=[]
        

        Within the loop after you've set instance push it into instances

        instances << instance
        

        After the loop

        group=model.active_entities.add_group(instances)
        

        Note: you could define entities outside of the loop and then reuse it - stuff you define in a loop is not accessible outside of it...
        🤓

        TIG

        1 Reply Last reply Reply Quote 0
        • S Offline
          sm4rt
          last edited by

          oh nice! thank you for it and for your note... (really need to study ruby first I think)

          I've just to transform it now with two rotations but only the last one work in fact. if you got a lil tip for it... I'll calculate the resulting vector and angle of the two transform I need that's pretty strange...

          1 Reply Last reply Reply Quote 0
          • M Offline
            MartinRinehart
            last edited by

            In addition to TIG's info, you should move all the one-time code outside the loop.

            
            model = Sketchup.active_model
            entities = model.active_entities
            path = Sketchup.find_support_file "mymodel.skp" ,"Components/"
            . . .
            
            

            I also heartily recommend that you use four-space indentation in spite of the fact that two spaces is a Ruby convention. Four is much more readable which is why it is mandatory in Python, convention in C++, Java, JavaScript, ... (every language I know, except Ruby).

            New languages are always a PITA. Fortunately, quite a small subset of Ruby is all you really need to create SketchUp plugins.

            Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement