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

    Get rotation(transformation)

    Scheduled Pinned Locked Moved Developers' Forum
    31 Posts 3 Posters 1.1k 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.
    • jolranJ Offline
      jolran
      last edited by

      WOW, you rewrote the whole script?!!! You are quite amazing. But, but.. Its your plugin, then??

      Heh, I almost got mine to work except the "petite" distance between lines thingy..

      Can I load the code in ruby code editor and launch? Cause nothing happends when I run your script.

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

        Please use it [or ideas in it] as you will - for example it doesn't always set the hatching at 45 degrees to where you might want just relative to the first edge of each face...
        There's no options for the angle or spacing - add a dialog for those?
        It's not optimized as it often makes more/longer edges than it needs to make the hatching but it was a quick kludge to make it work - to see what it does disable the closing parts that intersect/erase edges etc and use it on one face...

        It has ideas in it that should help you... πŸ€“

        PS: You have to have one or more faces selected before running it...

        TIG

        1 Reply Last reply Reply Quote 0
        • jolranJ Offline
          jolran
          last edited by

          You are so helpful. I can almost not believe it..
          Thank you TIG!

          I will continue with my script since I understand easier where variables are pointing to.
          See where I have gone wrong in some areas and use your script as a guidence.

          Thanks a million!

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

            @jolran said:

            I'm getting it to work almost.

            @unknownuser said:

            vector.length=20.0

            The copied distance will always be desired length on the vectors line, but depending on the angle of diagonal the edges will not be same distance apart. So I guess I will have to do another compensation? Or is there some Quick fix like the last one(thank you TIG)

            I'm guessing will have to do a comparison between Diagonal, user(desired angle, here 45 deg) and somehow
            compensate the copy distance for that. Boy this is hard..

            Here is a example of finding the normal vector of a grouped line, using a cross product. The cross product of two vectors prduces a third vector, at right angles to the original ones.

            model = Sketchup.active_model
            ent = model.entities
            sel = model.selection
            line = ent.add_line [3,3,0], [5,5,0]
            group = ent.add_group line
            v1 = line.vertices[0].position.transform(group.transformation)
            v2 = line.vertices[1].position.transform(group.transformation)
            v = v1.vector_to v2
            # I used z vector as 2nd vector, but can try "face.normal" for general case
            normal_vec = v.cross([0,0,1])  #cross product to get normal vector
            pt = [0,0,0]
            demo = ent.add_line  pt, pt.offset(normal_vec)  #drew demo line representing normal vector
            demo.material = 'red'
            n = normal_vec
            n.length = 1
            g1 = group.copy
            g1.transform! n  # moved copied group using normal vector
            
            1 Reply Last reply Reply Quote 0
            • jolranJ Offline
              jolran
              last edited by

              Hi Kyyu!

              Interresting. So you mean I use the 3rd vector for measuring? Or was it meant to be
              a method to get an angle 45 deg of the vector?
              Remember 45 deg is just an example for this particular hatching. The user must be able to
              choose any angle for the lines across the face.

              I will look into it more and see if I understand you code a little better.
              Thank you Kyyu.

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

                @jolran said:

                Hi Kyyu!

                Interresting. So you mean I use the 3rd vector for measuring? Or was it meant to be
                a method to get an angle 45 deg of the vector?
                Remember 45 deg is just an example for this particular hatching. The user must be able to
                choose any angle for the lines across the face.

                I will look into it more and see if I understand you code a little better.
                Thank you Kyyu.

                The 3rd vector would be your translation vector. In your code you have it as:

                vector=diag_vect
                vector.length= user_length
                

                It's perpendicular to what ever your final line is. Here, I just changed the line to a random new angle, not 45 deg. I set the length of the vector (distance of translation) to 1.
                find vector perpendicular to line in group.png

                I found this picture that explains cross product pretty well.

                1 Reply Last reply Reply Quote 0
                • jolranJ Offline
                  jolran
                  last edited by

                  Translation vector? The translation must be on the diagonal or the lines wont cover the whole face.
                  I already have the rotation of lines, copy/translation set up. Except that the "bug" is that
                  the translation distance doesent get 100% accurate if the face is very distorted.
                  Maybe that is what you are trying to fix, and I don't see it.
                  If thats the case sorry 😳 I'm a noob, you know.

                  The angles of lines on the picture are the identical. Although they don't appear to be.

                  1 Reply Last reply Reply Quote 0
                  • jolranJ Offline
                    jolran
                    last edited by

                    Hate to bother again, but I've been going on all day and intersect_with is troublesome. 😞

                    Tried TIG's combo, and others but I think I'm making a fundamentional fault.
                    Doesent intersect_with work with nested groups?

                    tr3=Geom::Transformation.new()
                    face_group.entities.intersect_with(recursion,tr3,face_group,tr3,true,[hatch_lines_group])

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

                      If you read through the way I did it... I make a hatching group then simply add a face and overly long hatching lines to it, intersect everything with each other, erase the faceless edges outside of the face perimeter and then erase the faces too. I never use subgroups - if you want to then just explode them...
                      You are better off transforming points/vectors and drawing the edges that grouping things endlessly/needlessly it'll be slooooow πŸ˜‰

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • jolranJ Offline
                        jolran
                        last edited by

                        @unknownuser said:

                        I make a hatching group then simply add a face and overly long hatching lines to it, intersect everything with each other, erase the faceless edges outside of the face perimeter and then erase the faces too

                        Aha! Did not quite understand what was going on.

                        Yes, yes I will TRY to do the same. That way I will learn the right way. Slow doesent sound good πŸ˜„

                        My resulted line_groups apears pretty fast on screen for the moment though, and its possible to make
                        a manual intersect with selected. But a lot cooler if it is manual.

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

                          @jolran said:

                          ...Except that the "bug" is that the translation distance doesent get 100% accurate if the face is very distorted.
                          Maybe that is what you are trying to fix, and I don't see it.
                          If thats the case sorry 😳 I'm a noob, you know.

                          Yes, that is what I am showing how to fix.

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

                            Where my script does a transformation.rotation on things simply using 45.degrees so it your user inputs an angle in a dialog as a 'float' - e.g. 12.5 use - angle=results[0] and spacing=results[1] (or whatever your dialog returns) and then in the transformation.rotation use angle.degrees instead...

                            TIG

                            1 Reply Last reply Reply Quote 0
                            • jolranJ Offline
                              jolran
                              last edited by

                              Great!! Will try that. But? That correction will just be a fix for the dialoginput, no?
                              I havent gotten that far yet 😳

                              Or maybe you mean your advice WILL fix missing geometry in the corners in certain angles)? Cause thats what bugging me, atm. I was only using Int's changing the angles and spacing.

                              Maybe that face.normal rotation of yours doesent work in all angles? Unless som serious fix?
                              Then using grouped edges might be more suitable, what do you think?
                              I'm not questioning anything, just don't know wich way to go.

                              Thank you TIG.

                              1 Reply Last reply Reply Quote 0
                              • jolranJ Offline
                                jolran
                                last edited by

                                BTW. The splats in my script was probably coming from the outliner open.

                                So Hmm. The direction I'm taking now is using edge_group_copying(my original idea). I cannot modify TIG's version due to lack of understanding. Not sure it will work like it is. But I'm a screwbie with bad solutions, so TIG can probably just wack in something just like that to prove I'm wrong πŸ˜›

                                But I will try to use the face normal to align my copies like in TIG's script, just to
                                have something to work on.
                                And use Kyuu's example for getting better accuracy with the distance between copies.
                                Methods for each view/axis would prob. make the script unnecessary long.
                                ABout adding groups. Sketchup doesent like it when your inside a group in model mode-
                                select a face- then by code add a group?

                                No suggestions I suppose? 😐

                                1 Reply Last reply Reply Quote 0
                                • jolranJ Offline
                                  jolran
                                  last edited by

                                  Ok! Thats very nice Kyyu!

                                  Will rework your advice. It looks like a smart solution. But I'm pretty confused right now...

                                  I managed to get the intersect_with working in "my" code. It hatches as it should do in the X,Z-axis, although with the distance-error, your trying to correct. However selecting a face inside a group in Sketchup and running the script gives a constant bugsplat. So I don't know if I should go forward an do the other views yet. Does not feel solid.

                                  I'm also worried going against TIG's advice with using groups hey-wild, but I can't implement his code into mine. It's to complicated to understand for me and can't get it to run properly.

                                  IF I can get the problem with creating hatches inside Sketchup model.groupes, and the distance between lines can be fixed, I think the performance would be OK with my version. But maybe the problem cannot be fixed other
                                  than rewriting everything as TIG says..
                                  I'm not lazy, just dumb..

                                  1 Reply Last reply Reply Quote 0
                                  • jolranJ Offline
                                    jolran
                                    last edited by

                                    Ok, take2. A little bit forward. Baby steps.

                                    So I've been going trough TIG's script 2 days now and I think I understand it better.
                                    It's of course much more sofisticated an more effective than my intentional idea,
                                    not surprisingly πŸ˜„

                                    vp.length=di*2
                                          tot=0
                                          until tot>=di*3 # fixes -45 deg. corner issue
                                    

                                    Made an adjustment to line 27 di*3(was di). It's an until.statement, where it keep copying the edges on an offset until the "offset-amount" has reached the length of the diagonal?
                                    (Hope I got that right..) So by multiplying the di by 3 it will get those extra edges
                                    needed to cover the corners with steep angles. Extra calculation YES! But needed.

                                    Have not fixed issues of spacing. The spacing is OK when kept around 45 degrees.
                                    But gets narrower when the degrees amount goes "away" from the original amount.

                                    MOST cases doing hatches one uses 45 degrees anyway. -45 and 45 degrees.
                                    So I will go ahead and try too make the ver1. UI now.


                                    fixed corners.jpg

                                    1 Reply Last reply Reply Quote 0
                                    • jolranJ Offline
                                      jolran
                                      last edited by

                                      I'm getting it to work almost.

                                      @unknownuser said:

                                      vector.length=20.0

                                      The copied distance will always be desired length on the vectors line, but depending on the angle of diagonal the edges will not be same distance apart. So I guess I will have to do another compensation? Or is there some Quick fix like the last one(thank you TIG)

                                      I'm guessing will have to do a comparison between Diagonal, user(desired angle, here 45 deg) and somehow
                                      compensate the copy distance for that. Boy this is hard..

                                      mod = Sketchup.active_model # Open model
                                      ent = mod.entities # All entities in model
                                      sel = mod.selection # Current selection
                                      
                                      =begin
                                      TODO
                                      Wrap in module.
                                      Get proper names. Shorter strings.
                                      def methods for different Axis. Name them as SU views.
                                      After Inputbox call appropriate method.
                                      Use instance or global variables, necessary?
                                      INPUTBOX promt; Hatch line degrees, distance between edges.
                                      Extras; Background color, keep background?
                                      Intersect with method.
                                      =end
                                      
                                      
                                      
                                      face_group = ent.add_group(sel)
                                      Sketchup.active_model.selection.add( face_group )
                                      
                                      bbox = face_group.bounds
                                      
                                      bpt1 = bbox.corner(0)
                                      bpt2 = bbox.corner(1)
                                      bpt3 = bbox.corner(2)
                                      bpt4 = bbox.corner(3)
                                      bpt5 = bbox.corner(4)
                                      bpt6 = bbox.corner(5)
                                      bpt7 = bbox.corner(6)
                                      bpt8 = bbox.corner(7)
                                      
                                      pt1 =bpt1
                                      pt2 =bpt2
                                      pt3 =bpt3
                                      pt4 =bpt4
                                      pt5 =bpt5
                                      pt6 =bpt6
                                      pt7 =bpt7
                                      pt8 =bpt8
                                      
                                      # get center, diagonal vector directions from bbox
                                      # mesure angle between x and diagonal
                                      
                                      x_cen = bbox.center
                                      x_diag = bbox.diagonal
                                      x_vect = pt1.vector_to pt4   # horisontal X-axis line
                                      diag_vect = pt1.vector_to pt6  # vector across
                                      x_ang = x_vect.angle_between(diag_vect).radians   
                                      user_input = 45   # Will get shorter alias
                                      user_length = 20.cm # Will get shorter alias substitute for cm? Must work in inches.
                                      
                                      
                                      h_group =ent.add_group()
                                      line_group=ent.add_group() ###==new empty groups
                                      line_group.entities.add_line(pt1, pt6)
                                      
                                      # rotate and reset parallel to X
                                      tr1 = Geom;;Transformation.rotation x_cen, [0,1,0],(x_ang).degrees
                                      tr2 = Geom;;Transformation.rotation x_cen, [0,1,0],(user_input).degrees
                                      ent.transform_entities tr1, (line_group)
                                      ent.transform_entities tr2, (line_group)
                                      
                                      cop_dist = x_diag/2   #copy distance/2 copies from center to top corner
                                      cop_times = cop_dist/user_length   
                                          
                                      vector=diag_vect
                                      vector.length= user_length
                                      gp=line_group
                                      groups=[gp]
                                      cop_times.to_i.times{|i|
                                      tgp=gp.copy
                                      tgp.transform!(Geom;;Transformation.translation(vector))
                                      gp=tgp
                                      groups << gp
                                      } 
                                      #my_transformed_vector.length=20.0   
                                      
                                      
                                      
                                         
                                      
                                      
                                      
                                      
                                      1 Reply Last reply Reply Quote 0
                                      • jolranJ Offline
                                        jolran
                                        last edited by

                                        I finally got TIG's version going(forgot to comment out #def.self when running it in R.code.editor, amanidiot!)
                                        SOme funky thing going on when changing hatch_angle. But its stable and works in any axis.

                                        Not what can be said about "my" script. A bit unstable, until the intersectionpart.
                                        My intuition tells me doing copying edges within groups + intersection gives more predictable hatch_result when rotating hatches. But is alot more unstable when gathering and erasing?

                                        Plan A: Stop whining and get the work done so Layout-users finally have a hatch-plugin πŸ˜„

                                        Plan B: Adjust TIG's script so it works in all angles, with menus and such.
                                        (will be difficult, since I don't totally understand it yet)

                                        PlanC: Continue to work on mine(a bit egoistic but I won't learn from copy/paste), integration as much of TIG's script as I can, thus make my script more stable if possible.
                                        However. That might not be possible, and I would have to do at least 5 different methods for views.

                                        I guess I'm asking if there is any pointers for things to avoid that make this script crash.

                                        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