[Plugin] Styles Favourites (v01)

[Plugin] Styles Favourites (v01)

Postby Trogluddite » Thu Nov 22, 2012 4:53 pm

EDIT) I have now made a new plugin Render Favourites, that extends the features of this one by including many other rendering options, so you may want to check that out before loading this one. However, I keep this here, as a pure 'Style switcher' may suit your way of working better.

Hi All,

So finally I got around to learning some Ruby - helped no end of course by all the forum guru's great lessons here - and here is my first ever plugin. Trog's Style Chooser.

The plugin allows you to choose your four favourite styles, memorise them, and call them up from a dedicated sub-menu of the 'view' menu.
The idea is to be able to assign a shortcut key to the 'Recall' menu items, and then you can instantly change styles with a quick stab of a key. Of course, with the right settings, you can do something similar with scenes - but I prefer to use those just for storing viewpoints, and you can only assign shortcuts to cycle around them, which I find very annoying when I just want to quickly get to one of the first few from a long list.

A few instructions...
To assign a view, set up the model appearance as you like, and then, if it isn't already, store this as a named style. Then selected "View -> Style Favourites -> Store (X)".
To recall, "View -> Style Favourites -> Recall (X)".
The favourites are stored in a small file inside a sub-folder of the "plugins" folder, so that they are there for next time.
All of those options will be available for assigning shortcut keys.

Note that the Styles are referenced by name, so you need to be aware...
- To recall a style it must be resident in the current model (I added my favourites to my default template to make sure they're always there)
- The styles must have unique names.
- Recall menu items will be greyed out if no favourite has been set, or if the style is not present in the current model.
- A folder called "Trog_Style_Chooser" will be created inside the plugins folder to store your favourites.

MOST IMPORTANT. This is my first ever plugin!! Despite the wonderful examples provided here on the forum, I cannot guarantee that the plugin is perfect - there are no restrictions on how you may use it, but I also make no promises how good or useful it might be!!

DOWNLOAD..
Trog_Style_Chooser.rb


If any of the forum Ruby experts care to comment about the quality, or otherwise, of my code, I would be extremely grateful. I have tried to avoid all of the pitfalls that I have seen warnings about on the developer's forum - but I am very new to Ruby, and much of what I read goes straight over my head at the moment! :oops:
0
Last edited by Trogluddite on Sat Dec 08, 2012 3:57 pm, edited 3 times in total.

Trogluddite 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Styles Favourites (v01 Beta 01)

Postby Dave R » Thu Nov 22, 2012 5:40 pm

Interesting idea. Other than the keyboard shortcut, how would this be different from picking the styles from the In Model Styles library?
0
Etaoin Shrdlu


%

(THERE'S NO PLACE LIKE)

G28 X0.0 Y0.0 Z0.0

M30

%
User avatar
Dave R 
Global Moderator
 

Re: [Plugin] Styles Favourites (v01 Beta 01)

Postby TIG » Thu Nov 22, 2012 5:43 pm

In a module == good
Styles_dir = Sketchup.find_support_file("Plugins") + '/Trog_Styles_Chooser'
Styles_path = Styles_dir + "/Trog_Styles.dump"

would be better as
Styles_dir = File.join(File.dirname(__FILE__), 'Trog_Styles_Chooser')
Styles_path = File.join(Styles_dir, 'Trog_Styles.dump')

Then as long as your script and its supporting subfolder exist it'll work - if someone loads things from somewhere other than the Plugins folder it'll break with your code.
You might also want to add the line:
Dir.mkdir(Styles_dir) unless File.exist?(Styles_dir)
INSIDE the module to make the folder if it's missing.
You could put all of your your menu code inside your module 'code-block', to keep it wholly separate.
You can then replace 'Trog' with 'self' - so later on when you decide that 'Trogs_Module' would be your preferred name you don't need to change it but the once.
One minor point "Constants" are traditionally all in CAPITAL letters, although using just an initial Capital will suffice!
I think that 'opening' the file to read the data using a block 'auto-closes' it - but being old school I prefer to manually 'close' it...

All in all, a good'un as far as your first go at scripting is concerned... :D
Although it does somewhat 'reinvent-the-wheel' of the built-in Style dialog method...
A Template with the preferred Styles used for each premade Scene-tab would also be an alternative... :?
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Styles Favourites (v01 Beta 01)

Postby Trogluddite » Thu Nov 22, 2012 5:58 pm

Dave R wrote:Other than the keyboard shortcut, how would this be different from picking the styles from the In Model Styles library?

That's pretty much it - just the keyboard shortcuts!
Probably just a reflection of my own way of working - but I don't like mixing scene tabs that all have different sub-sets of parameters, I like to think of them more as "viewpoints". So this just saves me having to have the styles window open - I do mostly engineering type stuff, so switching between solid, wireframe with axis colours, x-ray etc. are the only thing I use styles for.

TIG wrote:All in all, a good'un as far as your go at scripting is concerned...

Thanks TIG, coming from you, that means a lot! :D
And thanks of course for the tips - the file system and script loading is the bit that I was most concerned about, I couldn't quite decide what should be in the module, and what as 'bare code'. Now I know it can all go safely inside the module, I can code with a little more confidence.
0

Trogluddite 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Styles Favourites (v01)

Postby Trogluddite » Fri Nov 23, 2012 9:36 pm

Download updated in the top post
Nothing new - just a revision to incorporate TIG's suggestions for making the plugin more robust.
0

Trogluddite 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Styles Favourites (v01)

Postby renderiza » Sat Nov 24, 2012 5:35 am

Hi,

I am currently trying to figure out how I can come up with a sky system plugin with day and night cycles and my current rout is dealing with different style properties.

My initial plan was to animate the sky toggling thru scene tabs with code but this new approach you just created to change styles with code without transitioning thru pages is worth my attention big time.

Thanks for sharing this great idea and of course to the people that helped you make it better as well!
0
User avatar
renderiza 
Premium Member
Premium Member
 

Re: [Plugin] Styles Favourites (v01)

Postby Trogluddite » Sat Nov 24, 2012 5:36 pm

Renderiza wrote:Thanks for sharing this great idea and of course to the people that helped you make it better as well!

Thankyou for your kind words and feedback. :D

I'm just investigating the "add_style" method now, which allows the selection of a style from a standard style definition file from a HDD library - to get around the limitation that the 'favourites' must be resident in the current model.
I wonder if that could be useful too for your sky system - allowing a folder of styles with indexed names to be installed alongside your plugin, so that all the necessary visual settings are automatically available. AFAIK, this is something that can't be done with scenes, as they are specific to a particular model.
0

Trogluddite 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Styles Favourites (v01)

Postby renderiza » Sat Nov 24, 2012 10:18 pm

Trogluddite wrote:I wonder if that could be useful too for your sky system - allowing a folder of styles with indexed names to be installed alongside your plugin, so that all the necessary visual settings are automatically available. AFAIK, this is something that can't be done with scenes, as they are specific to a particular model.


Hi,

This defenetly sound like a very usefull feature!

Not sure if having multiple styles preloaded on to pages is less eficiant in maneging memmory & cpu than loading styles from external file. I say this because there is a point when you are creating animations were lag start to become an issue and if your proposed way of loading styles is better then I am all for it.

Another thing that I will like to know is if loading styles the way you propose can have a transition time of 5 sec for example to blend from one to another like you do with pages?

Cheers
0
User avatar
renderiza 
Premium Member
Premium Member
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Plugins

Who is online

Users browsing this forum: chrisblue and 129 guests

Visit our sponsors: