[Plugin] Click2flip v1.0 20110928

[Plugin] Click2flip v1.0 20110928

Postby TIG » Wed Sep 28, 2011 12:27 pm

Written as a quick response to someone's query - to show how to detect clicks only on a 'back of a face'...

TIG (c) 2011
Usage: Plugins menu > 'Click Back of Face to Flip...'
Click on a face.
If you click on its back the face flips [reverses].
If you click on its front it's unchanged.
If you don't click on a face nothing happens.
If the face is 'nested' inside a group or component it will still flip!
Press <Esc> or activate another tool to stop this tool...
If you want it to 'beep' when a face is flipped then set @@BEEP=true at
the start of the code...
Donations:
PayPal.com info @ revitrev.org
Version:
1.0 20110928 First issue.
TIG-Click2flip.rb


Here's the alternative 'TIG.flipBacks()' that processes selected faces en mass... http://forums.sketchucation.com/viewtop ... 93#p357193
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Click2flip v1.0 20110928

Postby Carrozza » Wed Sep 28, 2011 12:37 pm

Seems like a great time-saver in some situations, and generally such a clever feature that should be built-int.
Bravo TIG! ^__^
0
User avatar
Carrozza 
 

Re: [Plugin] Click2flip v1.0 20110928

Postby pilou » Wed Sep 28, 2011 2:03 pm

If you don't click on a face nothing happens.

This one is my favorite! :fro: ;)
0
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie
User avatar
pilou 
Top SketchUcator
 

Re: [Plugin] Click2flip v1.0 20110928

Postby CadFather » Wed Sep 28, 2011 2:10 pm

Pilou, you are the best! :lol:
0
User avatar
CadFather 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Click2flip v1.0 20110928

Postby byrnebm » Wed Sep 28, 2011 4:19 pm

You are a genius.

Just to explain why I wanted to know how to do this. I wanted to use your "RelazioneFacce" script for some work I do. I want to select all the inside surfaces of a room (modelled as a box with no top). The "RelazioneFacce" script gives the orientation I am looking for but only when I have all the back sides of walls facing into the box. I can do this manually by clicking on the faces and reversing them so the back side of faces point in. But I thought there might be something I could put into the script so that when I select all the faces and run the "RelazioneFacce" script the code would firstly check if the back sides were facing inwards and reverse any faces that arent.

This click2flip script will greatly speed up my process so thank you. Just wondering if it could be incorporated programatically as I have described?
0

byrnebm 
 

Re: [Plugin] Click2flip v1.0 20110928

Postby TIG » Wed Sep 28, 2011 4:33 pm

To run it on 'all selected faces' is easier - just recast the code so that it isn't a 'tool' that needs to process clicked faces, but rather a method that processes a selection thus...
Code: Select all
module TIG
def self.flipBacks()
  model=Sketchup.active_model
  eye=model.active_view.camera.eye
  faces=[]
  Sketchup.active_model.selection.each{|e|faces << e if e.class==Sketchup::Face}
  return nil unless faces[0]
  model.start_operation("Flip Selected Back Faces...")
  faces.each{|face|
    normal=face.normal
    vector=face.bounds.center.vector_to(eye)
    angle=normal.angle_between(vector)
    face.reverse! if angle > 90.degrees
  }
  model.commit_operation
end
UI.menu('Plugins').add_item('Flip Selected Back Faces...'){self.flipBacks()} unless file_loaded?(__FILE__)
file_loaded(__FILE__)
end
Copy/paste the code into a new file in Plugins called 'TIG-flipBacks.rb', restart Sketchup and the item is in the Plugins menu for you...

EDIT: here's a .rb ready made
TIG-flipBacks.rb
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Click2flip v1.0 20110928

Postby byrnebm » Wed Sep 28, 2011 5:04 pm

Thanks again. When I select the 4 inside surfaces of a box, the script correctly flips all but one of the walls. Do you know what might be causing this? Is it anything to do with my viewpoint when I run the script?
0

byrnebm 
 

Re: [Plugin] Click2flip v1.0 20110928

Postby TIG » Wed Sep 28, 2011 5:32 pm

Yes, if a face is towards the camera it won't reverse because as far as the rules go it IS already facing the right way!
If all you want to do is reverse all selected faces then simply make a Shortcut to 'Reverse'.
Select any face so the option is available in the context-menu list, then use Window > Preferences > Shortcuts, filter for 'Reverse', set a shortcut to it - I also have a similar key+alt mapped to 'Orient'... Then you can quickly reverse a selection of faces.
These tools are specifically for reversing all picked or selected faces that are 'backwards' when considering their orientation 'towards' the current eye position... :geek:
Capture.PNG
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Click2flip v1.0 20110928

Postby byrnebm » Thu Sep 29, 2011 11:12 am

