nisus.com
https://www.nisus.com/forum/

Not so "read only"
https://www.nisus.com/forum/viewtopic.php?f=17&t=4812
Page 1 of 1

Author:  phspaelti [ 2012-02-12 01:20:52 ]
Post subject:  Not so "read only"

According to the Macro Reference the properties of the Image Object are all "read only". In defiance of this advice I wrote the following macro:

Code:
Select Document Start
while Select Next Image
$img = Image.selectedImage
$img.width = 200
end


Nothing seemed to happen, but when I checked the metrics of the images, they all had the value "200" ! This was despite the fact that the images displayed unchanged.
I saved the file and reopened, and now all the images displayed with a width of 200 pt. So apparently the change was for real. Why doesn't the display update? (Maybe because one isn't supposed to do such things :lol: ) Is there any way to get the display to update without saving/closing/re-opening?

Author:  phspaelti [ 2012-02-12 01:24:39 ]
Post subject:  Re: Not so "read only"

Oh, and here is a smarter macro to do this kind of thing. Even though the width/height are linked, changing the width in this manner does not change the linked height, so it is necessary to do it by hand.

Code:
$wid = 200
Select Document Start
while Select Next Image
$img = Image.selectedImage
$ratio = $wid / $img.width
$img.height = $img.height * $ratio
$img.width = $wid
end

Author:  martin [ 2012-02-13 13:47:47 ]
Post subject:  Re: Not so "read only"

It's true: the image width/height properties can be changed via a macro, but as you've discovered it's not entirely reliable, which is why the macro guide doesn't advertise it. I think the only issue was that the images don't update/redisplay, though there may be some problems with undo as well, so you might want to operate on a copy of the document.

One workaround to the stale display is to make some trivial formatting change to get NWP to recognize the image resize, eg:
Code:
$image.width = 999
Bold # force NWP to notice the new image size
Bold # back to normal

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/