Reply to topic  [ 8 posts ] 
Macro keeps sending to document start 
Author Message

Joined: 2014-06-06 04:32:29
Posts: 7
Hi

am very new to macros and eventually managed to write a macro that allows me to put a dark blue border around a graphic (shape) in a document manual for some software (I use screenshots taken by Snagit). The macro does everything I want except it always takes me to the start of the document when it finishes - I have no idea why.

I can't find a command to keep me at the same place in the document as the graphic I have just worked on - nor can I understand why it takes me to the start.

Here is the macro

#This macro puts the graphic (shape) in the centre with a blue border
#and with text wrapped above and below only.
#The next command toggles so it’s important to make sure it’s off first
#normally it is when you first insert the shape
Tools:Shapes:Wrap Text Around Shape
Tools:Shape Metrics:Align Center
Tools:Shapes:Text Wrapping:No Text on Either Side
#Sets the Anchor to the Paragraph Nearby
Tools:Shapes:Adjust Anchor When Shape Repositioned
#Chooses the Border Around the Shape
Tools:Shape Stroke:Line Style:
Tools:Shape Stroke:Thickness:1½ pt
Tools:Shape Stroke:Color:Dark Blue


I admit I am struggling to understand all this at the moment. Any help would be wonderful.

Mike


Attachments:
File comment: This is the macro file
Edit Shape.nwm [17.97 KiB]
Downloaded 158 times
2014-06-06 04:58:48
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Hello Mike,
you picked the most tricky area of Nisus to write your first macro :)

The business of jumping to the beginning of the document has to do with the fact that you are starting with an inline selection and then converting that selection to a floating object. I think that Nisus probably could have implemented a more user friendly behaviour, but maybe there is something here that I am overlooking.

But anyhow to your problem: you can improve the behaviour by having the macro set the selection at a place of your choice. I am attaching a modified version which selects the anchor of the new floating image. To do this you need to use Nisus' macro language (see the reference in the 'Help' menu). Have a look and if you have any questions let me know.

Attachment:
Edit_Shape_with_Select.nwm [18.19 KiB]
Downloaded 159 times


best
Philip

_________________
philip


2014-06-07 03:50:05
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
And here is another version which selects the floating image instead.
Attachment:
Edit_Shape_with_Select.nwm [18.1 KiB]
Downloaded 136 times


The more I think about this, the more I am convinced that Nisus' behaviour is really a bug. If you look at my code, you'll see it looks pretty redundant.

_________________
philip


2014-06-07 03:57:49
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
mikegrace wrote:
I can't find a command to keep me at the same place in the document as the graphic I have just worked on …

The command that you can use to move the view to the current selection is:
Code:
Edit:Select:Flash Selection

That would work for your macro too.

_________________
philip


2014-06-07 04:12:31
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Another point:
mikegrace wrote:
#Chooses the Border Around the Shape
Tools:Shape Stroke:Line Style:
Tools:Shape Stroke:Thickness:1½ pt
Tools:Shape Stroke:Color:Dark Blue

I admit I am struggling to understand all this at the moment. Any help would be wonderful.


I assume that the line:
Code:
 Tools:Shape Stroke:Line Style:

was an aborted attempt to set the line style?
Again there seem to be a number of bugs and inconsistencies here in the Nisus Macro language. With inline images the "Line Style" menu is disabled, even though it shouldn't be. :( Since the menu items are graphical, it's kind of hard to type them as macro commands. And while the macro language now has name equivalents ("Solid", "Double", etc.) there is no way to use these names for images or floating objects.
There is however a way to set the line style, if you do it like this:
Code:
$lineStyles = Menu.menuAtPath “:Tools:Shape Stroke:Line Style”
# set line style to "Double"
$lineStyles.submenus[2].activate

Note that ".submenus" is an array, which is 0-indexed. So
    $lineStyles.submenus[0] = "None"
    $lineStyles.submenus[1] = "Solid"
    etc.

PS: Note this works even with inline images, even though those submenus are disabled :!:

_________________
philip


2014-06-07 18:27:45
Profile

Joined: 2014-06-06 04:32:29
Posts: 7
Hi Everyone

I have just returned from visiting my mum (she is very old now and in a care home just south of London) and it's evening here in the UK - so I will work on the replies to my post tomorrow.

But I would just like to include a huge thank you to everyone who responded, and I will reply to you individually tomorrow.

Mike


2014-06-08 09:54:22
Profile

Joined: 2014-06-06 04:32:29
Posts: 7
Hi Philip

First, my apologies - in my e-mail last night I just wanted to thank people and didn't notice that all the e-mails came from you - so I am sorry it was a rather generic e-mail that apparently thanked a number of people when I should have only thanked you. So thank you for the time and effort you put into this.

First - solving the problem. I found your second version of the macro worked the best for me - the one that went
# Select the image
$img = Image.selectedImage
$doc = Document.active
$doc.setSelection $img

I didn't understand your email about Edit:Select:Flash Selection - it didn't seem to work for me and I think it's an area I haven't quite grasped yet.

Your latest e-mail on line style was very welcome, and it works. What I don't understand is that the macro actually worked without the new code you provided (although it was really useful seeing the new code). So it seems my original attempt of Tools:Shape Stroke:Line Style was working, although it was so vague. I was getting a line around the graphic when the macro ran. Odd.

Anyway - the main thing is I now have a macro that works exactly how I want it - and I've understood a bit more about writing them.

Thanks again.

Mike


2014-06-09 03:01:37
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Hi Mike,
I'm glad you got it working to your satisfaction.
Sorry for the confusing flurry of messages on my part. The problem really is that dealing with floating graphics is one area where Nisus' macro language is not very "stable". So I kept/keep discovering new wrinkles to my ramblings on this topic.
mikegrace wrote:
First - solving the problem. I found your second version of the macro worked the best for me - the one that went
# Select the image
$img = Image.selectedImage
$doc = Document.active
$doc.setSelection $img

I didn't understand your email about Edit:Select:Flash Selection - it didn't seem to work for me and I think it's an area I haven't quite grasped yet.

Sorry, I thought that would work. Anyhow there really isn't anything to grasp here. This is a bug on Nisus' part plain and simple. There is no reason one should even need to write any code for this.
To be very technical about this, the problem is that when the image is moved from being inline to floating, while the image stays selected, the internal variable that tells Nisus what to display does not seem to get updated correctly: It remains pointed at an (inline) TextSelection, even though the image is now floating. Since that selection is gone, Nisus defaults to the beginning of the document instead.

mikegrace wrote:
Your latest e-mail on line style was very welcome, and it works. What I don't understand is that the macro actually worked without the new code you provided (although it was really useful seeing the new code). So it seems my original attempt of Tools:Shape Stroke:Line Style was working, although it was so vague. I was getting a line around the graphic when the macro ran. Odd.


Well actually the line:
Code:
Tools:Shape Stroke:Line Style:

in your macro doesn't do anything. Or more precisely, it sets the line style of the image to "None" (which it probably already was). The reason why your code "worked" is that you wanted a solid border. And since the next line in the macro sets the line thickness, and a line thickness is pointless for the "None" border, Nisus changes the border to "Solid". The line which sets the color would also trigger a switch to a default solid border. (It would also switch to a default 1pt line thickness, if you hadn't already set the thickness.)
So if you wanted anything other than a solid border, you would have to use the menu object work around. Hopefully Nisus will implement more straightforward commands for this kind of stuff in some (near :wink: ) future update.

mikegrace wrote:
Anyway - the main thing is I now have a macro that works exactly how I want it - and I've understood a bit more about writing them.

Indeed.

_________________
philip


2014-06-09 05:32:27
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 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