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

    Place a shape at regular intervals between two lines

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 330 Views 2 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.
    • N Offline
      Nckb
      last edited by

      Hi all,
      I am new in ruby for sketchup, I do it as hobby...
      I am trying to understand how to use location, and shape distribution with ruby.
      And to do this, my test is to place one rectangular shape between two lines and paste it until the end of sinusoidal lines with regular intervals.

      Can you help me about this? Just to know which function I must to use, how to select my rectangular shape, and give it the destinations' lines to be paste and distribute?

      Thanks by advance !

      Nckb

      PS : I hope that I use correct english to explain you my problem 😉
      PPS : If you want pictures, I can upload it...

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

        An image or two would help.
        Rather than make separate rectangles each time I suggest you make a rectangle-component - manually beforehand, or in your code.
        Then you can add instances of that component [into a new enclosing group.entities context], iterating through an array of points for the location of each rectangle that is needed...
        Making the list of points is less clear... - if the 'curve' needs a rectangle at each node then you can get them from the edges forming the curve; otherwise you somehow need to decide the points interpolated along the curve...
        If you way to rotate the rectangles in some way, then you need to get a matching array of points in the second curve and work out the angle that one if from its matching entry in the array.
        Then as well as applying a transformation for the insertion-point you also apply a second transformation.rotation about that point and say the Z_AXIS, at that angle so each rectangle is rotated.
        Once you have all of the components placed you can explode them - if you want all of this geometry in one context...

        TIG

        1 Reply Last reply Reply Quote 0
        • N Offline
          Nckb
          last edited by

          Thank you for these first informations !
          I must do it step by step I see
          :

          1. Get group entity
          2. Insert instance
          3. Apply transformation
          4. ??

          This picture show that I have first : (Two lines => the path, and a shape (group) to copy on the path)
          2015-07-06_15h11_20.png

          And here the result :
          2015-07-06_15h15_17.png

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

            Read up:
            http://www.sketchup.com/intl/en/developer/docs/classes.php

            When you add an instance you apply an initial transformation, but you can do more transforming later...
            A group is a special kind of component.
            For now let's assume a component existe.
            So let's assume you have a component-definition containing your 'box' with a reference to it called ' compodef'.
            Let's assume the references:
            model = Sketchup_active_model ents = model.active_entities

            Let's also deal with just one curve, for now...
            Let's assume you have a reference to just one of the edges that form it, called ' edge'.
            Let's also assume you'll place instances at its nodes - i.e. the edges' 'end' points.
            curve = edge.curve vertices = curve.vertices points = [] vertices.each{|v| points << v.position }

            now you have an array of the points defining the curve.

            points.each{|point| tran = Geom::Transformation.new(point) instance = ents.add_instance{ compodef, tran } }

            now you have an instance of the component 'box' located at every node point of the curve...

            This is a simplified explanation...
            At least should get you started...
            If you want to 'swivel' each box to span between the nodes in one curve and the equivalent node in a second curve, then you need to assemble two arrays of points - says points1 and points2
            You iterate thus:
            ` points1.each_with_index{|point1, i|
            tranp = Geom::Transformation.new(point1)
            instance = ents.add_instance{ compodef, tranp }
            length = instance.bounds.length

            now get the second point

            point2 = points2[i]
            dist = point1.distance(point2)

            scale the box

            scalex = dist / length
            trans = Geom::Transformation.scaling(point1, scalex, 1.0, 1.0)
            instance.transform!(trans)

            rotate the box

            vec = point1.vector_to(point2)
            angle = X_AXIS.angle_between(vec)
            axis = X_AXIS.cross(vec) ### might be reversed - check ?
            trana = Geom::Transformation.rotation(point1, axis, angle)
            instance.transform!(trana)
            }`
            this is untested but should give you some ideas...
            It places the instance scales it so it'll stretch between the two points and the rotates the box so it spans between the two points.
            Obviously you need to do more work - like making the box component, checking the curve points for 'direction' and count-match etc...

            Good luck...

            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