• Login
sketchucation logo sketchucation
  • Login
πŸ”Œ Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

Plugin for changing radius of multiple circles

Scheduled Pinned Locked Moved Developers' Forum
8 Posts 3 Posters 554 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.
  • C Offline
    crazystick
    last edited by 21 Aug 2014, 15:25

    I've been looking for a plugin to change the radius of multiple circles but I didn't find one, so I had the idea to write one myself. I want to replicate the functionality of editing the radius in the Entity Info box, as I have a lot of holes which are pushed into / through another object, so they form empty cylinders.

    My basic idea was:

    1. select a circle
    2. get the center and normal
    3. make a new (bigger or smaller) circle and grab the points of the vertices
    4. delete the new circle
    5. move the vertices of the original circle to the new points

    My problem is that when you create a circle and push it through another one, the two circles are not directly above each other - they are offset by 2 arcs. If you do the same through the API they don't twist, and so moving the vertices twists the face of the cylinder which breaks it. Here's the code and the model. Before.skp

    ` model = Sketchup.active_model

    !!!manually select the top circle (sorry, has to be run in the console atm)

    cur_c = model.selection[0].curve
    cur_p = []

    grab the positions of each vertex

    cur_c.vertices.each { | v | cur_p << v.position }

    !!!manually select the bottom circle

    cur_c2 = model.selection[0].curve
    cur_p2 = []

    grab the position of the bottom circle's vertices

    cur_c2.vertices.each { | v | cur_p2 << v.position }

    show the points

    cur_p
    cur_p2`

    The output was

    
    > cur_p
    [Point3d(2.55906, 1.9685, 0.590551), Point3d(2.53893, 1.81566, 0.590551), Point3d(2.47994, 1.67323, 
    0.590551), Point3d(2.38609, 1.55092, 0.590551), Point3d(2.26378, 1.45707, 0.590551), Point3d(2.12135, 1.39808, 0.590551), Point3d(1.9685, 1.37795, 0.590551), Point3d(1.81566, 1.39808, 0.590551), Point3d(1.67323, 1.45707, 0.590551), Point3d(1.55092, 1.55092, 0.590551), Point3d(1.45707, 1.67323, 0.590551), Point3d(1.39808, 1.81566, 0.590551), Point3d(1.37795, 1.9685, 0.590551), Point3d(1.39808, 2.12135, 0.590551), Point3d(1.45707, 2.26378, 0.590551), Point3d(1.55092, 2.38609, 0.590551), Point3d(1.67323, 2.47994, 0.590551), Point3d(1.81566, 2.53893, 0.590551), Point3d(1.9685, 2.55906, 0.590551), Point3d(2.12135, 2.53893, 0.590551), Point3d(2.26378, 2.47994, 0.590551), Point3d(2.38609, 2.38609, 0.590551), Point3d(2.47994, 2.26378, 0.590551), Point3d(2.53893, 2.12135, 0.590551), Point3d(2.55906, 1.9685, 0.590551)]
    
    > cur_p2
    [Point3d(2.47994, 2.26378, 0), Point3d(2.53893, 2.12135, 0), Point3d(2.55906, 1.9685, 0), Point3d(2.53893, 1.81566, 0), Point3d(2.47994, 1.67323, 0), Point3d(2.38609, 1.55092, 0), Point3d(2.26378, 1.45707, 0), Point3d(2.12135, 1.39808, 0), Point3d(1.9685, 1.37795, 0), Point3d(1.81566, 1.39808, 0), Point3d(1.67323, 1.45707, 0), Point3d(1.55092, 1.55092, 0), Point3d(1.45707, 1.67323, 0), Point3d(1.39808, 1.81566, 0), Point3d(1.37795, 1.9685, 0), Point3d(1.39808, 2.12135, 0), Point3d(1.45707, 2.26378, 0), Point3d(1.55092, 2.38609, 0), Point3d(1.67323, 2.47994, 0), Point3d(1.81566, 2.53893, 0), Point3d(1.9685, 2.55906, 0), Point3d(2.12135, 2.53893, 0), Point3d(2.26378, 2.47994, 0), Point3d(2.38609, 2.38609, 0), Point3d(2.47994, 2.26378, 0)]
    
    

    The first point in the top circle is the third point in the bottom circle. Continuing anyway:

    ` entities = model.active_entities
    new_p = []

    create a bigger circle on the top face

    new_e = entities.add_circle cur_c.center, cur_c.normal, 20.mm
    new_c = new_e[0].curve

    grab the new vertices

    new_c.vertices.each { | v | new_p << v.position }

    delete the circle

    entities.erase_entities new_e

    move the vertices to the new positions

    cur_c.move_vertices new_p

    new_p2 = []

    create a bigger circle on the bottom face

    new_e2 = entities.add_circle cur_c2.center, cur_c2.normal, 20.mm
    new_c2 = new_e2[0].curve

    grab the vertices

    new_c2.vertices.each { | v | new_p2 << v.position }

    delete the circle and move the vertices

    entities.erase_entities new_e2
    cur_c2.move_vertices new_p2

    look at the points where the new vertices are

    new_p
    new_p2`

    The output was:

    
    > new_p
    [Point3d(1.1811, 1.9685, 0.590551), Point3d(1.20793, 2.1723, 0.590551), Point3d(1.28659, 2.3622, 0.590551), Point3d(1.41173, 2.52528, 0.590551), Point3d(1.5748, 2.65041, 0.590551), Point3d(1.76471, 2.72908, 0.590551), Point3d(1.9685, 2.75591, 0.590551), Point3d(2.1723, 2.72908, 0.590551), Point3d(2.3622, 2.65041, 0.590551), Point3d(2.52528, 2.52528, 0.590551), Point3d(2.65041, 2.3622, 0.590551), Point3d(2.72908, 2.1723, 0.590551), Point3d(2.75591, 1.9685, 0.590551), Point3d(2.72908, 1.76471, 0.590551), Point3d(2.65041, 1.5748, 0.590551), Point3d(2.52528, 1.41173, 0.590551), Point3d(2.3622, 1.28659, 0.590551), Point3d(2.1723, 1.20793, 0.590551), Point3d(1.9685, 1.1811, 0.590551), Point3d(1.76471, 1.20793, 0.590551), Point3d(1.5748, 1.28659, 0.590551), Point3d(1.41173, 1.41173, 0.590551), Point3d(1.28659, 1.5748, 0.590551), Point3d(1.20793, 1.76471, 0.590551), Point3d(1.1811, 1.9685, 0.590551)]
    
    > new_p2
    [Point3d(1.1811, 1.9685, 0), Point3d(1.20793, 2.1723, 0), Point3d(1.28659, 2.3622, 0), Point3d(1.41173, 2.52528, 0), Point3d(1.5748, 2.65041, 0), Point3d(1.76471, 2.72908, 0), Point3d(1.9685, 2.75591, 0), Point3d(2.1723, 2.72908, 0), Point3d(2.3622, 2.65041, 0), Point3d(2.52528, 2.52528, 0), Point3d(2.65041, 2.3622, 0), Point3d(2.72908, 2.1723, 0), Point3d(2.75591, 1.9685, 0), Point3d(2.72908, 1.76471, 0), Point3d(2.65041, 1.5748, 0), Point3d(2.52528, 1.41173, 0), Point3d(2.3622, 1.28659, 0), Point3d(2.1723, 1.20793, 0), Point3d(1.9685, 1.1811, 0), Point3d(1.76471, 1.20793, 0), Point3d(1.5748, 1.28659, 0), Point3d(1.41173, 1.41173, 0), Point3d(1.28659, 1.5748, 0), Point3d(1.20793, 1.76471, 0), Point3d(1.1811, 1.9685, 0)]
    
    
    

    The second set of points, created from circles added through the API are not twisted, i.e. the first point in new_c is directly above the first point in new_c2

    The result of this is that after you have moved both sets of vertices, the surface of the cylinder is broken. You'll get a warning when you load it. After.skp

    1 Reply Last reply Reply Quote 0
    • S Offline
      sdmitch
      last edited by 21 Aug 2014, 16:45

      why not just scale the circle using a scale_factor = new_radius/old_radius

      mod = Sketchup.active_model
      ent = mod.active_entities
      sel = mod.selection
      crv = sel[0].curve
      rad = crv.radius
      ctr = crv.center
      var = UI.inputbox(["New Radius;"],[rad],"Resize Circle")
      if !var then return end
      tr = Geom;;Transformation.scaling(ctr,var[0]/rad)
      ent.transform_entities(tr,crv)
      
      

      Nothing is worthless, it can always be used as a bad example.

      http://sdmitch.blogspot.com/

      1 Reply Last reply Reply Quote 0
      • C Offline
        crazystick
        last edited by 21 Aug 2014, 17:23

        I don't know why, I just figured that was too easy πŸ˜„

        Anyway, I tested that method, and it does work and appears to be accurate, so thank you. Unfortunately it still breaks the model, not as badly as my previous method, but on saving you still get a bunch of warnings The plane equation for CFace (xxxxxx) is not valid.

        Any ideas?

        1 Reply Last reply Reply Quote 0
        • S Offline
          sdmitch
          last edited by 21 Aug 2014, 18:58

          @crazystick said:

          I don't know why, I just figured that was too easy πŸ˜„

          Anyway, I tested that method, and it does work and appears to be accurate, so thank you. Unfortunately it still breaks the model, not as badly as my previous method, but on saving you still get a bunch of warnings The plane equation for CFace (xxxxxx) is not valid.

          Any ideas?

          I have run several tests and I don't get any error messages in v8 or v2014. Could you post the model. Also info on initial and final radii.

          Nothing is worthless, it can always be used as a bad example.

          http://sdmitch.blogspot.com/

          1 Reply Last reply Reply Quote 0
          • C Offline
            crazystick
            last edited by 21 Aug 2014, 19:12

            @sdmitch said:

            I have run several tests and I don't get any error messages in v8 or v2014. Could you post the model. Also info on initial and final radii.

            The model is the one from this post, just a simple cube with a cylindrical hole. I ran the script on the top and bottom circle, then tried to save.

            I just made one change, which was to convert to mm - I can't cope with 0.15346 etc.

            rad = crv.radius.to_mm
            

            The starting radius in the model is 15mm, I tried going down to 10mm and up to 20mm with the same result. I'm using Sketchup Pro 2014

            1 Reply Last reply Reply Quote 0
            • S Offline
              sdmitch
              last edited by 21 Aug 2014, 20:23

              @crazystick said:

              @sdmitch said:

              I have run several tests and I don't get any error messages in v8 or v2014. Could you post the model. Also info on initial and final radii.

              The model is the one from this post, just a simple cube with a cylindrical hole. I ran the script on the top and bottom circle, then tried to save.

              I just made one change, which was to convert to mm - I can't cope with 0.15346 etc.

              rad = crv.radius.to_mm
              

              The starting radius in the model is 15mm, I tried going down to 10mm and up to 20mm with the same result. I'm using Sketchup Pro 2014

              Sorry I forgot about the models in first post. I downloaded both and using the scale method on both didn't cause any errors using 2014 free. I have found that you can never be totally sure about the order of things in sketchup.

              Use .to_l to display values in model units.

              Nothing is worthless, it can always be used as a bad example.

              http://sdmitch.blogspot.com/

              1 Reply Last reply Reply Quote 0
              • D Offline
                Dan Rathbun
                last edited by 22 Aug 2014, 03:02

                To do this manually. You would select the inside surface of the hole, and then select the scale tool. You'd use two opposite corner handles, in the middle of the cylinder (not on the top or bottom circles. IE, you scale in the X and Y axis, but not in the Z axis.)

                The scale tool may adjust the selection set for the user.

                So try running it on the surface instead.

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • C Offline
                  crazystick
                  last edited by 23 Aug 2014, 12:57

                  I didn't know you could scale a cylinder like that. It's handy to know. I don't know how to do that in ruby though - I tried scaling all 24 faces in the x,y axes using the centre of the cylinder, but unfortunately that didn't work.

                  I also don't know why the model gets corrupted when I run the script and not when others do, I get the same results in 2013 Pro too. Maybe its a Mac issue.

                  If you have any more ideas, let me know, otherwise I'll just have to live with it πŸ˜„

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

                  Advertisement