Ok thanks. Just a quick question is relation to the script "relazionefacce" which I use with click2flip. For the parameters it returns i.e FACCIA, ORIENAMENTO,AREA and MATERIALE. Where does the Faccia parameter come from and is this something that can be set for each face?
0

byrnebm 
 

Re: [Plugin] Click2flip v1.0 20110928

Postby TIG » Thu Sep 29, 2011 11:35 am

FACCIA [FACE] is name=face.to_s.split(":")[-1].split(">")[0]
i.e. when the array of faces is made they are by their 'id' e.g.
[#<Sketchup::Face:0x1182fad0>,
#<Sketchup::Face:0x1182f9e0>,
...]

The splitting takes the 'id' code so the above list becomes
[0x1182fad0
0x1182f9e0
...

You could of course just omit that column in the file as it does little of use...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Click2flip v1.0 20110928

Postby byrnebm » Thu Sep 29, 2011 11:39 am

I was just wondering if there was some way of naming the faces. I was hoping to be able to assign the room name to the horizontal face ie the floor of the room. So when i copy the parameters returned by relazionefacce to a spreadsheet I would know what room the results refer to.
0

byrnebm 
 

Re: [Plugin] Click2flip v1.0 20110928

Postby TIG » Thu Sep 29, 2011 12:19 pm

You could of course add an attribute to each face and later match the tabulated values to those, but it means manually adding them all - that's why I used the 'id' - but that only exists per session so isn't that useful later either...
When I code with attributes I usually add a time-stamp id as it's unique enough - if you have two attributes with the value 'office' only one might get found.
Tools like 'flattery' add a unique attribute code to every selected face and then use this in matching parts together later. You could do something similar - add an attribute to every selected face and use the attribute in your tabulated forms. You'd then need a second simple tool to 'find face by id' - it opens a dialog, you'd paste the attribute value from the tabulated data, and it finds the face by its attribute and then highlights that face for you...
Change 'FACCIA' to say 'ID'.
Modify the code thus...
Code: Select all
faces.each{|face|
  tid=(Time.now.to_f*1000).to_i
  face.set_attribute('BB','id',tid)if not face.get_attribute('BB','id',nil)
  ### if it already has an id it's kept...
  tid=face.get_attribute('BB','id',0)
  ###
  name=tid.to_s
  ### ...

Now write a new tool to find a face by id...
Code: Select all
module TIG
 def self.findfacebyid()
  model=Sketchup.active_model
  ss=model.selection
  ss.clear
  results=inputbox(['ID: '],[0],'FindFaceByID')
  return nil unless results
  id=results[0].to_i
  model.active_entities.each{|e|ss.add(e)if e.get_attribute('BB','id',nil)==id}
 end
end
Usage: type TIG.findfacebyid
or make a second menu item using it - follow the other menu item as a guide...
Copy+paste an id from the table into the dialog
The faces' IDs will persist across sessions provided the model is saved...
I used 'BB' as the attribute-library based on your initials, but you can use anything you want...
:geek:
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Click2flip v1.0 20110928

Postby Gillman » Mon Oct 03, 2011 2:08 pm

Just wanted to thank you for this great plug-in. It has already saved me a ton of time.
0

Gillman 
 

Re: [Plugin] Click2flip v1.0 20110928

Postby mirale999 » Tue Oct 18, 2011 2:56 am

:berserk:
A wonderful plugin! thank you TIG!I think TIG-flipBacks.rb is much more easier than other face reversers until now~
0
paranoia is a higher form of awareness...

mirale999 
 

Re: [Plugin] Click2flip v1.0 20110928

Postby 3dsmax9 » Tue Oct 18, 2011 9:35 am

it's great to have a lot of choice thanks TIG, personally i prefer this one FrontFace1-2 : viewtopic.php?t=13380
0

3dsmax9 
 

Re: [Plugin] Click2flip v1.0 20110928

Postby mirale999 » Sat Oct 22, 2011 4:55 pm

3dsmax9 wrote:it's great to have a lot of choice thanks TIG, personally i prefer this one FrontFace1-2 : viewtopic.php?t=13380


haha! I'm using frontface and Click2flip, they have different feature~ I appreciate the amazing performance of the former, while the latter is faster when I have so many small faces to reverse at once!
0
paranoia is a higher form of awareness...

mirale999 
 

Re: [Plugin] Click2flip v1.0 20110928

Postby artmusicstudio » Fri Jul 26, 2013 3:16 pm

hi tig,
i am not a programmer, but as flipped faces always happen in skp and in complicated structures it is sometimes difficult to select them one after another, i had a following idea for this script

1. could it flip ALL SELECTED faces at once (of course with your "automatic" identificaton?

2. could it become an option :

>> make all front / make all back / make all faces the side, which is "higher" represented (sorry for this english....means with 100 faces, when 3 are back and the rest is front, it would make all front and vice versa)

by that i could double-click & select all connected faces and define all at once

thanx stan
0
User avatar
artmusicstudio 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Click2flip v1.0 20110928

Postby TIG » Fri Jul 26, 2013 3:39 pm

Isn't a pair of shortcut-keys, to 'Reverse' and 'Orient' to match the just reversed face, going to do most of this ?
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Click2flip v1.0 20110928

Postby artmusicstudio » Fri Jul 26, 2013 9:54 pm

TIG wrote:Isn't a pair of shortcut-keys, to 'Reverse' and 'Orient' to match the just reversed face, going to do most of this ?


yes, you're right. maybe for selection (if there is any) or all elements.
so this 'make positive/negative' feature would be great and a real time-saver.
regards stan
0
User avatar
artmusicstudio 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Click2flip v1.0 20110928

Postby clubber2k » Wed Sep 25, 2013 1:21 pm

Wow, magical! :thumb: :thumb: :thumb:

looked for something like this way back and didn't find.

only issue is that the automatic decision making stress me out. on complex models it might flip the right one facing to me, but also another that should be facing in another direction and I didn't even notice...

can you add an option using the same concept to just label all the wrong facing faces - allowing more precise decision making?

thanks :fro:
0

clubber2k 
 

Re: [Plugin] Click2flip v1.0 20110928

Postby Dave R » Wed Sep 25, 2013 1:28 pm

You might find it useful to set the back face color to something more easily discernible. I use a green I'd never use in the model as a color/texture.
0
%

(THERE'S NO PLACE LIKE)

G28 X0.0 Y0.0 Z0.0

M30

%
User avatar
Dave R 
Global Moderator
 

Re: [Plugin] Click2flip v1.0 20110928

Postby clubber2k » Wed Sep 25, 2013 5:27 pm

Dave R wrote:You might find it useful to set the back face color to something more easily discernible. I use a green I'd never use in the model as a color/texture.


Yes - that's a generally good idea but since sometimes you have materials on the back side you need to go monochrome and back too see whats going on.. anyway since this plugin already exist - adding a label option will add great usability if possible..
0

clubber2k 
 

Re: [Plugin] Click2flip v1.0 20110928

Postby CadFather » Mon Dec 29, 2014 6:27 pm

great and simple tool, would be super-fab if able to flip curved faces as well!

...i thought combining the 2 bits of code above might do the trick:

1, click2flip
2, flip selection

the idea being that if i click on a curved face, i'm also selecting it and therefore running the 2nd script might reverse the whole curved face, say a cylinder. (ideally i thought it could be toggled by pressing an accelerator key) a fair bit beyond my christmas powers... surely possible though..?


Code: Select all
class TIG::Click2flip
  @@BEEP=false
  def initialize()
    @ip  = nil
    @ip1 = nil
  end
  def activate()
    @ip  = Sketchup::InputPoint.new
    @ip1 = Sketchup::InputPoint.new
    @msg="Click back of face to flip it..."
    self.reset()
  end
  def deactivate(view)
    view.invalidate
  end
  def onCancel(flag, view)
    view.invalidate
    Sketchup.send_action("selectSelectionTool:")
    return nil
  end
  def resume(view)
    Sketchup::set_status_text(@msg, SB_PROMPT)
  end
  def reset()
    Sketchup::set_status_text(@msg, SB_PROMPT)
  end
  def onMouseMove(flags, x, y, view)
    @ip.pick(view, x, y)
    if @ip != @ip1
        view.invalidate if @ip.display? or @ip1.display?
        @ip1.copy!(@ip)
        view.tooltip = @ip1.tooltip
    end
  end
  def onLButtonDown(flags, x, y, view)
    if @ip1.valid?
        @pt=@ip1.position
        ph = view.pick_helper
        ph.do_pick(x,y)
        @face = ph.picked_face
        self.flipper() if @face
    end
  end
  def flipper()
    normal=@face.normal
    vector=@pt.vector_to(Sketchup.active_model.active_view.camera.eye)
    angle=normal.angle_between(vector)
    if angle > 90.degrees
      @face.reverse!
      UI.beep if @@BEEP
    end#if
  end
end#class


Code: Select all
def self.flipBacks()
  model=Sketchup.active_model
  eye=model.active_view.camera.eye
  faces=[]
  Sketchup.active_model.selection.each{|e|faces << e if e.class==Sketchup::Face}
  return nil unless faces[0]
  model.start_operation("Flip Selected Back Faces...")
  faces.each{|face|
    normal=face.normal
    vector=face.bounds.center.vector_to(eye)
    angle=normal.angle_between(vector)
    face.reverse! if angle > 90.degrees
  }
  model.commit_operation
end




EDIT: actually just noticed the second script only flips half a cylinder (the side to the screen), the back remains undone.
0
User avatar
CadFather 
PluginStore Author
PluginStore Author
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Plugins

Who is online

Users browsing this forum: delysa, juju, moh8kazem and 9 guests

Visit our sponsors: