Not so "read only"

Get help using and writing Nisus Writer Pro macros.
Post Reply
User avatar
phspaelti
Posts: 916
Joined: 2007-02-07 00:58:12
Location: Japan

Not so "read only"

Post by phspaelti » 2012-02-12 01:20:52

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?
philip

User avatar
phspaelti
Posts: 916
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Not so "read only"

Post by phspaelti » 2012-02-12 01:24:39

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
philip

User avatar
martin
Official Nisus Person
Posts: 4287
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Not so "read only"

Post by martin » 2012-02-13 13:47:47

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

Post Reply