Hole plugin
-
I'm gonna read your articles
and test what you tell me to do.
-
<span class="syntaxdefault"><br /> </span><span class="syntaxcomment">#We get all faces, norms, reversed norms and plans<br /> </span><span class="syntaxdefault">all_faces </span><span class="syntaxkeyword">= []<br /> </span><span class="syntaxdefault">all_norms </span><span class="syntaxkeyword">= []<br /> </span><span class="syntaxdefault">all_norms_reverse </span><span class="syntaxkeyword">= []<br /> </span><span class="syntaxdefault">all_plans </span><span class="syntaxkeyword">= []<br /> </span><span class="syntaxdefault">j </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">0<br /> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">do |</span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">|<br /> if </span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_a</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">all_faces</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">j</span><span class="syntaxkeyword">] = </span><span class="syntaxdefault">current_ent<br /> all_norms</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">j</span><span class="syntaxkeyword">] = </span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal<br /> all_norms_reverse</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">j</span><span class="syntaxkeyword">] = </span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">reverse</span><span class="syntaxkeyword">!<br /> </span><span class="syntaxdefault">all_plans</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">j</span><span class="syntaxkeyword">] = </span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">plane<br /> j </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">j </span><span class="syntaxkeyword">+ </span><span class="syntaxdefault">1<br /> end </span><span class="syntaxcomment"># end if current_ent is_a face<br /> </span><span class="syntaxdefault">end </span><span class="syntaxcomment">#end current_ent<br /> </span><span class="syntaxdefault"></span>
First of all,
@entities
is incorrect. In your code you set this to@model.entities
- which is the root entities collection. The face you pick might be from any group or component - so you want to use the entities collection that face belongs to.face.parent.entities
.Second of all, you use a counter to insert items into your arrays.
<span class="syntaxdefault"><br />j </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">0<br /></span><span class="syntaxkeyword">for </span><span class="syntaxdefault">e in model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br /> array1</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">] = </span><span class="syntaxdefault">foo<br /> array2</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">] = </span><span class="syntaxdefault">bar<br />end<br /></span>
No need for that, just push the data directly to the arrays.
<span class="syntaxdefault"><br /></span><span class="syntaxkeyword">for </span><span class="syntaxdefault">e in model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br /> array1 </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">foo<br /> array2 </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">bar<br />end<br /></span>
Both
foo
andbar
are still located with the same index in each their arrays.A cleaned up version of your code snippet:
<span class="syntaxdefault"><br /> </span><span class="syntaxcomment">#We get all faces, norms, reversed norms and plans<br /> </span><span class="syntaxdefault">all_faces </span><span class="syntaxkeyword">= []<br /> </span><span class="syntaxdefault">all_norms </span><span class="syntaxkeyword">= []<br /> </span><span class="syntaxdefault">all_norms_reverse </span><span class="syntaxkeyword">= []<br /> </span><span class="syntaxdefault">all_plans </span><span class="syntaxkeyword">= []<br /> </span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">parent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">do |</span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">|<br /> if </span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_a</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">all_faces </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">current_ent<br /> all_norms </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal<br /> all_norms_reverse </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">reverse</span><span class="syntaxkeyword">!<br /> </span><span class="syntaxdefault">all_plans </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">current_ent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">plane<br /> end </span><span class="syntaxcomment"># end if current_ent is_a face<br /> </span><span class="syntaxdefault">end </span><span class="syntaxcomment">#end current_ent<br /> </span><span class="syntaxdefault"></span>
(Still looking)
-
I don't understand the rest of your code.
mini = 10000
What is this magic number?current_norm_reverse.length = 1000
What is the purpose of this line? -
@thomthom said:
I don't understand the rest of your code.
mini = 10000
What is this magic number?current_norm_reverse.length = 1000
What is the purpose of this line?me too, that code is from rectangleHoletool.rb from the link in my first post
-
I made some test on that plugin.
If the entity is longer than ~25000 cm (more than 25400cm, I just test it), you can make any hole. If it's smaller than that value, it workingre-edit2 : I can make a hole in groups ! (many thanks thom !)
Now I still have the first problem... -
The logic for finding the opposite face is somewhat odd. The magic number is no good design and puts on an artificial limit.
I'm thinking that it'd be better to trace a ray to pick the opposite face. Shoot a ray from one of the vertices (or a calculated face centre) in the opposite direction of the face normal - see if it hit a face with a reversed normal. Then use that length to push-pull. -
-
Meh! Doesn't work for faces outside the current context...
-
This one works.
UPDATE: I'd forgotten to remove some old code. Please check the new version.
-
I saw a tiger lurking...
-
I made an inept and incorrect comment, which I then decided to erase
You have fixed it now anyway...
BUT where'd it go
Now it's back again... The art of illusion..........
"Now you see it, now you don't."PS:
The latest code method'smodel = face.model
is now redundant, because you iterate through theface.parent.entities
to find the matching 'back-face'... -
@tig said:
PS:
The latest code method's model = face.model is now redundant, because you iterate through the face.parent.entities to find the matching 'back-face'...True that. (Won't bother to update for that one line though.)
-
ahahah
AHAHAHAHAHA !!! Thank you thomthom !!It works great !!!
Many many many .... (ctrl+C, ctrl+V) ... many thanks !!
Advertisement