Jump to content
herbieherb

ExportImageFile does nothing

Recommended Posts

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

Share this post


Link to post

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.)

Share this post


Link to post

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?

Share this post


Link to post
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

  • Like 1

Share this post


Link to post

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

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×