[Help!]  creat a face from edges on existing face
- 
 Hi PCT, I cannot help but best would be to use the [code] or [ruby] tags because the keep script formatting better. 
- 
 @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_faceis 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 edgeswhich you feedadd_facedoes not have valid content to create a face?
- 
 @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_faceis 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 edgeswhich you feedadd_facedoes 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 ,  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
  
 
- 
 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:inpreviewShape' C:\users\thomas\desktop\circle_any_plan_&Pull.rb:123:indraw'
 C:\users\thomas\desktop\circle_any_plan_&Pull.rb:210`
- 
 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...
- 
 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 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
- 
 @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].normalYou add InputPoint to the @inputpointsarray, then you try to extract a normal from one of them. This is the error. InputPoints doesn't return any normals.
- 
 @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 muchAfter 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 , 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     
- 
 If all of your circles are 'flat' then use normal=Z_AXIS.cloneand it'll work just fine...
- 
 @tig said: If all of your circles are 'flat' then use normal=Z_AXIS.cloneand it'll work just fine...:+1: Thanks for you suggestion TIG, I would try as your comment :smile:
- 
 @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 edgesYou 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 endI 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.axesAnd 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,trueHere is the modified file: 
 circle_any_plan_&Pull(modified).rb
Advertisement



 
                             
                             
                             
                             
                             
                             
                            