Exporting Images at Set Resolution

So I'm exporting parts of a large map (room battlemaps for Undermountain) and want to always be exporting at a fixed resolution (20 pixels per map unit) but I don't know a way of doing that without doing the math myself. Part of the issue is each map has a different map size. Here's my current process, can anyone think of a better/quicker way to do this?

- Get the part of the map I want to export on the screen
- Turn on Effects
- Measure size of map area I want to export (using DIST2 command)
- Save As, Rectangular JPG, Options, set map export size accordingly (math in my head)
- Set Name
- Select area to be exported

Thanks in advance :)

Comments

  • MonsenMonsen Administrator 🖼️ 81 images Cartographer
    You could write a macro that asks you to define a rectangle, then measures that rectangle, multiplies by 20, sets the export resolution options, and then export that area.
  • Oohh, ok, will be worth my time to figure that out. Will go read up on creating macros :)
  • This intrigued me as its something I do a lot as well. I have got the macro figured out all the way up to the last steps. I cant figure out how to set the export resolution options and then export them. I did find reference to the WBSM command which is supposed to allow macro rectangular export, but I cant figure out how to pass the options in to it.
  • MonsenMonsen Administrator 🖼️ 81 images Cartographer
    edited July 2018
    You need to use the various export setting commands to set the actual settings before calling WBSM, you'll find them listed in this article, WBSM itself only takes the filename and coordinates for the export.
  • LordEntrailsLordEntrails Traveler
    edited July 2018
    OK, much easier than I thought (but I've done CAD macros before). But I've got a challenge I can't find a solution to...

    How can I set the options values for bitmaps?
    I can use either the EXPORT or the GLOBALOPT commands to get to the dialog I need to set the variables for, but macros can't set variables in a user dialog...
    I need to set Pixel Size Width & Height values.

    For reference, this is the macro so far;

    MACRO DHEXPJPGRCT
    GV res 20
    GV ^DEnter resolution in pixels per unit: (20)
    GP xy1 ^DEnter or Select first corner
    GP xy1 ^DEnter or Select second corner
    IFERR MacroDone
    GETX vx1 xy1
    GETx vx2 xy2
    GETY vy1 xy1
    GETY vy2 xy2
    GN sizex (vx2-vx1)*res
    GN sizey (vy2-vy1)*res

    (this is where I need to set the export pixels)

    :MacroDone
    ENDM
  • (hold on, need to investigate WBSM macro... (should have refreshed the page before posting!)
  • LordEntrailsLordEntrails Traveler
    edited July 2018
    I've almost got it to work...
    When I type the commands in the command line it works, as a macro though I have two issues;
    1) After selecting the points for the export (during the WBSM command) I am not prompted for a file name
    2) The image viewer doesn't open after the macro completes (and I can't find the image)

    A prospective concern or two...
    a) if sizex and/or sizey ever come out to be negative, is that going to cause problems?
    b) is there any way to set the default directory/folder for the WBSM command to save the file to?

    MACRO DHEXP
    GV res 20
    GV res ^DEnter resolution in pixels per unit: (20)
    GP xy1 ^DEnter or Select first corner
    GP xy2 ^DEnter or Select second corner
    IFERR MacroDone
    GETX vx1 xy1
    GETx vx2 xy2
    GETY vy1 xy1
    GETY vy2 xy2
    GN sizex (vx2-vx1)*res
    GN sizey (vy2-vy1)*res
    EXPORTSETWIDTH sizex
    EXPORTSETHEIGHT sizey
    EXPORTSETCROP 0
    EXPORTSETBORDER 1
    EFFECTSON
    WBSM
    EFFECTSOFF
    :MacroDone
    ENDM

    (edit: correct macro line to "GV res ^DEnter...")
  • MonsenMonsen Administrator 🖼️ 81 images Cartographer
    Commands in a macro doesn't prompt for anything (Unless you specifically request it to to so with ^D, like in your GP's earlier), instead it would just continue accepting the following data as parameters. In your case, I am betting that it interprets 'EFFECTSOFF' as the file name (and probably fails because it doesn't have an extension, so it doesn't know which file type to use).

    You need to provide WBSM with both the file name to use (get it and put it in a variable first if you wish to prompt for it) as well as the coordinates for the two opposing cornners (xy1 and xy2 in your case). If you need any defaults, just hardcode them in your macro.


    Also, I am unsure exactly how EFFECTSON will behave in a macro, given that it triggers a redraw and such. Maybe turning off redraw first (RDOFF) will help, as that should prevent the screen from being redrawed.
  • In the macro, WBSM still prompts for the points, just not the filename. I'll try feeding it a variable. Any documentation on the macro? I couldn't even find it defined in the fcw32.mac file.

    EFFECTSON seems to work fine, haven't tried it on a large map though, RDOFF is probably smart to add to it.

    Thanks again.
  • MonsenMonsen Administrator 🖼️ 81 images Cartographer
    edited July 2018
    WBSM isn't a macro, it is a built in CC3+ command.

    The syntax is WBSM;sFilename;xyPoint1;xyPoint2

    If you own last years annual, you can see this command in use in the scripts from issue 129 (Large Exports)


    In your macro, I am guessing the reason it asks for points but not filename is that it interpret "EFFECTSOFF" as the filename, and then it runs out of argument (your macro ends) so it asks for the rest
    A short test confirms this suspicion, it creates an export named EFFECTSOFF.bmp
  • Cool, thanks. Haven't saved up enough for the annuals yet. On my list if UM makes any money :)

    What's the proper syntax for WBSM? I'll play with it, but if you get a chance to respond before I figure it out...
  • edited July 2018
    I did a similar implementation, probably not as clean as yours. I did deal with the negatives bit by using an if positive branch to reverse the order of the subtraction. for example:
    GV X3 X1-X2
    GV Y3 Y1-Y2
    IFP X3 XDone
    GV X3 X2-X1
    :XDone
    IFP Y3 YDone
    GV Y3 Y2-Y1
    :YDone

    The WBSM argument I did looked like:
    WBSM $abc.jpg;P0;P1;

    where P0 & P1 are the points selected. The $ means it saves in the same directory as the fcw map file with the filename abc.jpg. I'm sure you can also prompt for the filename and use it
    Posted By: LordEntrailsI've almost got it to work...
    When I type the commands in the command line it works, as a macro though I have two issues;
    1) After selecting the points for the export (during the WBSM command) I am not prompted for a file name
    2) The image viewer doesn't open after the macro completes (and I can't find the image)

    A prospective concern or two...
    a) if sizex and/or sizey ever come out to be negative, is that going to cause problems?
    b) is there any way to set the default directory/folder for the WBSM command to save the file to?
  • edited July 2018
    Hmm, I'm not understanding something on the exportset settings. Here is my macro script. I run it and select a region and expect it to create an output of 20pixels per campaign cartographer unit. However, after running this command, it does export, but it does it based on the pixels set during the most recent save rectangular jpg, not based on the height/width set by the macro. However, if I go and look in the options, they are changed to the new values from the script. Its almost like those values are not getting updated until after the WBSM is called.

    EDIT: It seems that running the script will change the values in the options, but it wont use the new values until you open up the options using GLOBALOPT and clicking OK. Once you do that, it will export using the new values. Until you open it and click ok, it seems to use the old value

    MACRO ExportBM
    SELSAVE
    SAVESETTINGS
    GP P0 ^DClick First Point
    IFERR MacroDone
    GP P1 ^DClick Second Point
    IFERR MacroDone
    GETX X1 P0
    GETY Y1 P0
    GETX X2 P1
    GETY Y2 P1
    GV X3 X1-X2
    GV Y3 Y1-Y2
    IFP X3 XDone
    GV X3 X2-X1
    :XDone
    IFP Y3 YDone
    GV Y3 Y2-Y1
    :YDone
    GV SF 20
    GV WDTH X3*SF
    GV HGHT Y3*SF
    RDOFF
    EFFECTSON
    EXPORTSETWIDTH WDTH
    EXPORTSETHEIGHT HGHT
    WBSM $abc.jpg;P0;P1
    EFFECTSOFF
    RDON
    :MacroDone
    GETSETTINGS
    SELREST
    ENDM
  • Thanks Matt, I was noticing something strange there too but hadn't looked into it yet. Been struggling to pass a variable to the filename of WBSM. I can't get that to work...

    Have you tried breaking he macro into 2 separate macros? That's what I was going to try next... would mean I would have to pick the rectangle twice, but *shirgs*
  • I did learn a neat trick for picking the rectangle by drawing a box and using getsell and getselh. this avoids the negative numbers issue. you create a box so you can see the bounding area, then immediately delete the box after getting the height/width. like so:

    FSTYLE HOLLOW
    GV SF 20
    BOX ^DClick first corner:
    SELBYP
    GETSELL P0
    GETSELH P1
    ERA
    GETX X0 P0
    GETY Y0 P0
    GETX X1 P1
    GETY Y1 P1
    GV dX (X1-X0)*SF
    GV dY (Y1-Y0)*SF
  • I was hoping 2 macros would resolve the issue with the net settings not taking effect, but that didn't help. I'll look to see if their is a macro version of GLOBALOPT that could be run from inside the macro.

    I'll also email support to let them know about the export settings not taking effect.
  • MonsenMonsen Administrator 🖼️ 81 images Cartographer
    edited July 2018
    There is indeed an issue with this command. It should be fixed in the next update, although I have no idea on the roadmap for that.

    In the meantime, the only workaround I know of will be splitting it in 2 macros. the first macro should collect the data, set the appropriate variables and such, and then call GLOBALOPT as the very last line in the macro.
    The second macro (which must be manually launched after closing the options window) should then do the actual export, using the coordinates stored in the variables you set in the first part of the macro.
  • edited July 2018
    This does work, but one thing to note, just opening GLOBALOPT and clicking ok doesnt work. Once the options window opens, you have to click on the BMP,JPEG,PNG button to open the Bitmap Options Dialog, then click Ok. Once you do that you can run the second macro and export it. Here is the code I did which seems to work. So you load the macro file, run SetExportBM, open the bitmap options dialog, click ok and ok to close the options, then run ExportBM. This will save the file in the same directory as the original FCW with the name abc.jpg

    Edit: Last edit, changed output to make a jpg in the same directory as the FCW with the same name as the original FCW file.

    MACRO SetExportBM
    GP P0 ^DClick First Point
    IFERR MacroDone
    GP P1 ^DClick Second Point
    IFERR MacroDone
    GETX X1 P0
    GETY Y1 P0
    GETX X2 P1
    GETY Y2 P1
    GV X3 X1-X2
    GV Y3 Y1-Y2
    IFP X3 XDone
    GV X3 X2-X1
    :XDone
    IFP Y3 YDone
    GV Y3 Y2-Y1
    :YDone
    GV SF 20
    GV WDTH X3*SF
    GV HGHT Y3*SF
    EXPORTSETWIDTH WDTH
    EXPORTSETHEIGHT HGHT
    :MacroDone
    GLOBALOPT
    ENDM

    MACRO ExportBM
    GETDWGNAME F0
    NOEXTENSION F1 F0
    GRFN F2 F1
    APND F2 .jpg
    WBSM F2;P0;P1
    ENDM
  • Thank you Matt!

    I took a poke at this real quick the another night and it didn't work so I gave up and went to bed. Was just getting back to looking at it now. Really appreciate you posting the detailed solution and macro.

    Also, as Monsen said, Ralf confirmed the issue and they will see if they can find a solution and implement it in the next patch.
  • Can someone else verify? I can't get the second macro to run/work.
  • MonsenMonsen Administrator 🖼️ 81 images Cartographer
    Watch out for a space after ENDM in the second macro. The forum software seems to add one at the end of the post. CC3+ is a little particular about the ENDM command, there should be no trailing space on the line containing this command.
  • Thanks Monsen.
    No space after the ENDM, but it also requires an empty line after it.

    I've tried to modify the second macro so I can input a file name, but can't getit to work. Anyone have ideas?
    I've tried things like this;

    MACRO DOX
    GETDWGNAME F0
    GV F0 ^DFilename:
    NOEXTENSION F1 F0
    GRFN F2 F1
    APND F2 .jpg
    WBSM F2;P0;P1
    ENDM
  • edited July 2018
    I think I have a solution for your naming. try this as the second macro. It will create a subdirectory located where the original file is and named the same. so if your map is test.fcw, it will create a test\ folder at that location. Then it prompts you to enter a file name, then exports it as that filename inside that folder.

    MACRO SEBM
    GP P0 ^DClick First Point
    IFERR MacroDone
    GP P1 ^DClick Second Point
    IFERR MacroDone
    GETX X1 P0
    GETY Y1 P0
    GETX X2 P1
    GETY Y2 P1
    GV X3 X1-X2
    GV Y3 Y1-Y2
    IFP X3 XDone
    GV X3 X2-X1
    :XDone
    IFP Y3 YDone
    GV Y3 Y2-Y1
    :YDone
    GV SF 20
    GV WDTH X3*SF
    GV HGHT Y3*SF
    EXPORTSETWIDTH WDTH
    EXPORTSETHEIGHT HGHT
    :MacroDone
    GLOBALOPT
    ENDM

    MACRO EBM
    GETDWGNAME F0
    NOEXTENSION F1 F0
    GRFN F2 F1
    MKDIR F2
    APND F2 \
    GL fName2 ^DEnter Filename
    APND F2 fName2
    APND F2 .jpg
    WBSM F2;P0;P1
    ENDM
  • And LordEntrails, are you the same LE from the Fantasy Grounds forums? I switched over to FG about 5 months ago and recognize your name from there.
  • Thanks Matt. Yea, that's me. I use the alias most everywhere, and am the only one I'm aware of using it.

    Thanks for the new macro, I'll try that later when I get a chance. Much more functional than what I was looking for, appreciate it!
Sign In or Register to comment.