• Login
sketchucation logo sketchucation
  • Login
πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

[Plugin]ArcCurve-set_segments.rb & changearcsegments 130830

Scheduled Pinned Locked Moved Plugins
32 Posts 11 Posters 65.0k Views 11 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.
  • T Offline
    thomthom
    last edited by 19 May 2010, 07:54

    Some of these methods can be simplified with the aid of Curve.is_polygon? added in Google SketchUp 7.1 - Maintenance 1.

    Here's a set I made for my TT_Lib:

    
    	def self.is_curve?(entity)
    		return false unless entity.is_a?(Sketchup;;Edge) && entity.curve
    		return false if entity.curve.respond_to?(;is_polygon? ) && entity.curve.is_polygon?
    		return true
    	end
    	
    	def self.is_arc?(entity)
    		return self.is_curve?(entity) && entity.curve.is_a?(Sketchup;;ArcCurve)
    	end
    	
    	def self.is_circle?(ent)
    		# (i) A bug in SU makes extruded circles into Arcs with .end_angle of 720 degrees when reopening the file.
    		# Instead of checking for 360 degrees exactly, we check for anything larger as well. A 2D arc
    		# can't have more than 360 degrees.
    		#
    		# This doesn't work. Maybe due to rounding errors?
    		# return (arc_curve.end_angle - arc_curve.start_angle >= 360.degrees) ? true ; false
    		return false unless self.is_arc?(ent)
    		return ((ent.curve.end_angle - ent.curve.start_angle).radians >= 360) ? true ; false
    	end
    	
    	def self.is_polygon?(ent)
    		return ent.is_a?(Sketchup;;Edge) && ent.curve && ent.curve.respond_to?(;is_polygon? ) && ent.curve.is_polygon?
    	end
    	
    	def self.is_ngon?(ent)
    		return false unless self.is_polygon?(ent) && ent.curve.is_a?(Sketchup;;ArcCurve)
    		return ((ent.curve.end_angle - ent.curve.start_angle).radians >= 360) ? true ; false
    	end
    
    

    SU versions prior to this .is_polygon? will not be able to tell a Circle or Polygon apart, but no error is thrown.

    Thomas Thomassen β€” SketchUp Monkey & Coding addict
    List of my plugins and link to the CookieWare fund

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 16 Feb 2011, 22:22

      Here's an updated version that avoids other method clashes... http://forums.sketchucation.com/viewtopic.php?p=158903#p158903
      IF you have the older script ArcCurveTests.rb installed please remove it as it might clash with some other methods...

      TIG

      1 Reply Last reply Reply Quote 0
      • E Offline
        eskis
        last edited by 6 Aug 2011, 23:08

        great! great! great! that is what i was looking for!!!!!!
        thank you...

        1 Reply Last reply Reply Quote 0
        • A Offline
          ahnvtk
          last edited by 23 Aug 2011, 17:05

          I've tried making a script that automatically creates an 8-sided circle in a group at sketchup start, to see if all circles created by a user would then be 8-sided as well. They aren't - scripting an 8-sided circle still leaves the default sides at 24. 😞

          I tried changing the sides of a circle with this script as well - Sketchup still leaves the default at 24.

          How can I change the default sides of a circle? ❓

          1 Reply Last reply Reply Quote 0
          • T Offline
            TIG Moderator
            last edited by 23 Aug 2011, 19:28

            You can't.
            😞

            TIG

            1 Reply Last reply Reply Quote 0
            • A Offline
              ahnvtk
              last edited by 23 Aug 2011, 21:26

              😞

              At least this script here just saved me time reducing polys from extruded circles.. thanks!

              1 Reply Last reply Reply Quote 0
              • B Offline
                boilingsnow
                last edited by 20 Jan 2012, 23:16

                TIG it's nice of you to share this with us. I think this ruby is very useful but it's convenient to use because everytime I have to type "changearcsegments NNN" in the ruby console...Why not make it possible to be added in the plugin menu and works with a popup window to type in the segment number.

                1 Reply Last reply Reply Quote 0
                • T Offline
                  TIG Moderator
                  last edited by 21 Jan 2012, 11:45

                  Edit the script with a plain-text editor [Notepad/Notepad++.exe] and add this code at the end

                  unless file_loaded?(File.basename(__FILE__))
                    UI.menu("Plugins").add_item("Change Arc Segments"){
                      segments=inputbox(["Segments; "],[12],"Change Arc Segments")
                      changearcsegments(segments[0])if segments
                    }
                  end
                  file_loaded(File.basename(__FILE__))
                  

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • B Offline
                    boilingsnow
                    last edited by 21 Jan 2012, 13:42

                    @tig said:

                    Edit the script with a plain-text editor [Notepad/Notepad++.exe] and add this code at the end

                    unless file_loaded?(File.basename(__FILE__))
                    >   UI.menu("Plugins").add_item("Change Arc Segments"){
                    >     segments=inputbox(["Segments; "],[12],"Change Arc Segments")
                    >     changearcsegments(segments[0])if segments
                    >   }
                    > end
                    > file_loaded(File.basename(__FILE__))
                    

                    Thank you!

                    1 Reply Last reply Reply Quote 0
                    • L Offline
                      LorenzoS
                      last edited by 22 Mar 2012, 10:12

                      Hi!

                      Is Anyone so kind to tell me how to use this plug-in.

                      I get an error that says
                      Error Loading File ArcCurve-set_segments=.rb
                      no such file to load -- ArcCurveTests.rb

                      any help?

                      thx!
                      p.s.
                      I downloaded the script from the first post.

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        TIG Moderator
                        last edited by 22 Mar 2012, 12:44

                        It doesn't even use ArcCurveTests.rb or mention it in its code - in fact in earlier posts [in this thread] you are recommended to remove that very file from your Plugins folder, because changes to the API have meant that it might clash and updates of this tool no longer need it anyway.
                        So it is not 'required' by the recent versions of this script...
                        Your error message leads me to think that you have an old version of the tool loading...
                        Are you sure you have got the latest one in the Plugins folder? Windows Vista/Win7 can 'play tricks' if you don't have full access rights to the Plugins folder - it looks like you have added/updated a file/subfolder... but there's a 'Compatibility Files' button added to the folder's window-bar and they have actually gone into a side folder, IF you haven't got full security access rights to a folder [right-click context-menu Properties > Security]

                        Here's the latest version http://forums.sketchucation.com/viewtopic.php?p=158903#p158903
                        It has the Plugins menu item added to the code as discussed a few posts back...
                        Download the latest file from this link.
                        It should make a Plugins menu item which opens a dialog into which you type the number of arc segments required to process all selected arcs/circles...

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          theotses
                          last edited by 5 May 2013, 21:29

                          Hi!

                          I downloaded the plugin and istalled it. I have a big drawing with many arcs and is nearly impossible to select them all. So i select the whole drawing as i imported it and then i use the plugin. But the plugin works only with some of the arcs and the others remain with the default number of segments.

                          How can i use the plugin on all the arcs?

                          Thank you in advance.

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            TIG Moderator
                            last edited by 6 May 2013, 07:55

                            SketchUp's Arcs/Circles can have their 'segmentation' set as they are made OR later on by using 'Entity Info', OR bu using this tool.
                            BUT Arcs that have been scaled, exploded into edges OR are now incorporated into 3d geometry [extrusions etc] are never changeable.
                            So if you can't change your Arc's segmentation using 'Entity Info', then you can't change it with anything else either: its properties have been fixed by your earlier actions.

                            TIG

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              theotses
                              last edited by 6 May 2013, 08:24

                              I can change the segmentation from entity info but the arcs are too many. So I tried to select the whole drawing and change the segmentation with the tool but only few of the arcs got the segments I wanted.

                              1 Reply Last reply Reply Quote 0
                              • T Offline
                                TIG Moderator
                                last edited by 6 May 2013, 09:01

                                Wireframe mode will avoid picking faces, then select-by-fence, missing out anything that is obviously not an edge/curve...
                                Any errors in the Ruby Console ?

                                TIG

                                1 Reply Last reply Reply Quote 0
                                • T Offline
                                  theotses
                                  last edited by 6 May 2013, 12:02

                                  Thank you for your instant replies.

                                  I don't have any faces in my model. I don't really understand what you mean with the fence selection. (This is my first model in SketchUp 😳 )

                                  I don't get any errors at all. I just select all the lines and arcs (because i said in the first post that it is impossible to select every arc with clicks), then i use the plugin and i set the desired number of segments. Unfortunately not all the arcs get the number of segments I set in the plugin dialog box.

                                  1 Reply Last reply Reply Quote 0
                                  • T Offline
                                    TIG Moderator
                                    last edited by 6 May 2013, 12:48

                                    Can you attach your SKP to a post so we can see what's up...

                                    TIG

                                    1 Reply Last reply Reply Quote 0
                                    • T Offline
                                      theotses
                                      last edited by 11 May 2013, 22:20

                                      Thank you for your will to help me. As I understood the plugin can handle max 100 arcs at a time. I partially selected the whole model and everything was ok!

                                      1 Reply Last reply Reply Quote 0
                                      • T Offline
                                        TIG Moderator
                                        last edited by 30 Aug 2013, 09:54

                                        Slight update - rev 'a' - http://sketchucation.com/forums/viewtopic.php?p=158903#p158903
                                        ArcCurveTes.rb added for compatibility with v7 etc...

                                        TIG

                                        1 Reply Last reply Reply Quote 0
                                        • M Offline
                                          mbastian
                                          last edited by 17 Jun 2016, 19:58

                                          First of all: I am NOT a programmer, so there is ZERO error handling on this quick-and dirty script. I had tried TIG's solution, but did not work on my DWG because some of the arcs would "clip" others as they were rebuilt by the script.

                                          So I wrote this small routine to:

                                          • loop through imported AutoCAD entities.
                                          • select curves and group them (individually)
                                          • create a more refined clone of the curve (the number of segments is controlled by two parameters. See script)
                                          • Delete the original curve.

                                          Anyone is welcome to turn this snippet into something better and more reusable.

                                          Best,
                                          Marcos.


                                          theModel = Sketchup.active_model
                                          #selEntities = theModel.selection

                                          theModel.selection.clear
                                          allEntities = theModel.entities

                                          Collect user values:

                                          prompts = ["Minimum number of segments:", "Minimum Segment Length:"]
                                          defaults = [36, 10]
                                          input = UI.inputbox(prompts, defaults, "Enter Desired Settings")

                                          #set minimum length for each arc segment (in model units)
                                          userSegs = input[0]
                                          minLen = input[1]

                                          #UI.messagebox(userSegs.to_s)
                                          #UI.messagebox(minLen.to_s)

                                          allEntities.each do |i|
                                          if (i.typename == "Edge")
                                          aCurve = i.curve
                                          if (aCurve)
                                          Sel = theModel.selection unless defined?(Sel)
                                          Sel.add (aCurve.edges)
                                          newGroup = allEntities.add_group (theModel.selection)
                                          Sel.clear
                                          else
                                          #not a Curve
                                          end
                                          end
                                          end

                                          theModel = Sketchup.active_model
                                          theModel.selection.clear
                                          allEntities = theModel.entities

                                          Loop through all entities

                                          allEntities.each do |i|

                                          #open Groups, search for Curves
                                          if (i.typename == "Group")

                                          #Loop through array of Entities inside each Group
                                          subset = i.entities
                                          subset.each do |s|
                                          curve = s.curve

                                          if it is a curve, collect a few properties

                                          if (curve)

                                          get coord. transformation, since entities are in a group

                                          #use "transform" below to translate to global coordinates
                                          tr=i.transformation

                                          cCenter = curve.center.transform! (tr)
                                          cSangle = curve.start_angle
                                          cEangle = curve.end_angle
                                          cRadius = curve.radius
                                          cNormal = curve.normal.transform! (tr)
                                          cXaxis = curve.xaxis.transform! (tr)
                                          cYaxis = curve.yaxis.transform! (tr)

                                          cLength = curve.length
                                          #UI.messagebox(" Curve Length is " + cLength.to_s)

                                          #divides arcs in minLen(model unit) increments
                                          divSegs = (cLength / minLen).to_i
                                          #UI.messagebox("Divided Result is " + divSegs.to_s)

                                          #for very small arcs, sets a minimum number of segments
                                          if (divSegs <= userSegs)
                                          numSegs = userSegs

                                          UI.messagebox("Using: " + numSegs.to_s)

                                          else
                                          #subdivides larger arcs using target length
                                          numSegs = divSegs.to_i

                                          UI.messagebox("using Divided total" + numSegs.to_s)

                                          end

                                          myarc = allEntities.add_arc cCenter,cXaxis,cNormal,cRadius,cSangle,cEangle,numSegs
                                          #Erases original
                                          i.erase!

                                          end # if curve

                                          end # entities inside group loop

                                          end # if it is a group

                                          end #loop through all entities

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

                                          Advertisement