Reply to topic  [ 3 posts ] 
Not so "read only" 
Author Message
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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?

_________________
philip


2012-02-12 01:20:52
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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

_________________
philip


2012-02-12 01:24:39
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
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


2012-02-13 13:47:47
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software