Page 1 of 1

Not so "read only"

Posted: 2012-02-12 01:20:52
by phspaelti
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 all

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?

Re: Not so "read only"

Posted: 2012-02-12 01:24:39
by phspaelti
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: Select all

$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

Re: Not so "read only"

Posted: 2012-02-13 13:47:47
by martin
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: Select all

$image.width = 999
Bold # force NWP to notice the new image size
Bold # back to normal