I’m looking at the Ruby docs, but I don’t get it.
I think it says do this, but it doesn’t work.
styles = Sketchup.active_model.styles
style1 = styles[0]
style2 = styles[“00Default Style.style”]
I’m looking at the Ruby docs, but I don’t get it.
I think it says do this, but it doesn’t work.
styles = Sketchup.active_model.styles
style1 = styles[0]
style2 = styles[“00Default Style.style”]
That code snippet assign variables to the styles in the collections of model styles.
Are you trying to change the active style?
Or modify it’s properties?
I am trying to finish writing a batch script, that changes all the files to the default style. I have written the rendering options before;
Sketchup.active_model.rendering_options[“BackgroundColor”] = 210,208,185
Sketchup.active_model.rendering_options[“BandColor”] = 0,0,0
Sketchup.active_model.rendering_options[“ConstructionColor”] = 0,0,0
Sketchup.active_model.rendering_options[“DepthQueWidth”] = 4
Sketchup.active_model.rendering_options[“DisplayColorByLayer”] = false
ETC, but the script doesn’t always change the style correctly. But everything else works ok. I’m just not sure, how to tell it to change the style to the default. Instead of all the rendering options code, I would just like to point to the default style.
Thanks.
Batch convert to SU7.rb (6.2 KB)
Do you have specific example?
The default? There is no absolute default. Each template has their own style. The style you try to switch to - is it loaded into the model?
These are files I download from the warehouse, and with this batch script, I change the settings to the settings I like, 1/64 inch accuracy, etc. They are all saved in different styles, measurements, etc. The script does everything I want, but it won’t always change the style correctly. I just want to change the style, on all the files to
00Default Style.style.
It is located here…C:\Program Files (x86)\Google\Google SketchUp 7\Styles\Default Styles\00Default Style.style
this works on a mac, but only if I use Test.FindFile…
default_styles = Sketchup.find_support_files("","Styles").grep(/Default Styles/)
change_style = Test.FindFile(default_styles[0],"00Default Style.style")
styles = Sketchup.active_model.styles
status = styles.add_style(change_style, true)
styles.purge_unused
you still need to set your Units/Shadows etc, separately…
john
Thanks John.
Didn’t work. Maybe, it’s just not an option.
does this fail with a hardcoded path?
it should work from v6 on…
styles = Sketchup.active_model.styles
status = styles.add_style "C:\Program Files (x86)\Google\Google SketchUp 7\Styles\Default Styles\00Default Style.style ", true
UI.messagebox ('A style was added: ’ + status.to_s)
john
It doesn’t work. It says: false. It is the right path though.
When I just use…
styles = Sketchup.active_model.styles
status = styles.add_style "C:\Program Files (x86)\Google\Google SketchUp 7\Styles\Default Styles\00Default Style.style "
I get Run aborted. Error: (eval):2:in ‘add_style’: wrong number of arguments(1 for 2)
the second arg is the ,true at the end of line…
also I just noticed the escaping in the path isn’t showing correctly in the forum…
I believe you need \\ to escape the separator, and wrapping in args in () won’t hurt…
styles.add_style( “C:\\Program Files (x86)\Google\\Google SketchUp 7\\Styles\Default Styles\\00Default Style.style”, true )
john
Still not working. I give up. Shouldn’t be this hard to add a default style.
Thanks for the help !!
It is easier to just use Ruby forward slashes, (or single-quoted strings if you insist on backslashes.)
As Dan said…
A file-path should usually use forward-slashes /
as separators - "C:/P..."
or 'C:/P...'
Inside ""
or ''
[double/single quotes]
You can use a back-slash \
BUT then inside ""
you’ll then need to escape ALL of them as "C:\\P..."
, note that 'C:\P...'
will work too…
It’s just easier to use a /
@DanRathbun or @TIG, why would my first example fail on windows?
do you not have TTest.FindFile or is the problem SU v7 related?
john
You have NOT escaped all of the \ as \\ !
There are several lone \ !!
Read your text more carefully…
@TIG
I was referring to the first example, that has no path separators…
that’s all left up to ruby/SU…
default_styles = Sketchup.find_support_files("","Styles").grep(/Default Styles/)
change_style = Test.FindFile(default_styles[0],"00Default Style.style")
styles = Sketchup.active_model.styles
status = styles.add_style(change_style, true)
styles.purge_unused
john
@John: Test::FindFile
is not documented.
The Trimble team does add some methods to the Test
module for internal use only.
Can your example be rewritten using one of the Enumerable
methods mixed into the Array
class ?
[quote=“john_drivenupthewall, post:17, topic:10020”]
I was referring to the first example, that has no path separators…that’s all left up to ruby/SU…
default_styles = Sketchup.find_support_files(“”,“Styles”).grep(/Default Styles/)
change_style = Test.FindFile(default_styles[0],“00Default Style.style”)
styles = Sketchup.active_model.styles
status = styles.add_style(change_style, true)
styles.purge_unused
[/quote] So try…
default_style = Sketchup.find_support_file("00Default Style.style", "Styles/Default Styles")
styles = Sketchup.active_model.styles
status = styles.add_style(default_style, true)
styles.purge_unused
Assuming that the subfolder ‘Styles/Default Styles’ and the style ‘00Default Style.style’ exist it WILL work.
You seem to be making this more complex than it needs to be …
no doubt …
it was a quick cobble and find_support_file is very fickle on a mac with sub-directories…
your version does work and avoids the need for two bites at the cherry…
@DanRathbun I knew it was undocumented but I couldn’t find the sub-dir that TIG’s version does …
cheers to both
john