[Plugin] Add Named Scene

[Plugin] Add Named Scene

Postby mirale999 » Tue Dec 06, 2011 10:44 am

Hi all,I'm a newbie in ruby, although being here several years...
I made a little plugin that lets you give a name upon adding a new scene~

Name : Named_Scene.rb
# Date : v1.0 11/12/6
# Description : To Let you rename it upon adding a new scene
# Menu Item : View -> Add Named Scene

Still have a problem, I want that: when clicking the menu or hot key, give you a small inputbox, and write the name, and create, you can also not change the default name, and add the new scene as normal~ The default name of the new scene can increase each time, I made the "Scene_Num" to do it but everytime it is "scene 1".

Who can teach me how to? :?


Thanks Thomthom~! I've updated the attachment below!
Now it works like this :
Hit the hotkey or click the menu item, give you an inputbox, you can choose to give the new a unique name, Or leave it to its default and create like normal: Scene 1- Scene 2- Scene 3-...
The first one define the new tab's name according to the number of existing pages:

Named_Scene.rb


Finally make the second one that do exactly the same thing as the normal scene tool, scene 1 - scene 2 - scene 3 - scene 4 - ... ignoring the number of existing pages, will not have any duplicate names! :D
& Use the
Code: Select all
File::basename(__FILE__)
to ignore its own file name.

Named_Scene2.rb


Code: Select all
# mirale999 first release, with Thomthom's help.
# Permission to use, copy, modify, and distribute this software for
# any purpose and without fee is hereby granted
# Freely use
# Name               :          Named_Scene.rb
# Date               :          v1.0 11/12/6
# Description        :          To Let you rename it upon adding a new scene
# Menu Item          :          View -> Add Named Scene

# It works like this :
# Hit the hotkey or click the menu item, give you an inputbox, you can
# choose to give the new a unique name, Or leave it to its default and
# create like normal: Scene 1- Scene 2- Scene 3-...
#----------------------------------------------------------------------------

require 'sketchup.rb'

module Named_Scene
 
  # Add menu items.
  unless file_loaded? File::basename(__FILE__)
    add_separator_to_menu("View")
    UI.menu("View").add_item("Add Named Scene") { self.add_namedScene }
  end

  @@scene_i = 1

  def self.add_namedScene
    model = Sketchup.active_model
    pages = model.pages   

    # Ask user for page name.
    list = []
    prompts = ["Scene Name:"]
    defaults = ["Scene"+" "+"#{@@scene_i}" ]
    input = UI.inputbox( prompts, defaults, list, "Add Named Scene" )

    # Check if the user cancelled.
    return if input==false

    # Get data from result array
    scene_name = input
    @@scene_i = @@scene_i + 1

    status = pages.add( scene_name.to_s )
  end
 
end

#-----------------------------------------------------------------------------
    file_loaded File::basename(__FILE__)
#-----------------------------------------------------------------------------
 




Hi all, after several years this small plugin has a bug because of the new version of ruby, and mariocha adds LanguageHandler in this version.The new modified version is here:
Named_Scene2.rbz
0
Last edited by mirale999 on Mon Feb 13, 2017 9:31 am, edited 3 times in total.
paranoia is a higher form of awareness...

mirale999 
 

Re: [Plugin] Add Named Scene

Postby thomthom » Tue Dec 06, 2011 11:09 am

mirale999 wrote:Still have a problem, I want that: when clicking the menu or hot key, give you a small inputbox, and write the name, and create, you can also not change the default name, and add the new scene as normal~ The default name of the new scene can increase each time, I made the "Scene_Num" to do it but everytime it is "scene 1".


'Scene1'.next
> Scene2


:?:
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Add Named Scene

Postby thomthom » Tue Dec 06, 2011 11:16 am

Ah - looking at your code now:

Code: Select all
# mirale999 first release
# Permission to use, copy, modify, and distribute this software for 
# any purpose and without fee is hereby granted
# Freely use
# Name        :          Named_Scene.rb
# Date        :          v1.0 11/12/6
# Description :          To Let you rename it upon adding a new scene
# Menu Item   :          View -> Add Named Scene
#----------------------------------------------------------------------------

require 'sketchup.rb'
 
Scene_Num=0


module Named_Scene
 
     unless file_loaded
?('Named_Scene.rb')
        
# Add menu items.
        
add_separator_to_menu("View")
                
UI.menu("View").add_item("Add Named Scene") { self.Add_NamedScene }
     
end
     
      
     def self
.Add_NamedScene
     model 
Sketchup.active_model
     pages 
model.pages

        
# Ask user for page name.
        
list=[]
        
prompts=["Scene Name:"]
        
defaults=[("Scene"Scene_Num.to_s) ]
        
input=UI.inputbox(promptsdefaults, list, "Add Named Scene" )
        
        
# Check if the user cancelled.
        
return if input==false
        
        
# Get data from result array
        
scene_name input


        status 
pages.add scene_name.to_s
     end
     
        Scene_Num
=Scene_Num 1
end

#-----------------------------------------------------------------------------
file_loaded('Named_Scene.rb')
#-----------------------------------------------------------------------------
 


Your Scene is a constant. But you are using it as a variable.

You need to look into the difference between variables and constants. Initial capital letter means a constant in Ruby.

Here's an amended version:

Code: Select all
# mirale999 first release
# Permission to use, copy, modify, and distribute this software for 
# any purpose and without fee is hereby granted
# Freely use
# Name        :          Named_Scene.rb
# Date        :          v1.0 11/12/6
# Description :          To Let you rename it upon adding a new scene
# Menu Item   :          View -> Add Named Scene
#----------------------------------------------------------------------------

require 'sketchup.rb'


module Named_Scene
 
  unless file_loaded
?('Named_Scene.rb')
    
# Add menu items.
    
add_separator_to_menu("View")
    
UI.menu("View").add_item("Add Named Scene") { self.add_namedScene }
  
end

  def self
.add_namedScene
    model 
Sketchup.active_model
    pages 
model.pages

    
# Ask user for page name.
    
list = []
    
prompts = ["Scene Name:"]
    
defaults = [("Scene#{pages.count}") ]
    
input UI.inputboxpromptsdefaults, list, "Add Named Scene" )

    
# Check if the user cancelled.
    
return if input==false

    
# Get data from result array
    
scene_name input

    status 
pages.addscene_name )
  
end
  
end

#-----------------------------------------------------------------------------
file_loaded('Named_Scene.rb')
#-----------------------------------------------------------------------------
 


I make the default name of the scene be made out of the number of existing pages in the current model. If you do it your way, with instance variables instead of constants, then it would just keep on counting between models.

I also cleaned up your indentation. Always keep your source code clean and organized, good indentation makes it easier to read - which is essential to debug and maintain your code.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Add Named Scene

Postby mirale999 » Tue Dec 06, 2011 12:08 pm

thomthom wrote:Ah - looking at your code now:


Your Scene is a constant. But you are using it as a variable.

You need to look into the difference between variables and constants. Initial capital letter means a constant in Ruby.

Here's an amended version:


I make the default name of the scene be made out of the number of existing pages in the current model. If you do it your way, with instance variables instead of constants, then it would just keep on counting between models.

I also cleaned up your indentation. Always keep your source code clean and organized, good indentation makes it easier to read - which is essential to debug and maintain your code.





Thanks Thomas~!! I use your code and now it's a correct version!
And the Scene name is the very same as the normal one~
0
paranoia is a higher form of awareness...

mirale999 
 

Re: [Plugin] Add Named Scene

Postby thomthom » Tue Dec 06, 2011 12:09 pm

But.... if you delete a scene or two you'll end up with duplicate names. So if you want to avoid that, then you need to make some extra checks.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Add Named Scene

Postby mirale999 » Tue Dec 06, 2011 3:52 pm

thomthom wrote:But.... if you delete a scene or two you'll end up with duplicate names. So if you want to avoid that, then you need to make some extra checks.


:berserk: Done!
0
paranoia is a higher form of awareness...

mirale999 
 

Re: [Plugin] Add Named Scene

Postby mariocha » Mon Sep 07, 2015 4:30 pm

Hum.. This plugin is a very good idea. Often wished this would be the native way to do.
But for me it the bracket and quote signs are unwanted?
See scene 555 attached.
1
Mario C.
Certified SketchUp Trainer, QC CA.
Every rule has exceptions, but some.
User avatar
mariocha 
Premium Member
Premium Member
 

Re: [Plugin] Add Named Scene

Postby glro » Mon Sep 07, 2015 9:11 pm

mariocha wrote:Hum.. This plugin is a very good idea. Often wished this would be the native way to do.
But for me it the bracket and quote signs are unwanted?
See scene 555 attached.


this is because the plugin has been written with a previous version of ruby

instead of

# Get data from result array
scene_name = input

put

# Get data from result array
scene_name = input[0]
1

glro 
 

Re: [Plugin] Add Named Scene

Postby chrisconcise » Wed Apr 12, 2017 4:21 pm

Good Job on your plugin, We are often creating scenes, and it is a pain to not be able name it once created. When creating a scene, the scene name it add includes [""], It would be really helpful to me if it could be modified, so that the scene name is only what you enter into the field, maybe I am doing something wrong, please advise if you would
thanks
Chris
0

chrisconcise 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Plugins

Who is online

Users browsing this forum: genki.tt, MSLMR, Rocaextra and 27 guests

Visit our sponsors: