Select Style for drawing
-
Is there a way to select a style for my drawing?
I would like it to use "Construction Documentation Style"
Here is the code I am using to save the image.
` model = Sketchup.active_model
entities = model.active_entities
Sketchup.send_action("viewIso:")
view = model.active_viewPuts in SketchUp install directory by default
status = view.write_image "test.jpeg"
keys = {
:filename => "S:/Stairs/Stair Pics/write_image.jpeg",
:width => 500,
:height => 400,
:antialias => false,
:compression => 0.5,
:transparent => false
}
model = Sketchup.active_model
view = model.active_viewnew_view = view.zoom_extents
view.write_image keys`Thanks
-
Your code seems to be saving an image of the model.
And I expect that's not what you want ?The API includes several distinct methods for affecting a model's 'Styles'...
http://ruby.sketchup.com/Sketchup/Styles.html
http://ruby.sketchup.com/Sketchup/Style.html
http://ruby.sketchup.com/Sketchup/Page.html#style-instance_method
http://ruby.sketchup.com/Sketchup/Page.html#use_style%3F-instance_method
etcTo 'load' a particular Style you need to get the path to its
.style
file...
There are ways to find this in Ruby...
But on a PC I think it's easy to get through:
desired_style_file_path = 'C:\ProgramData\SketchUp\SketchUp 2018\SketchUp\Styles\Default Styles\08Construction Documentation Style.style'
Then use that to set the Style ??
-
Thanks,
I could not find the actual file location, I was able to right click on the style and save it to a different location, and use that address to for the code.
While this code does change the style.` model = Sketchup.active_model
entities = model.active_entities
Sketchup.send_action("viewIso:")
view = model.active_view#---------------Change Style----------
filename = File.expand_path('C:\Users\dmorrison\Downloads\08Construction Documentation Style.style')
styles = Sketchup.active_model.styles
status = styles.add_style(filename, true)
#-----------------------------Puts in SketchUp install directory by default
status = view.write_image "test.jpeg"
keys = {
:filename => "S:/Stairs/Stair Pics/write_image.jpeg",
:width => 500,
:height => 400,
:antialias => false,
:compression => 0.5,
:transparent => false
}
model = Sketchup.active_model
view = model.active_viewnew_view = view.zoom_extents
view.write_image keys`It does not change in my actual plugin.
The last lines of the plugin to insert the image into excel
` #-----Pictures Insert Code---------------#require 'win32ole'
model = Sketchup.active_model
entities = model.active_entities
Sketchup.send_action("viewIso:")
view = model.active_view
#---------------Change Style----------
filename = File.expand_path('C:\ProgramData\SketchUp\SketchUp 2015\SketchUp\Styles\Default Styles\08Construction Documentation Style.style')
styles = Sketchup.active_model.styles
status = styles.add_style(filename, true)
#-----------------------------Puts in SketchUp install directory by default
status = view.write_image "test.jpeg"
keys = {
:filename => "S:/Stairs/Stair Pics/write_image.jpeg",
:width => 500,
:height => 400,
:antialias => false,
:compression => 0.5,
:transparent => false
}
model = Sketchup.active_model
view = model.active_viewnew_view = view.zoom_extents
view.write_image keys
#------------------------------------
worksheet.pictures.delete
#-----Pictures Insert Code---------------
pic = worksheet.Pictures.Insert('S:\Stairs\Stair Pics\write_image.jpeg')
range = worksheet.Range('a14:e32')
pic.ShapeRange.LockAspectRatio = false
pic.Top = range.Top
pic.Left = range.Left
pic.Width = range.Width
pic.Height = range.Height` -
So you have the Style changing as you hope.
Does your middle code write the images you expect.
You seemingly pointless "test.jpeg
" will go in the current working directory.
To find that usep Dir.pwd
in the Ruby Console...
It might NOT be the main SketchUp folder...
Running the code with the Console open might help spot errors etc...:filename => "S:/Stairs/Stair Pics/write_image.jpeg",
will only work if the folder"S:/Stairs/Stair Pics"
exists - does it ?So is this image getting saved ?
I suddenly realized that you briefly mention v2015 in your code.
So the default Styles are [probably] in another location - I only have >=v2017 on this PC so I can't confirm...I think that the
write_image
method using akey
only works for PNG files in older SketchUp versions - try that PNG file-type and see if it helps...
Saving images as a JPG with akey
etc are only supported in newer SketchUp versions - in older SketchUp versions you need to passoverloads
as arguments listed after the file path...
See here...
http://ruby.sketchup.com/Sketchup/View.html#write_image-instance_methodAlso the
[#]require 'win32ole'
might not work with older SketchUp versions !
It's only been shipped since the Ruby set up changed...
In that case you might need to include an equivalent.so
in your own subfolder and load that manually ?? -
Thanks Tig,
The image does end up in excel, but not with the correct style
-
What version of SketchUp are you using ?
Let's break this down into individual steps.
- Add and activate Style
pause - Export Image
pause - Add Image to Excel
For 1. - does it add and activate the Style as you hope ?
For 2. - does it export an Image using the expected Style [and view, zoom etc] ? Is the actual JPG file what you want ?
For 3. - is there a preexisting Image in the Excel file ? Is the Image imported the one seen in 2. ?
At the moment your "reporting" is clear to you but unclear to the rest of us !
- Add and activate Style
-
Okay, there is something very strange. I spent a lot of time trying to figure out why it would not pause or even show a msgbox as it was going through the code. I commented out the entire code and got nothing, I un-commented just the 1st line and the code produced a drawing, I don't know what code it used as I had all the code commented out.
For example
` UI.menu("PlugIns").add_item("Get From Excel") { get_from_excel }# def get_from_excel
ents=Sketchup.active_model.active_entities
require 'win32ole'
xl = WIN32OLE::connect('Excel.Application')
workbook = excel.Workbooks('Stair_Info_to_Sketchup')
worksheet = workbook.Worksheets(1)
................`
How is this possible? I am going to assume it was is obviously running a code from somewhere else, but I can't locate it.
-
I found it, it was a test .rb file, not a plugin but it did have
def get_from_excel
That is where the plugin was getting the code from.
Thank you,
The style does change now that I am in the correct code.
Advertisement