Save shape styles?

Everything related to our flagship word processor.
Post Reply
ugur
Posts: 7
Joined: 2022-02-13 10:42:28

Save shape styles?

Post by ugur »

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

Re: Save shape styles?

Post by phspaelti »

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:
  1. Convert the image to floating
  2. Copy Shape Appearance
  3. Convert back to inline
  4. Select other image
  5. Convert to floating
  6. Paste Shape Appearance
  7. Convert back to inline
This works up to the last step. At that point NWP removes the Shape Appearance again :(

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
Note the intricate arrangement of prepositions and plurals :P

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
seems to work just fine, except…
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
This is the result I got:
Before
Screen Shot 2022-03-01 at 0.41.51.png
Screen Shot 2022-03-01 at 0.41.51.png (107.97 KiB) Viewed 2122 times
After
Screen Shot 2022-03-01 at 0.42.09.png
Screen Shot 2022-03-01 at 0.42.09.png (112.15 KiB) Viewed 2122 times
There doesn't seem to be any way to control which edges of the floating content to apply the attributes to.
philip
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Save shape styles?

Post by phspaelti »

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:

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
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.
philip
ugur
Posts: 7
Joined: 2022-02-13 10:42:28

Re: Save shape styles?

Post by ugur »

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.
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Save shape styles?

Post by phspaelti »

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 fact

Code: Select all

$myFloatingContent.strokeAttributes = $myLineAttributes
seems to work just fine,
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.

What remains though is the problem that one doesn't seem to have control over which edges the attributes are to apply to.
philip
Vanceone
Posts: 211
Joined: 2013-05-03 07:06:31

Re: Save shape styles?

Post by Vanceone »

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.
Post Reply