Whenever I insert an image into my document, I would like it to have a "frame" or a shape stroke (hairline).
Is there a way to appl this to an image and save these settings as a style element? Or a macro that'd allow me to apply the shape stroke to inserted images?
Save shape styles?
Re: Save shape styles?
This is an area of NWP that is a total mess. The behavior is just all over the place.
Let's consider some things that work.
1. Images can be inline or floating. If your image is floating, you are in luck! You can use the menu command "Edit > Copy > Copy Shape Appearance". Then you can paste them on other floating images (with "Edit > Paste > Paste Shape Appearance"
2. What if your image is inline? In that case those Shape Appearance commands are disabled. Apparently the stroke on an image is different from that of a floating image.
You might think you could work around this problem like this:
3. What about macros?
This is a total mine field. Generally Nisus Macro language has an elaborate set of commands and features to set strokes, but these commands are extremely ideosyncratic. The features for the stroke are set using LineAttributes. You will find them described in the Table Objects section of the Macro Language Reference. For table cells this works like a charm, though for some reason there are two sets of commmands to set them:
Now you might have thought that you could do the same for floating content objects, and you can up to a point. Floating content objects have a macro property .strokeAttributes (more tricky naming) which return a LineAttributes object. However this property is described as following value semantics which would seem to mean that it can't be set. This is either a feint to keep out the unwary, or an undocumented change in behavior. In fact
seems to work just fine, except…
When I tried to following very simple code:
This is the result I got:
Before After There doesn't seem to be any way to control which edges of the floating content to apply the attributes to.
Let's consider some things that work.
1. Images can be inline or floating. If your image is floating, you are in luck! You can use the menu command "Edit > Copy > Copy Shape Appearance". Then you can paste them on other floating images (with "Edit > Paste > Paste Shape Appearance"
2. What if your image is inline? In that case those Shape Appearance commands are disabled. Apparently the stroke on an image is different from that of a floating image.
You might think you could work around this problem like this:
- Convert the image to floating
- Copy Shape Appearance
- Convert back to inline
- Select other image
- Convert to floating
- Paste Shape Appearance
- Convert back to inline

3. What about macros?
This is a total mine field. Generally Nisus Macro language has an elaborate set of commands and features to set strokes, but these commands are extremely ideosyncratic. The features for the stroke are set using LineAttributes. You will find them described in the Table Objects section of the Macro Language Reference. For table cells this works like a charm, though for some reason there are two sets of commmands to set them:
- To get them from a single table cell use .lineAttributesForEdge
- To set them on a single table cell use .setLineAttributesForEdge
- To set them for a selection of table cells use .applyLineAttributesToEdges

Now you might have thought that you could do the same for floating content objects, and you can up to a point. Floating content objects have a macro property .strokeAttributes (more tricky naming) which return a LineAttributes object. However this property is described as following value semantics which would seem to mean that it can't be set. This is either a feint to keep out the unwary, or an undocumented change in behavior. In fact
Code: Select all
$myFloatingContent.strokeAttributes = $myLineAttributes
When I tried to following very simple code:
Code: Select all
$doc = Document.active
$fcs = $doc.allFloatingContents
$lineAttributes = $fcs[0].strokeAttributes
$fcs[1].strokeAttributes = $lineAttributes
Before After There doesn't seem to be any way to control which edges of the floating content to apply the attributes to.
philip
Re: Save shape styles?
Finally I should also mention macro control of stroke attributes for inline images.
Since the stroke attributes can be set using menu commands, you can hard-code a specific set of attributes with a macro like this:
This will apply the relevant styling to the selected image.
Writing a macro to pick up the formatting from an existing image and transfer it to another might be possible, but it might be a bit tricky.
Since the stroke attributes can be set using menu commands, you can hard-code a specific set of attributes with a macro like this:
Code: Select all
$lineStyleMenu = Menu.menuAtPath(":Tools:Shape Stroke:Line Style").submenus[5]
$lineStyleMenu.state = 1
Shape Stroke:Thickness:6 pt
Shape Stroke:Color:Fuchsia
Writing a macro to pick up the formatting from an existing image and transfer it to another might be possible, but it might be a bit tricky.
philip
Re: Save shape styles?
Wow, super helpful tips! Thank you very much for taking the time!
Meanwhile I have been using KeyboardMaestro to accomplish what I want, but I'll review your tips thoroughly when I am in front of my computer later.
Meanwhile I have been using KeyboardMaestro to accomplish what I want, but I'll review your tips thoroughly when I am in front of my computer later.
Re: Save shape styles?
Confusion on my part. Of course this is exactly how value semantics are supposed to work. The .strokeAttributes property retrieves a copy of the currently set line attributes and can be set using the .strokeAttributes = … method.phspaelti wrote: ↑2022-02-28 07:45:57 However this property is described as following value semantics which would seem to mean that it can't be set. This is either a feint to keep out the unwary, or an undocumented change in behavior. In factseems to work just fine,Code: Select all
$myFloatingContent.strokeAttributes = $myLineAttributes
What remains though is the problem that one doesn't seem to have control over which edges the attributes are to apply to.
philip
Re: Save shape styles?
This is an interesting conundrum. It doesn't look like there is any way, even manually, to set a different stroke for a shape depending on the side, or "edge" as the macro language calls it.
It looks like setting the lineAttribute property sets all six possible edges that a LineAttribute object may apply to. LineAttributes exist for table cells, paragraph borders, and likely page borders as well, though I'm not sure on that. But with table cells, you can specify an edge to apply your lineAtribute to. I would assume that you would grab the "edge" of a paragraph and set its lineAttribute object as well.
Would that work in an image? Grab it's left edge, says, then set only its lineAttribute object? It doesn't appear possible, to be frank.
Of course Nisus is not meant to be a serious graphics program, and if your needs are such that you need differing borders around an image, it is likely best to add them to the image in your graphic program and then pasting it into Nisus.
If you have OmniGraffle, you can create some graphics there and paste them into Nisus and use "link back" to edit the graphic in Omnigraffle and have it automatically update in Nisus.
Neat feature, sort of like Publish and Subscribe from ye olde System 7 days. Sadly, not nearly as well supported nowadays.
It looks like setting the lineAttribute property sets all six possible edges that a LineAttribute object may apply to. LineAttributes exist for table cells, paragraph borders, and likely page borders as well, though I'm not sure on that. But with table cells, you can specify an edge to apply your lineAtribute to. I would assume that you would grab the "edge" of a paragraph and set its lineAttribute object as well.
Would that work in an image? Grab it's left edge, says, then set only its lineAttribute object? It doesn't appear possible, to be frank.
Of course Nisus is not meant to be a serious graphics program, and if your needs are such that you need differing borders around an image, it is likely best to add them to the image in your graphic program and then pasting it into Nisus.
If you have OmniGraffle, you can create some graphics there and paste them into Nisus and use "link back" to edit the graphic in Omnigraffle and have it automatically update in Nisus.
Neat feature, sort of like Publish and Subscribe from ye olde System 7 days. Sadly, not nearly as well supported nowadays.