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

[Help!] creat a face from edges on existing face

Scheduled Pinned Locked Moved Developers' Forum
13 Posts 5 Posters 713 Views
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.
  • H Offline
    Heven7_floor
    last edited by Heven7_floor 23 Nov 2010, 10:54

    I just learning ruby code in SU, and found problem about draw a face onto existing face, I can identify any method in new face further , such as

    <span class="syntaxdefault"><br /></span><span class="syntaxkeyword">@</span><span class="syntaxdefault">cir_face </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face edges                     </span><span class="syntaxkeyword">----------></span><span class="syntaxdefault"> drawing it on existing face<br /><br />if not</span><span class="syntaxkeyword">(@</span><span class="syntaxdefault">cir_face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">samedirection</span><span class="syntaxkeyword">?</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">dir_vec</span><span class="syntaxkeyword">)</span><span class="syntaxdefault">        </span><span class="syntaxkeyword">---------></span><span class="syntaxdefault"> get error </span><span class="syntaxstring">"undefine method 'normal' on nil "</span><span class="syntaxdefault"> <br />  puts </span><span class="syntaxstring">"change to initial direction"<br /></span><span class="syntaxdefault">  </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">cir_face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">reverse</span><span class="syntaxkeyword">!<br /></span><span class="syntaxdefault">end<br /></span>
    

    any one please help me to explain why cause of this error , I don't understand why I can't undentify this method

    thanks everyone in advance

    1 Reply Last reply Reply Quote 0
    • G Offline
      Gaieus
      last edited by 23 Nov 2010, 10:58

      Hi PCT,

      I cannot help but best would be to use the [code] or [ruby] tags because the keep script formatting better.

      Gai...

      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 23 Nov 2010, 11:23

        @heven7_floor said:

        @cir_face = entities.add_face edges ----------> drawing it on existing face

        if not(@cir_face.normal.samedirection? @dir_vec) ---------> get error "undefine method 'normal' on nil "

        This, "undefine method 'normal' on nil means that @cir_face is nil - which means your add_face method failed. When you get such errors it's worth inspecting the values of the variables you use in case they do not contain the data your expect.

        Could it be that the variable edges which you feed add_face does not have valid content to create a face?

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

        1 Reply Last reply Reply Quote 0
        • H Offline
          Heven7_floor
          last edited by 23 Nov 2010, 15:51

          @thomthom said:

          @heven7_floor said:

          @cir_face = entities.add_face edges ----------> drawing it on existing face

          if not(@cir_face.normal.samedirection? @dir_vec) ---------> get error "undefine method 'normal' on nil "

          This, "undefine method 'normal' on nil means that @cir_face is nil - which means your add_face method failed. When you get such errors it's worth inspecting the values of the variables you use in case they do not contain the data your expect.

          Could it be that the variable edges which you feed add_face does not have valid content to create a face?

          Hi Gaieus
          You just helpfully to support my post for looking , I appreciate and thanks for your kindly helpfulness , it was seem very easy to reading πŸ‘

          Hi thom
          Thanks very much , you explain that cause to me clearly β˜€ , but I still doubt some time this code is functionally, when I draw this face in empty space and error in very time , when I try repeat drawing new face to existing faces
          In my idea for coding, I attempt to coding a plug-in to help me to draw piping on desirous direction , I use "notepad++" to code plug-in to draw initial circle face in any direction and pull face long to cylinder as desire.
          I got success it to draw in empty space , but fail in repeat with some condition as picture below


          Clip.jpg


          circle_any_plan_&Pull.rb

          1 Reply Last reply Reply Quote 0
          • T Offline
            thomthom
            last edited by 23 Nov 2010, 16:24

            I get errors when I try to draw in empty space. Step1.

            @f_point = (1349,912557mm, 1796,5358mm, 0mm) @sec_point = (3105,012557mm, 1796,5358mm, 0mm) inputpoint length = 2 Error: #<NoMethodError: undefined methodnormal' for #Sketchup::InputPoint:0xc380278>
            C:\users\thomas\desktop\circle_any_plan_&Pull.rb:210:in previewShape' C:\users\thomas\desktop\circle_any_plan_&Pull.rb:123:in draw'
            C:\users\thomas\desktop\circle_any_plan_&Pull.rb:210`

            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
              thomthom
              last edited by 23 Nov 2010, 16:29

              btw, line 74: group = Sketchup.active_model.active_entities.add_group - doesn't seem to do anything other than adding an empty group... the code terminates there...

              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 23 Nov 2010, 16:57

                Line#210 normal=@inputpoints[0].normal - will give an error as a 'point' doesn't have a 'normal' - that's a 'face'/'arc' method ??

                Also to tidy things up, replace @GetPoint - an instance constant - with @getPoint - an instance variable...

                TIG

                1 Reply Last reply Reply Quote 0
                • H Offline
                  Heven7_floor
                  last edited by 24 Nov 2010, 02:06

                  @tig said:

                  Line#210 normal=@inputpoints[0].normal - will give an error as a 'point' doesn't have a 'normal' - that's a 'face'/'arc' method ??

                  Also to tidy things up, replace @GetPoint - an instance constant - with @getPoint - an instance variable...

                  Thom and TIG  have tried to help me find any error in code, you both  warm me up there :+1: ,  this help is much to me ,  btw I can't find this cause :unamused:  ,however this fill me persistency :tada:   and I must solve this error in finally
                  
                   Thanks very much
                  
                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    thomthom
                    last edited by 24 Nov 2010, 07:37

                    @heven7_floor said:

                    this help is much to me , btw I can't find this cause

                    The error I got - was due to this line:
                    normal=@inputpoints[0].normal

                    You add InputPoint to the @inputpoints array, then you try to extract a normal from one of them. This is the error. InputPoints doesn't return any normals.

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

                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      Heven7_floor
                      last edited by 24 Nov 2010, 07:38

                      @heven7_floor said:

                      @tig said:

                      Line#210 normal=@inputpoints[0].normal - will give an error as a 'point' doesn't have a 'normal' - that's a 'face'/'arc' method ??

                      Also to tidy things up, replace @GetPoint - an instance constant - with @getPoint - an instance variable...

                      Thom and TIG  have tried to help me find any error in code, you both  warm me up there :+1: ,  this help is much to me ,  btw I can't find this cause :unamused:  ,however this fill me persistency :tada:   and I must solve this error in finally
                      
                       Thanks very much
                      

                      After I re-thing about Thom & TIG 's commnet , I decide convert last entity to group, before repeat drawing ,it solve error when I draw new object again to last face πŸ˜› , but I still don't know why I can't define method else on new face which close in other face ❓
                      by the way I thanks you Thom & TIG for suggestion πŸ‘ πŸ‘ πŸ‘

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        TIG Moderator
                        last edited by 24 Nov 2010, 11:23

                        If all of your circles are 'flat' then use normal=Z_AXIS.clone and it'll work just fine...

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • H Offline
                          Heven7_floor
                          last edited by 25 Nov 2010, 14:28

                          @tig said:

                          If all of your circles are 'flat' then use normal=Z_AXIS.clone and it'll work just fine...

                          :+1:   Thanks for you suggestion TIG,  I would try as your comment  :smile:
                          
                          1 Reply Last reply Reply Quote 0
                          • K Offline
                            kyyu
                            last edited by 30 Nov 2010, 03:39

                            @heven7_floor said:

                            I just learning ruby code in SU, and found problem about draw a face onto existing face, I can identify any method in new face further , such as

                            <span class="syntaxdefault"><br /></span><span class="syntaxkeyword">@</span><span class="syntaxdefault">cir_face </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face edges                     </span><span class="syntaxkeyword">----------></span><span class="syntaxdefault"> drawing it on existing face<br /><br />if not</span><span class="syntaxkeyword">(@</span><span class="syntaxdefault">cir_face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">samedirection</span><span class="syntaxkeyword">?</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">dir_vec</span><span class="syntaxkeyword">)</span><span class="syntaxdefault">        </span><span class="syntaxkeyword">---------></span><span class="syntaxdefault"> get error </span><span class="syntaxstring">"undefine method 'normal' on nil "</span><span class="syntaxdefault"> <br />  puts </span><span class="syntaxstring">"change to initial direction"<br /></span><span class="syntaxdefault">  </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">cir_face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">reverse</span><span class="syntaxkeyword">!<br /></span><span class="syntaxdefault">end<br /></span>
                            

                            any one please help me to explain why cause of this error , I don't understand why I can't undentify this method

                            thanks everyone in advance

                            I've run into this problem before. Sketchup won't let you make a internal face with the add_face method. For example, if you simply draw a rectangle inside the interior of a face. Delete the rectangle's face. Select the 4 edges. The following code using Jim Foltz's Ruby Web Console won't remake the face:

                            model = Sketchup.active_model
                            ent = model.entities
                            sel = model.selection
                            edges = sel.to_a
                            ent.add_face edges
                            

                            You need to use the "find_faces" method, but that only returns the number of faces made. So you have to go through the trouble of finding the face it made. So rewriting your code, it would work this way:

                            	#@cir_face = entities.add_face edges
                                edges[0].find_faces
                                faces = edges[0].faces
                                for i in (0..faces.length)
                                    result = faces[i].classify_point(@f_point)    
                                    if result == Sketchup;;Face;;PointInside
                                      @cir_face = faces[i]
                                      break
                                    end
                                end
                            

                            I found this plugin very interesting. Here are some extra stuff, I cleared up at the beginning.

                            The "normal=@inputpoints[0].normal" was giving an error, like everyone pointed out. Looks like to me, its the same vector as "@dir_vec". So I set it equal to that vector:

                            #normal=@inputpoints[0].normal      
                            @dir_vec = find_vec(@inputpoints[0],@inputpoints[1])
                            normal = @dir_vec
                            v_axes = @dir_vec.axes
                            

                            And I found that your pushpull direction only went positive and not negative. So added these extra lines before your pushpull:

                            @pushpull_dir_vec = (@cpt_l-@f_point)
                            if !(@pushpull_dir_vec.samedirection? @dir_vec)
                                @cy_dist = -@cy_dist 
                            end         
                            status = @cir_face.pushpull @cy_dist,true
                            

                            Here is the modified file:
                            circle_any_plan_&Pull(modified).rb

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

                            Advertisement