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

    Unfolding plugin idea

    Scheduled Pinned Locked Moved Plugins
    19 Posts 9 Posters 5.6k Views 9 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.
    • M Offline
      MattC
      last edited by

      Hello Everybody.
      I am working on a project (Using Sketchup to design paper models).I was able to write a small excel spreadsheet that will perform some 3D coordinates transformations to unroll surface. What I have so far you can see at: [url]sketchup-p-p.blogger.com[/url]
      But maybe it would be possible to do it all in Sketchup.
      Unfortunately learning Ruby at this time is not an option, so I am looking for someone that is willing to help.
      IDEA: Automatically unroll selected faces starting with picked face

      http://lh3.googleusercontent.com/_EBkdeqdPHu4/TdtvBXtGtJI/AAAAAAAAA9c/bxkLMp0ShLs/s400/1.PNG

      Our example consist of 6 faces, faces 1 and 2, 3 and 4, 5 and 6 are coplanar to each other.
      Step 1 – Select faces to unroll (Basic selection)
      Step 2 – Select first face

      http://lh4.googleusercontent.com/_EBkdeqdPHu4/TdtvBp_SVSI/AAAAAAAAA9k/PtEhAJ7qCds/s400/2.PNG

      Step3 - Select all faces from Basic Selection that coplanar are to the first face.(Coplanar selection)

      http://lh6.googleusercontent.com/_EBkdeqdPHu4/TdtvCnoIAjI/AAAAAAAAA9s/lhh-qZkceg0/s400/3.PNG

      Step 4 – Select one face adjacent to Coplanar Selection

      http://lh5.googleusercontent.com/_EBkdeqdPHu4/TdtvB1eKy0I/AAAAAAAAA9o/7h9qN6_v75w/s400/4.PNG

      Step 5 - Rotate Coplanar Selection to the same plane as adjacent face

      https://lh3.googleusercontent.com/_EBkdeqdPHu4/TdtvCh9JtuI/AAAAAAAAA9w/r-tjOYQ8Xpg/s400/5.PNG

      Step 6 – Like step 3 select all coplanar faces

      http://lh5.googleusercontent.com/_EBkdeqdPHu4/TdtvDe7oHAI/AAAAAAAAA94/Vu-x83qH6m8/s400/6.PNG

      Step7 – like step 4 Select one adjacent face

      http://lh3.googleusercontent.com/_EBkdeqdPHu4/TdtvDHQfmII/AAAAAAAAA90/gi8Jvihfv2U/s400/7.PNG

      Step 8 - like step 5 rotate to same plane as adjacent face

      http://lh6.googleusercontent.com/_EBkdeqdPHu4/TdtvBQb1AgI/AAAAAAAAA9g/VCmi_IqPxTE/s400/8.PNG

      Repeat until all faces from basic selection are coplanar.

      Anyone interested to share programming skills?

      Matt

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

        There are already two unfold scripts around that you could use as inspiration in your own coding... Jim's 'Unfold' and Pumpkin-Pirate's 'Flattery'... first read through those and then come back to us...

        TIG

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

          So I chewed TIG's reply over , and I got to work.
          Result is this:[flash=425,344:oyqeq35r]http://www.youtube.com/v/vAAt2Jb9P4Y&hl=fr&fs=1[/flash:oyqeq35r]

          I can call it from Ruby editor, but how to wrap it up to a plugin state ??
          Where can I find any tutorial or help ?

          1 Reply Last reply Reply Quote 0
          • K Offline
            kyyu
            last edited by

            @mattc said:

            So I chewed TIG's reply over , and I got to work.
            Result is this: <snip>

            I can call it from Ruby editor, but how to wrap it up to a plugin state ??
            Where can I find any tutorial or help ?

            MattC, look at this video: http://www.youtube.com/watch?v=YEJLw3WJsnU

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

              kyyu - Thanks a lot, somehow I missed this one.
              Work continues...

              1 Reply Last reply Reply Quote 0
              • J Offline
                Jim
                last edited by

                A little late, but don't forget about the Waybe unfold plugin.

                Link Preview Image
                404 - Page Not Found

                favicon

                (waybe.weebly.com)

                Hi

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

                  I have seen Waybe, but I haven't really tried it yet.
                  Other thing is that it is not free, not as much of a problem if you are a hobbyist, but for commercial use? Quite pricey. So is it possible to do most of what Waybe do for free? I hope so πŸ˜„
                  In a meantime ...

                  I base my work mostly on unfold plugin by Jim. So I try to reverse engineer structure of the code.
                  But the problems arise. Idea is that to run my plugin I need 3 selections : basis selection of faces that will be unfolded, and 2 faces that will specify unfolding direction.
                  Basis selection is not a problem, because I can select it before running code.
                  But I need to be able to select 2 faces when prompted.
                  I know that I should use onLButtonDown, but I miss something and it does not work. Can anyone help ?

                  Code:

                  module Autounfold
                  # Plugin require elements that we want to unfold to be selected before running
                  def Autounfold.main
                  	model = Sketchup.active_model
                  	model.start_operation "Autounfold"
                  	sel = model.selection
                  	bas_sel = []
                  	face1 = []
                  	face2 = []
                  	Sketchup.active_model.selection.each do |e| #we define basis selection of faces to unroll
                  		if e.is_a? Sketchup;;Face 
                  			bas_sel<<e;
                  		end
                  	end
                  Sketchup.active_model.selection.clear  #clear selection before asking for faces that defines direction of unrolling
                  UI.messagebox "#{bas_sel.length} faces selected to unrolling " # information, can be ommited
                  UI.messagebox "select first face";
                  # here I want to be able to select one face, and set it as face1 array
                  UI.messagebox "select second face";
                  # here I want to be able to select one face, and set it as face2 array
                  if face.length !=0 and face2.length!=0
                  	UI.messagebox "ready to unrol";
                  end
                  #here goes full algorythm 
                  end
                  def onLButtonDown(flags, x, y, view)
                          ph = Sketchup.active_model.active_view.pick_helper
                          ph.do_pick x, y
                          ref = ph.best_picked
                          if ref.nil?
                              puts "ref.nil"
                              Sketchup.active_model.selection.clear
                              Sketchup.set_status_text "Unfold; Selection cleared. Select face to unfold."
                              return
                          end
                          if( ref.typename == "Face" )
                              if face1.length == 0
                                  face1<<ref;
                                  UI.messagebox "face selected"
                  				return
                  			else
                  				if face2.length == 0
                                  face2<<ref;
                                  UI.messagebox "face selected"
                  				return
                  				end
                  			end
                          end
                  	Sketchup.active_model.commit_operation
                  end
                  end 
                  plug_menu=UI.menu("Plugins")
                  plug_menu.add_item ("Autounfold"){Autounfold.main}
                  

                  Thanks in advance, Matt

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

                    To use 'tool' methods like onLButtonDown() etc it must be inside a 'Class' that is launched as a 'tool' by Sketchup. Then it looks for all of the built-in special 'tool' methods like activate(), resume(), onMouseMove() etc if one is found it's used - see the LineTool example for several of these - and of course the API Tool doc http://code.google.com/apis/sketchup/docs/ourdoc/tool.html.
                    You've wrapped your methods inside a Module - it won't work as a 'tool' unless they are inside a 'Class' [which could also be inside the Module] and/or you need to also launch it as a 'tool' - you'd use something like plug_menu.add_item("Autounfold"){Sketchup.active_model.select_tool(Autounfold.new())} - [assuming the tool is a 'raw' class called 'Autounfold'???]...
                    The code inside the class's initialize() method runs first, then the code inside the activate() method next - any other methods are linked to those, or auto-activate depending on what you do with the mouse etc... If you use a @state variable and set it to have different values [0, 1, 2 etc] as various 'steps' are completed in the tool's methods then you can control things like 'onLButtonDown()' - by having for example return if @state!=1 in the first line of that method, so that method only becomes into play when you have set @state=1... NB: @ variables persist across methods in that instance of that class - @@ ones [initially set in the class itself, outside of any method]are remembered across uses of that class that session.

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • K Offline
                      kyyu
                      last edited by

                      Also, You can output text to the status bar vs alot of message boxes: http://code.google.com/apis/sketchup/docs/ourdoc/sketchup.html#status_text=
                      Message boxes are especially good for alerting the user of errors and debugging your code.

                      And there is a book that may help you out, concerning sketchup ruby. You can download the full pdf for free: http://www.autosketchup.com/

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

                        Thanks Everybody ! With Your help I got it working.
                        After this long weekend I will post what I have done.
                        Still there are some problems, but those I will try to solve later.

                        Matt

                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          DOD3R
                          last edited by

                          nice would be the possibility to make UV mam from this

                          1 Reply Last reply Reply Quote 0
                          • O Offline
                            Orangutan
                            last edited by

                            Nice work. Thanks.


                            autounfold.JPG

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

                              Hello Everybody

                              Here is result of my work.
                              Plugin will make a autounfold submenu , with 2 options: unroll and rotate to XY plane AND unroll and leave in plane of last element.
                              Select elements to unroll first and then activate tool.
                              Pick first face, and then pick one adjacent to define in which direction it schould be unfolded.

                              Script is based on idea of unfoldtool , and made with help of this comunity.
                              Therefore no rights reserved, and no responsibilities to be taken by author.
                              Feel free to test,use and modify.
                              C&C welcome!

                              Matt


                              Autounfold

                              1 Reply Last reply Reply Quote 0
                              • PixeroP Offline
                                Pixero
                                last edited by

                                Thanks! I will study it carefully. As you know I have an idea... πŸ˜‰

                                1 Reply Last reply Reply Quote 0
                                • K Offline
                                  Kuddl
                                  last edited by

                                  (old) Unfolding plugin idea

                                  (new) [Plugin] Unfolding automatically πŸ˜„

                                  Hi Matt,

                                  why do you do no official plug-in from this?
                                  Nice work. Thanks. πŸ‘
                                  You must not hide!

                                  Sorry my bad english… 😳
                                  Kuddl

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

                                    Hello

                                    First, it is not finished, there are some things that I would like to change but have no time at this moment.
                                    Second, it is not well tested, I know that on some conditions it will not work properly, I am still investigating the reasons.
                                    Third, When it comes to large curved surfaces, that consist of more than 400 faces, because if the loops that sit in code it can freeze.

                                    So no official plugin yet.Still lots of things to improve.

                                    Matt

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

                                      [Solved] BUT ideas are appreciated I am busy with reworking the code , but I found a small problem.
                                      First situation:
                                      Rectangle in XY plane, with a normal vector shown.
                                      Then this rectangle was split with a line into two triangles, again with shown normals.

                                      https://lh6.googleusercontent.com/-wwcErWmEVv8/Tjuv1W0tHLI/AAAAAAAABEY/e0rGPukMTkQ/s600/a1.PNG


                                      https://lh3.googleusercontent.com/-maBwUfPqGIU/Tjuv1osNksI/AAAAAAAABEg/utV0_szKZio/s600/a2.PNG

                                      No problem.
                                      Second situation, with rectangle not in XY plane:

                                      https://lh4.googleusercontent.com/-QXNPYC3ju_U/Tjuv19ltcrI/AAAAAAAABEk/wxlfgPhDme4/s600/a3.PNG


                                      https://lh5.googleusercontent.com/-7_n-e9E7vGs/Tjuv1ZbMONI/AAAAAAAABEc/bUFnmOqAdrA/s600/a4.PNG

                                      As you can see, there are smaal differences in coordinates.
                                      But when checking if faces are coplanar ( by comparing normals, of planes of faces) it gives a false result.
                                      Is there a walkaround? is it possible to perform some kind of rounding of coordinates?

                                      Thanks for help.
                                      Matt

                                      1 Reply Last reply Reply Quote 0
                                      • G Offline
                                        Gade
                                        last edited by

                                        Hello, i'm very interested into your plugin but it's not working on my computer... is it possible to use your plugin with mac ? i have sketchup 8? please help me to use your plugin i would like to make a model ...

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

                                          @gade said:

                                          Hello, i'm very interested into your plugin but it's not working on my computer... is it possible to use your plugin with mac ? i have sketchup 8? please help me to use your plugin i would like to make a model ...

                                          Hi I will need some more informations to answer, I havn't used it in a long time, at least this version, but I see no reason why it should not work on Mac.

                                          You can also take a look here:
                                          http://www.papermodelers.com/forum/software/18100-spp-sketchup-paper-planes-tools-sketchup.html

                                          Greets
                                          Matt

                                          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