herbieherb Posted April 16, 2019 Share Posted April 16, 2019 I am trying to make a script that exports an image object to a specified file path. Everything works well but vs.ExportImageFile(hImage, path) does nothing. Here is the script: ________________________________________________________ #Get selected bitmaps crit_ = '(((SEL=TRUE) & (T=BITMAP)))' out_list = [] def Add_Handle(obj): out_list.append(obj) vs.ForEachObject(Add_Handle,crit_) #GetFirstImage hImage = out_list[0] #Choose path fileName = vs.PutFile('Choose path:', 'image.bmp') #Exort Image to path vs.ExportImageFile(hImage, fileName) vs.Close(fileName) ________________________________________________________ And an example file: export image.vwx Quote Link to comment
Marionette Maven Marissa Farrell Posted April 16, 2019 Marionette Maven Share Posted April 16, 2019 vs.PutFile() is used for text files, but you want to create an image file. I suggest building your path using vs.GetFolder() You also will not need to use vs.Close() after making this change. fileName = vs.GetFolder('Choose path:')[1] + 'image.bmp' (You need to extract the second output from GetFolder, which is why the [1] is after it.) Quote Link to comment
herbieherb Posted April 17, 2019 Author Share Posted April 17, 2019 Thx a lot. This worked well. Here is the file with the scripts that export images directly. I had to use two scripts for jpg and png as i couldn't find out the image type. export image.vwx Is there a way to find out if an image is a png or a jpg? Quote Link to comment
MullinRJ Posted April 17, 2019 Share Posted April 17, 2019 3 hours ago, herbieherb said: Is there a way to find out if an image is a png or a jpg? Yes. This one liner will show the compression used on a placed image: vs.Message(vs.GetObjectVariableLongInt(vs.FSActLayer(), 532)) # 1 = JPEG, 2 = PNG Raymond 1 Quote Link to comment
herbieherb Posted April 17, 2019 Author Share Posted April 17, 2019 Thank you. Here's the revised script that distinguishes between jpg and png automatically: export image.vwx Quote Link to comment
herbieherb Posted April 29, 2019 Author Share Posted April 29, 2019 Luke from the german forum added a name generator to the script. So the filenames automatically get a date stamp and a overwrite should not happen anymore. export image.vwx Quote Link to comment
line-weight Posted June 7, 2019 Share Posted June 7, 2019 Any chance of back-saving this in VW2018 format? Quote Link to comment
herbieherb Posted June 7, 2019 Author Share Posted June 7, 2019 I have extended the script so that rendered viewports can now also be saved directly as images. The script now takes the name of the object as prefix of the file name. Here is the current script: export image v2018.vwx export image v2019.vwx 2 Quote Link to comment
line-weight Posted June 7, 2019 Share Posted June 7, 2019 30 minutes ago, herbieherb said: I have extended the script so that rendered viewports can now also be saved directly as images. The script now takes the name of the object as prefix of the file name. Here is the current script: export image v2018.vwx export image v2019.vwx I've just tried running this in one of my files... but get this error message That seems to happen whether I try it on a bitmap image, or on a viewport (have tried both Renderworks and OpenGL vports) Quote Link to comment
herbieherb Posted June 7, 2019 Author Share Posted June 7, 2019 Found the issue. Selected objects from other layers interfere with the script somehow. I'll try to fix it. 1 Quote Link to comment
herbieherb Posted June 7, 2019 Author Share Posted June 7, 2019 Fixed it: export image v2019.vwx export image v2018.vwx Quote Link to comment
line-weight Posted June 7, 2019 Share Posted June 7, 2019 1 hour ago, herbieherb said: Fixed it: export image v2019.vwx export image v2018.vwx Hm... for me I am still getting the same error message. Quote Link to comment
herbieherb Posted June 7, 2019 Author Share Posted June 7, 2019 Still had a bug this one fixes it hopefully: 😁 export image v2019.vwx export image v2018.vwx 1 Quote Link to comment
line-weight Posted June 7, 2019 Share Posted June 7, 2019 41 minutes ago, herbieherb said: Still had a bug this one fixes it hopefully: 😁 export image v2019.vwx export image v2018.vwx Works perfectly now - amazing! Thanks so much for this - I will start using it - it'll save me an immense amount of time faffing around. Quote Link to comment
Andy Broomell Posted June 7, 2019 Share Posted June 7, 2019 I've done a few quick tests and this appears to work really well! This seems to satisfy a simple function that people have requested repeatedly from VW for years, so thank you for taking the time to create this! Question - is it possible for a script like this to be made to work on multiple viewports at once? For example, if I have a grid of 12 renderings and I want to save out the images from all 12 at once? Quote Link to comment
herbieherb Posted June 11, 2019 Author Share Posted June 11, 2019 (edited) Yes, that should be possible, but it requires some work. I will take a look at it on occasion. Until then you could integrate the script as a menu command into your VW-UI. Then just shortcut it to use the script faster. Edited June 11, 2019 by herbieherb Quote Link to comment
Popular Post herbieherb Posted June 26, 2019 Author Popular Post Share Posted June 26, 2019 Here is a new version of the script: New features: exports All selected viewports and images at once gives unnamed images a name within Vectorworks which is also used as filename appends a version number to every exported object enhanced error messages when invalid objects are selected selects invalid and not exported objects after execution export images 1.0 v2018.vwx export images 1.0 v2019.vwx 4 1 Quote Link to comment
Andy Broomell Posted June 27, 2019 Share Posted June 27, 2019 Amazing, thank you herbieherb! The ability to export multiple viewports, plus the naming improvements are all really fantastic. By the way, before adding the script to my workspace as a command, I put a pound sign in front of lines 28 and 29, since I want to be able to export out-of-date viewports as well. I know very very little about coding, but this seemed to work 🙂 2 Quote Link to comment
line-weight Posted August 13, 2019 Share Posted August 13, 2019 I've just been using this too - thank you very much @herbieherb Like @Andy Broomell I'd like to be able to export out-of-date viewports, so I have also disabled lines 28 and 29 (using a £ sign didn't work for me, but just deleting them did) One comment, if you run the script, but then click 'cancel' instead of 'open' in the dialogue asking you for the file location, the image is not exported (as expected) however a message saying an image has been exported is returned nonetheless. 1 Quote Link to comment
herbieherb Posted August 13, 2019 Author Share Posted August 13, 2019 Thx for the bugreport. I'll check it out when I have some free space. Quote Link to comment
herbieherb Posted August 13, 2019 Author Share Posted August 13, 2019 1 hour ago, line-weight said: (using a £ sign didn't work for me, but just deleting them did) Use # instead of £ Quote Link to comment
line-weight Posted August 13, 2019 Share Posted August 13, 2019 1 minute ago, herbieherb said: Use # instead of £ Ah - I see, it's an American vs UK English translation issue! 1 Quote Link to comment
scottmoore Posted September 7, 2019 Share Posted September 7, 2019 Brilliant HerbieHerb!! 1 Quote Link to comment
line-weight Posted June 15, 2020 Share Posted June 15, 2020 (edited) @herbieherb I am continuing to use this scriptand it's very useful. Thank you. There's something strange I have noticed. I expect this is something in Vectorworks, not a problem with your script, but I wonder if it makes any sense to you. I will export a render viewport, and I'll get a PNG image with a certain size, let's say 2000px wide and 1000px high. I then do some kind of edit of the geometry that the viewport is looking at, and re-render it. And then I export it using the script again. And this time I will get a viewport that is 2000px wide and 1019px high (or similar). It'll be a slightly different size, and from what I can make out, the crop is the same, the image is just squashed or stretched very slightly. Surely this shouldn't happen - the viewport should produce the same pixel dimension image each time, no? Edited June 15, 2020 by line-weight 1 Quote Link to comment
herbieherb Posted June 16, 2020 Author Share Posted June 16, 2020 (edited) This is really weird. But I can reproduce it here. It's not the script. It already gets the different sized images from Vectorworks. So I can reproduce that too. The exact same viewport with the exact same content rendered and then converted into an image almost always results in a slightly different image size. Tested with ~4960x3510 pixels I have variations of ±1 pixel in Y-direction and even ±9 pixels in X-direction. Edited June 16, 2020 by herbieherb Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.