sketchucation logo sketchucation
    • Login
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Transformation (copy) by vector and distance ?

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 3 Posters 456 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.
    • artmusicstudioA Offline
      artmusicstudio
      last edited by

      hi experts,
      i did not really find an answer in the api, so

      when i draw a 3d line (any direction) ,

      can i take it's vector and then transfom an object from its origin (= startpoint of my vector)
      ALONG this vector with a defined (@distance_z) distance ?

      instead of calculation the target 3d-point ? this would make placing object along a line much easier.

      thanx stan

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        If @drawn is an edge, then:

        from = @drawn.start.position move_vec = from.vector_to(@drawn.end.position)

        ๐Ÿ’ญ

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • artmusicstudioA Offline
          artmusicstudio
          last edited by

          hi dan,
          ok, this one moves any object along the vector , but for this i have again to calculate the start and end point of the edge first.

          the question is, when i already have a calulated and drawn line of any length,
          how can i move along this line (=vector) by defining a DISTANCE (in the 3d-direction of this line?

          so the endpoint would be calculated automatically by the ruby ?

          like:

          vector = edge xxx
          object = whatever
          distance = float-value
          object.move (vector, distance)

          stan

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

            startp = edge.line[0] ### edge.line is [start_point, vector_to_end_point]
            vector = edge.line[1]
            object = reference_to_a_group_or_instance
            distnc = a_length ### 1.234.m etc, remember that a float is always taken as 'inches'
            vector.length = distnc

            then

            object.move!(vector)

            or

            object.transform!(vector)

            ๐Ÿ˜•

            TIG

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              IF moving a Group:

              vector = edge.start.position.vector_to(edge.end.position)
              group = whatever
              distance = edge.length
              vector.length = distance
              group.move!(vector)
              

              P.S: use transform! instead of move!, if you want the operations on the undo stack.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                IF moving an primitive object:

                vector = edge.start.position.vector_to(edge.end.position)
                group = whatever
                distance = edge.length
                vector.length = distance
                object.parent.entities.transform_entities( vector, object )
                

                ๐Ÿ’ญ

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • artmusicstudioA Offline
                  artmusicstudio
                  last edited by

                  hi dan,
                  i came now back to this part of the ruby.
                  is it possible to COPY instead of MOVE somehow? i tried several things, but ther is no

                  group.copy!

                  obviously in the ruby syntax.

                  the trial of mine:

                  
                  #within a bigger loop  >>> FL
                  #.....
                  new_line1 = @entities2.add_line @rl1a, @rl2a # define line for vector
                  length = new_line1.length
                  #									
                  rasterarray_h = length.divmod(5.0/@faktor/@teiler_cm ) # gaps shall be near 5 cm
                  raster = length / rasterarray_h[0] # calculate gap between verticals ( == true length)
                  #							
                  @stab = @entities2.add_group
                  @stab.name = "stab_senkrecht"
                  entities_stab = @stab.entities   # the group to be copied along new_line1
                  
                  @rl1a = [(fl)*  const1+var2*var3  , (fl)*  const2+var4 , 0 + (fl)*(@pmod * @rise)+@railsgapunten]
                  @rl2a = [(fl)*  const1+var2*var3  , (fl)*  const2+var4 , 0 + (fl)*(@pmod * @rise) + var6+@railsgapunten]
                  #			
                  edge = entities_stab.add_line @rl1a, @rl2a # create 1st vertical in the group
                  #			
                  puts "#{__LINE__} ; edge created"
                  puts "#{__LINE__} ; raster ; #{raster}"
                  puts "#{__LINE__} ; length ; #{length}"
                  puts "#{__LINE__} ; rasterarray_h[0] ; #{rasterarray_h[0]}"
                  #			 
                  for v_line in 1..rasterarray_h[0] # copy group along new_line1 in distance raster
                  #puts v_line
                  vector = new_line1.start.position.vector_to(new_line1.end.position)
                  vector.length = v_line*raster # every step 1 raster more
                  #@stab.move!(vector)   # TRIAL 1 ???????
                  #@stab.parent.entities.transform_entities( vector, @stab )   # TRIAL 2 ???????
                  			
                  end  # v_line loop
                  
                  
                  

                  thanx for helping again. copying in 3d by distance would be a great step further......

                  stan

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

                    http://www.sketchup.com/intl/en/developer/docs/ourdoc/group.php#copy ๐Ÿ˜’

                    group2 = group.copy

                    This makes a copy of the group exactly on the top of original group, AND in the same context as the original group***.
                    You can then transform that copy.

                    group2.transform!(some_transformation)

                    Be aware that this group2 copy is a 'second instance' of the original group, so any changes you make to one will appear in the other [just like with a component] - you can use group2.make_unique to resolve this; it will generate a warning about deprecated methods BUT this is a known error in the API code and should be removed one day when the API is upgraded...

                    Also be aware that group.copyt can fall foul of some entities-observers from other tools, and cause them to splat - it's a known bug in the API and should get fixed one day...

                    ***Another way to add a 'copy' of a group, BUT put it into another context uses this:

                    group2 = another_entities.add_instance(group.entities.parent, group.transformation)

                    Then transform the group2 as desired...
                    You can of course apply the new group's transformation as you add its instance...
                    Here's an example including the make_unique...

                    group2 = another_entities.add_instance(group.entities.parent, another_transformation) group2.make_unique

                    To do it in the same context use:

                    group2 = group.parent.entities.add_instance(group.entities.parent, another_transformation) group2.make_unique

                    ๐Ÿค“

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • artmusicstudioA Offline
                      artmusicstudio
                      last edited by

                      hi tig,
                      thanx so much, but this one really makes me crazy.....

                      what ever i do , the move! - instructions MOVES but does not copy, it's magical...( i tried all your codes, the code from the api....)

                      my code so far ( i am on the level of @entities2 (coming from a method above this one)

                      
                      new_line1 = @entities2.add_line @rl1a, @rl2a # define line for vector
                      length = new_line1.length
                      #									
                      rasterarray_h = length.divmod(5.0/@faktor/@teiler_cm )
                      raster = length / rasterarray_h[0] # calculate gap between verticals ( == true length)
                      #
                      # so the raster is the 3d-distance on the vector from new_line1
                      #
                      group = @entities2.add_group
                      entities_stab = group.entities
                      @rl1a = [(fl)*  const1+var2*var3  , (fl)*  const2+var4 , 0 + (fl)*(@pmod * @rise)+@railsgapunten]
                      @rl2a = [(fl)*  const1+var2*var3  , (fl)*  const2+var4 , 0 + (fl)*(@pmod * @rise) + var6+@railsgapunten]
                      #
                      edge = entities_stab.add_line @rl1a, @rl2a # create 1st vertical
                      #			
                      #entities = @entities2 # tried this, too..
                      #			
                      for v_line in 1..rasterarray_h[0]
                      #			
                          vector = new_line1.start.position.vector_to(new_line1.end.position)
                          distance = v_line*raster
                          vector.length = v_line*raster/2
                      #
                          group2 = group.copy
                          group2 = group.move!(vector)  
                      # and the line is moved, not copied....or the original group disappears? there shold be lots of vertical lines in distance of "raster".....
                      #			
                      end
                      #
                      
                      

                      grrrrhhh....
                      i make a break now, the brain is just about to explode.......๐Ÿ˜„

                      stan

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

                        ๐Ÿ˜ฎ
                        group2 = group.copy group2 = group.move!(vector) ๐Ÿ˜’

                        group2 = group.copy group2.move!(vector)

                        Should leave group where it was ???

                        TIG

                        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