Exporting Images at Set Resolution
LordEntrails
Traveler
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
- 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
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
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...")
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.
EFFECTSON seems to work fine, haven't tried it on a large map though, RDOFF is probably smart to add to it.
Thanks again.
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
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...
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
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
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*
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'll also email support to let them know about the export settings not taking effect.
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.
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
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.
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
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
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!
Been a long time, but I have recently updated this macro and thought it might be useful to others.
It is very specific to my use case (generating a set resolution set of player and DM images of a part of a CC3 map), but it does a few things. And should be modifiable by others to other use cases. Note it's broken up into "sub" macros, some of which can not be run on their own. The main macro is "UMB" (UnderMountain Both)
Hope somebody else finds this useful!
// Set layer display for Player map export
MACRO UMLAYPLAYER
HIDE 5Ft GRID
SHOW BACKGROUND
SHOW BACKGROUND (FLOOR 1)
SHOW BACKGROUND (FLOOR 2)
SHOW CAVES
SHOW CONSTRUCTION
SHOW CONTAINERS AND TREASURE
SHOW DEBRIS
SHOW ELEMENTAL AND MAGIC
SHOW FLOORS
SHOW FURNITURE
HIDE GAME MASTER ONLY
HIDE HEX/SQUARE GRID
SHOW ILLUSION
SHOW LABELS
SHOW LIGHT SOURCES
HIDE MAP BORDER
HIDE MAP KEY
SHOW MERGE
SHOW PORTALS-INVISIBLE
SHOW PORTALS-VISIBLE
SHOW SCREEN
HIDE SECRET
SHOW STANDARD
SHOW STRUCTURES (COLORS)
SHOW SYMBOL
SHOW SYMBOL DEFINITION
SHOW SYMBOL NORTH
SHOW SYMBOL SOUTH
SHOW TEMP
SHOW TEMPLATE
SHOW TEMPLE AND STATUES
SHOW TEXT LABELS
SHOW TILES
HIDE TRAPS
SHOW UP AND DOWN
SHOW VEGETATION
SHOW WALL FEATURES
SHOW WALLS
SHOW WEAPONS
ENDM
// Set layer display for DM map export
MACRO UMLAYDM
HIDE 5Ft GRID
SHOW BACKGROUND
SHOW BACKGROUND (FLOOR 1)
SHOW BACKGROUND (FLOOR 2)
SHOW CAVES
SHOW CONSTRUCTION
SHOW CONTAINERS AND TREASURE
SHOW DEBRIS
HIDE ELEMENTAL AND MAGIC
SHOW FLOORS
SHOW FURNITURE
SHOW GAME MASTER ONLY
HIDE HEX/SQUARE GRID
HIDE ILLUSION
SHOW LABELS
SHOW LIGHT SOURCES
HIDE MAP BORDER
HIDE MAP KEY
SHOW MERGE
SHOW PORTALS-INVISIBLE
SHOW PORTALS-VISIBLE
SHOW SCREEN
SHOW SECRET
SHOW STANDARD
SHOW STRUCTURES (COLORS)
SHOW SYMBOL
SHOW SYMBOL DEFINITION
SHOW SYMBOL NORTH
SHOW SYMBOL SOUTH
SHOW TEMP
SHOW TEMPLATE
SHOW TEMPLE AND STATUES
SHOW TEXT LABELS
SHOW TILES
SHOW TRAPS
SHOW UP AND DOWN
SHOW VEGETATION
SHOW WALL FEATURES
SHOW WALLS
SHOW WEAPONS
ENDM
// Get inputs and set options
MACRO UMGETINPUT
GV res 20
GV res ^DEnter resolution in pixels per unit: (20)
GL fname Export
GL fname ^DFilename: (Export)
RDOFF
SNAPON
GRIDOFF
GRIDV 5
SNAPV 1
CSNAPON
GP P0 ^DFirst Point
IFERR MacroDone
GP P1 ^DSecond Point
GETX x1 P0
GETX x2 P1
GETY y1 P0
GETY y2 P1
GV vx x2-x1
IFP vx XDone
GV vx x1-x2
:XDone
GV vy y2-y1
IFP vy YDone
GV vy y1-y2
:YDone
GV sizex vx*res
GV sizey vy*res
EXPORTSETWIDTH sizex
EXPORTSETHEIGHT sizey
EXPORTSETCROP 0
EXPORTSETBORDER 1
ENDM
// Export both player and DM images
MACRO UMEXPORT
GETDWGNAME dName
NOEXTENSION dName1 dName
GRFN dirName dName1
MKDIR dirName
APND dirName \
UMLAYPLAYER
EFFECTSON
GL NameP dirName
APND NameP fName
APND NameP .jpg
WBSM NameP;P0;P1
UMLAYDM
GL NameD dirName
APND NameD fName
APND NameD -DM
APND NameD .jpg
WBSM NameD;P0;P1
EFFECTSOFF
RDON
CSNAPOFF
NOSTEP
ENDM
// Run combined macros
MACRO UMB
UMGETINPUT
UMEXPORT
ENDM