in my current workflow (writing in Scrivener with MultiMarkdown formatting; exporting as .fodt to keep all the style information intact; importing into Nisus Writer Pro), I encountered a problem with images.

For MMD, the image info is included in the source file like this:

![image caption text][link_to_image_info]

and then later in the file

[link_to_image_info]: /Pictures/image.png width=600px

In Nisus Writer Pro, the images are not included; instead, there's a floating frame with just the caption text.
For now, I'm manually replacing each of these frames with the correct image and caption text, then switch the image placement to "Inline with text", apply a style to the image, apply another style to the caption.

It would be great to have a Macro that would automate this; here's what I imagine (without knowing if it's possible):

I could encode the image information like IMG[image caption text][/Pictures/image.png] or so (so MMD won't mess it up).
The macro could then parse the text for this format, load and place the referenced image as "Inline with text" with the "Image" style applied, and the paste the caption underneath, with the "Caption" style applied...

So I'd be happy to know if this is possible, and would be thankful for any pointers in the good direction!

I still have to absorb A a bit I guess (and see in the examples how things connect)...
The macro I had already tried (including trying to understand it ).

In the previous way that I referenced images in Scrivener it worked well:

![My boxed image][image]
[image]: /imagetester/images/DD3.png

In this case, the image would be placed in a figure, and your script would list these.

in the inline-referencing way like this: ![My inline image](/imagetester/images/DD3.png) the macro gives an error message (probably because no content floats).
To understand how I can use it for my problem, I'll need a nbit more tinkering.

Now I try to put the image caption / link into scrivener in a way that it will not be transformed by MultiMarkdown, like this:
[My inline image]IMG(/imagetester/images/DD3.png)

But if I then try to insert the caption (which should be in $1), the caption replaces the images (as these are the selected)...

Would you have any tip how I can insert the caption after the image, and preferably apply the style 'Image' to the image, and 'Caption' to the caption? Then I would be saved
(text deadline is approaching...)

It applies the 'image' style well, and also the 'caption' style is applied.
Unfortunately - and that is the last remaining problem - also to the style *following* the caption.
Mostly those are headings, which then become unheaded...

without the need for first getting the style object. This is the same as invoking the menu command.

But now to your actual problem.

janklug wrote:It applies the 'image' style well, and also the 'caption' style is applied.
Unfortunately - and that is the last remaining problem - also to the style *following* the caption.
Mostly those are headings, which then become unheaded...

Your macro edits the file much as the user would. It finds the next image specification, deletes, pastes in the image, applies the style.

Note that of course now you will have to apply the style afterwards. Also note that since you apparently want an extra new line, I just added it to the "Insert" command.

And in fact you really have to think about how you manipulate the text, when you do things this way. Because the Nisus macro language isn't really set-up to allow you to move around the file the way a user would. And this is probably a good thing, because you don't really want to write macros that edit via the visual interface (What we used to call the "light show" in the Nisus Classic days). The better approach is to work globally using objects.

Grab the document object

Grab the document text object

Find all the edit locations

Change the edit locations (globally or via a loop)

Save the edit locations (in an array)

Select the edit locations in one go

Apply the formatting in one go

Macros written like that will have much better performance, they will be fast even on very large documents. They'll also be easier to comprehend and maintain.