Export images to saved file location with file name
-
thanks - i think i forgot to mention the image name has to be the same as the sketchup file just saved
that's why i was trying: model_filename = File.basename(model.path)
(i thought i was getting the name of the file in that particular folder)
-
To get the 'root' of the model name you can use
title = model.title
then to make the full image path...
myimage=File.join(newfolder, title+'.png')
-
ok TIG, thanks, i think i understand it - i shall look into it (won't take more than a few months)
-
this does produce an image but the name is empty - only '.png'
title = model.title
myimage=File.join(dir2, title+'.png')
view.write_image( myimage, 600, 600, true )anyway at least i know i'm on a better track now.
-
Did that happen in a new (unsaved) file? Then the model has no file name and the title is empty. You would then need to provide a fallback name like:
title = model.title title = "untitled" if title.empty?
Eventually we would hve to check if such a file already exists and iterate until the file name is unique. -
yes, it already has a name, this is what i'm running after making a directory and saving the file..
dir=Dir.mkdr(File.join(model_dirname, 'TEST')) model.save(File.join(dir, File.basename(skp))) model_filename = File.basename(model.path) imager=File.join(dir, model_filename+'.png') view.write_image( imager, 600, 600, true )
-
BUT model.title and model.path etc are empty [''] UNLESS it's been saved.
Using the model.save() does NOT change the current model, it just saves a copy of it as it is...
So suspect you haven't saved the base SKP.
therefore the save you are doing is '.png', and the folder is probably not set wither
Therefore you need to do something to establish a 'title' some other way...Tip, to see what is going on run with the Ruby console open and put a temporary '
p
' in front of each reference you are setting to see what you get - e.g.p title=model.title
should return"mymodelname"
NOT""
- which shows it's not been saved... -
can't i just save it with the name of the copy then?
-
If you know that the file is saved to
File.join(dir, File.basename(skp)))
,
you can also write the image toFile.join(dir, File.basename(skp, ".skp")+".png"))
File.basename
understands the second argument as an extension and strips it off; if the extension was unknown, we could obtain it withFile.extname
("a_model.skp")
or a regular expression. -
friends, let me say.. you are not from this planet...! (..but i'm very glad you landed!)
-
I recommend a minor adjustment
File.join(dir, File.basename(skp, **".*"**)+".png"))
- it is safer, because a file ending with '.SKP' would fail == not matching ".skp"...
-
ok, TIG, i'll see what i can do.
this is what i'm getting towards: (and of course TIG has already done the biggest part)
i'll call it a batcher:
starts and asks for some options:
views to make = top, front, side, hi angle
delete all materials from model entities - on/off
shadows - on/off
fov value
layer name (to put the file contents into it)when it starts, it opens a folder to choose and processes all files in it.
process does:
delete all guides,
purge all unused entities,
create a layer (named from previous options) and move everything in it,
set a custom style
go to the first view (ie. top) and save the model to a subfolder (top),
save a transparent png image of the same view and place it in the same subfolder (top),then moves to the next file...
-
I have run into an issue when I'm working on the same image on two different computers - when exporting the Sketchup image, the Width & Height are locked (when one is edited, the other automatically matches that computer's viewport ratio). I am trying to find a way to export an image with independently filled in Width and Height resolutions. This seems to be the closest Ruby I could find to fixing my issue. Is there any way to modify this to get what I'm looking for? I export so often that I would like to create a button on a new toolbar to keep at the top of the screen, instead of entering the Ruby Console every time. Is there any way to do this?
Advertisement