SketchUcation Plugin Store

 

 

Hole plugin

Hole plugin

Postby njeremy2 » Tue May 29, 2012 8:56 am

Hello !

I need some help on a plugin.



I made geometrical form on that cube and I have a plugin which allow you to make hole in there (pushpull method).
When I started with 1,2,3,4 then A it worked.
If I start with a letter then number I have a hole only on A or B, but not in number because the pushpull make a hole on the edge of the cube.

Why it worked like that ?

I take the idea from that plugin, but this plugin work only for rectangle form...
http://rhin.crai.archi.fr/rld/plugin_details.php?id=326

I modify it to work with one click on the face. (you have to draw the geometrical form first then select the face and it create the hole)

How can I upload to plugin to show you ?


testhole.rb

THX thomthom !

To use it, copy it into plugin directory.
Then create a simple cube with geometrical form on that cube.
Click on "Plugins> njeremy2 Hole"
The plugin is activated, select the geometrical form and it create the hole
Please, register (free) to access all the attachments on the forums.
Last edited by njeremy2 on Tue May 29, 2012 9:26 am, edited 2 times in total.
njeremy2
 
Posts: 58
Joined: Mon Apr 16, 2012 2:53 pm
Name: jeremy

Re: Hole plugin

Postby thomthom » Tue May 29, 2012 9:11 am

UploadAttachments.png
Please, register (free) to access all the attachments on the forums.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Hole plugin

Postby njeremy2 » Tue May 29, 2012 9:22 am

I have an another pb... I can't create hole in components or groups. I have to explode it before make a hole
njeremy2
 
Posts: 58
Joined: Mon Apr 16, 2012 2:53 pm
Name: jeremy

Re: Hole plugin

Postby thomthom » Tue May 29, 2012 9:47 am

njeremy2 wrote:I have an another pb... I can't create hole in components or groups. I have to explode it before make a hole

Sounds like you are not referring to the correct entities collection.

If you use model.active_entities then it'll create the entities in the currently open group/component. If you want to edit a group you need to reference it's Entities collection: group.entities - When editing a ComponentInstance you need to modify the definition componentinstance.definition.entities.
(Here's a short summary about how instances and definitions relate in SketchUp: http://www.thomthom.net/thoughts/2012/0 ... -sketchup/ )
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Hole plugin

Postby thomthom » Tue May 29, 2012 9:52 am

Regarding test_hole.rb
Your method def in_face is outside the class. Move it to the inside of the class so it doesn't pollute the global namespace.




@entities = @model.entities
This is your problem with not being able to edit groups/components.
model.entities always refer to the root entities collection. Use model.active_entities to the current open set of entities.




(Still looking)
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Hole plugin

Postby njeremy2 » Tue May 29, 2012 9:58 am

I'm gonna read your articles

and test what you tell me to do. :)
njeremy2
 
Posts: 58
Joined: Mon Apr 16, 2012 2:53 pm
Name: jeremy

Re: Hole plugin

Postby thomthom » Tue May 29, 2012 10:04 am

Code: Select all

    
#We get all faces, norms, reversed norms and plans
    
all_faces = []
    
all_norms = []
    
all_norms_reverse = []
    
all_plans = []
    
0
    
@entities.each do |current_ent|
      if 
current_ent.is_a?(Sketchup::Face)
        
all_faces[j] = current_ent
        all_norms
[j] = current_ent.normal
        all_norms_reverse
[j] = current_ent.normal.reverse!
        
all_plans[j] = current_ent.plane
        j 
1
      end 
# end if current_ent is_a face
    
end #end current_ent
 


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.
Code: Select all

0
for e in model.entities
  array1
[i] = foo
  array2
[i] = bar
end

No need for that, just push the data directly to the arrays.
Code: Select all
for e in model.entities
  array1 
<< foo
  array2 
<< bar
end

Both foo and bar are still located with the same index in each their arrays.

A cleaned up version of your code snippet:
Code: Select all

    
#We get all faces, norms, reversed norms and plans
    
all_faces = []
    
all_norms = []
    
all_norms_reverse = []
    
all_plans = []
    
face.parent.entities.each do |current_ent|
      if 
current_ent.is_a?(Sketchup::Face)
        
all_faces << current_ent
        all_norms 
<< current_ent.normal
        all_norms_reverse 
<< current_ent.normal.reverse!
        
all_plans << current_ent.plane
      end 
# end if current_ent is_a face
    
end #end current_ent
 


(Still looking)
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Hole plugin

Postby thomthom » Tue May 29, 2012 10:12 am

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?
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Hole plugin

Postby njeremy2 » Tue May 29, 2012 10:28 am

thomthom wrote: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
njeremy2
 
Posts: 58
Joined: Mon Apr 16, 2012 2:53 pm
Name: jeremy

Re: Hole plugin

Postby njeremy2 » Tue May 29, 2012 10:46 am

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 working


re-edit2 : I can make a hole in groups ! :) (many thanks thom !)
Now I still have the first problem...
njeremy2
 
Posts: 58
Joined: Mon Apr 16, 2012 2:53 pm
Name: jeremy

Re: Hole plugin

Postby thomthom » Tue May 29, 2012 11:39 am

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.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Hole plugin

Postby thomthom » Tue May 29, 2012 11:55 am

Here is one alternative:
Please, register (free) to access all the attachments on the forums.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Hole plugin

Postby thomthom » Tue May 29, 2012 11:59 am

Meh! Doesn't work for faces outside the current context... :(
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Hole plugin

Postby thomthom » Tue May 29, 2012 12:21 pm

This one works. :D

UPDATE: I'd forgotten to remove some old code. Please check the new version.
Please, register (free) to access all the attachments on the forums.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Hole plugin

Postby thomthom » Tue May 29, 2012 12:23 pm

I saw a tiger lurking...


:shock:
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Hole plugin

Postby TIG » Tue May 29, 2012 12:26 pm

I made an inept and incorrect comment, which I then decided to erase :o
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's model = face.model is now redundant, because you iterate through the face.parent.entities to find the matching 'back-face'...
TIG
User avatar
TIG
Global Moderator
 
Posts: 14313
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Hole plugin

Postby thomthom » Tue May 29, 2012 12:44 pm

TIG wrote: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.)
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Hole plugin

Postby njeremy2 » Tue May 29, 2012 1:16 pm

ahahah
AHAHAHAHAHA !!! Thank you thomthom !!


It works great !!!
Many many many .... (ctrl+C, ctrl+V) ... many thanks !! :ecstatic: :thumb:
njeremy2
 
Posts: 58
Joined: Mon Apr 16, 2012 2:53 pm
Name: jeremy

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Artisan Organic Toolset - a set of powerful organic modeling tools.

Premium Members get 20% discount!

Ad Machine
Robot
 
Posts: 2012


Return to Developers' Forum

Who is online

Users browsing this forum: filipebonito, gilles and 2 guests