@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