Export to PNG/EMF using VB Scripting

  • 1
  • Question
  • Updated 3 months ago
Greetings!

  Can you share a snippet to script export current map to PNG/EMF with user-defined resolution, say 600 DPI please?

  Thank you.
Photo of Andrey Kazak

Andrey Kazak

  • 43 Posts
  • 4 Reply Likes

Posted 6 months ago

  • 1
Photo of aHa!Coaching

aHa!Coaching, Champion

  • 1192 Posts
  • 115 Reply Likes
There's a GraphicExport object to do these types of exports, see this thread: https://community.mindjet.com/mindjet/topics/export-map-as-image-from-vba-macro

However, you will not be able to set DPI on exports.
Photo of Andrey Kazak

Andrey Kazak

  • 43 Posts
  • 4 Reply Likes
Dear Mathieu,
  Thank you for the suggestion.

  However why do you think that I won't be able to set DPI?
  My plan is the following:
  1) define desired DPI value;
  2) find physical dimensions of the map (W and H);
  3) calculate DPI*W and DPI*H and
  4) feed the found pixel dimensions to the .GraphicExport.ExportSized.
  
  Now, how do I get physical dimensions (width and height) of the map?
Photo of Andrey Kazak

Andrey Kazak

  • 43 Posts
  • 4 Reply Likes
Any ideas on how to get physical dimensions (width and height) of the map?
Photo of aHa!Coaching

aHa!Coaching, Champion

  • 1192 Posts
  • 115 Reply Likes
Part of it could be done like this, but this doesn't take into account the current zoom factor:

Sub Main
    Dim dTop, dLeft, dWidth, dHeight

    ActiveDocument.GetBoundingRect(dTop, dLeft, dWidth, dHeight)

    MsgBox dTop & " | " & dLeft & " | " & dWidth & " | " & dHeight
End Sub

Photo of Andrey Kazak

Andrey Kazak

  • 43 Posts
  • 4 Reply Likes
Thank you. I tried the snippet, but could not figure out: what the units of dWidth, dHeight are.

Do you have ideas?
Photo of aHa!Coaching

aHa!Coaching, Champion

  • 1192 Posts
  • 115 Reply Likes
I'm guessing they are measured in milimetres (mm), as most of the things in MindManager (padding etc) are set in mm. 
Photo of Andrey Kazak

Andrey Kazak

  • 43 Posts
  • 4 Reply Likes
Hm... The scrip shows me some values, but I want to check it. How do I get/set Width and Height of a shape through MM GUI?
Photo of aHa!Coaching

aHa!Coaching, Champion

  • 1192 Posts
  • 115 Reply Likes
Your reply got me thinking....I did a quick test with an 85x85 px image which is part of a topic (see first screenshot) and then reading the image width using the macro below. Interesting results....




Sub Main
    Dim t As Topic
    Set t = ActiveDocument.Selection.PrimaryTopic

    MsgBox "current image width " & t.Image.Width
End Sub

Photo of Andrey Kazak

Andrey Kazak

  • 43 Posts
  • 4 Reply Likes
That's exactly what my question was about...
What is you interpretation of Width property units?
Photo of aHa!Coaching

aHa!Coaching, Champion

  • 1192 Posts
  • 115 Reply Likes
Further testing with aligning an image next to a 20mm topic (set via Format Topic > Size and Margins > Preferred Width) shows that the unit of the Width is probably in mm?




Photo of Nigel Goult (Olympic & MIVAP)

Nigel Goult (Olympic & MIVAP)

  • 344 Posts
  • 133 Reply Likes
I think you might find this will be different on each system depending on the display resolution and perhaps DPI scaling.

For example if I replicate your image and set it to 215 (112%) then the width value I get is 57.12706

Which is almost half of your value.

My display is currently set at 1920x1080 with scaling at 100%. I suspect yours is a he-def with maybe 200% scaling

When we created the Re-Size Image function in our MAP add-in we got the Width and Height values to set by taking the desired pixel size and dividing it by 0.265. We then set the Topic.Image.Width and Topic.Image.Height values to the result.

In the case above 32x32 would equate to a width and height value of 120.7547.

I can't remember why this works. :-)

Regards
Nigel

Olympic Limited
More about Olympic MindManager Add-ins
Contact Nigel

Photo of Ary Velstra, Expert Trainer

Ary Velstra, Expert Trainer

  • 1233 Posts
  • 181 Reply Likes
So  Nigel, you suggest to try (and buy) the MAP add-in?
I agree, if MAP has the functionality, why bother and retry to built something that is already available?
That saves time and increases creativity for developers and users ;-)
Photo of Nigel Goult (Olympic & MIVAP)

Nigel Goult (Olympic & MIVAP)

  • 344 Posts
  • 133 Reply Likes
Hi Ary,

That was not the reason for my post. I was just trying to shed some light onto how the image sizing seems to work and I knew I had pent some time trying to figure this out when I added that function to MAP years ago.

I suspect that purchasing will not help with what Andrey is trying to do unfortunately ;-)
(Edited)
Photo of Nigel Goult (Olympic & MIVAP)

Nigel Goult (Olympic & MIVAP)

  • 344 Posts
  • 133 Reply Likes
CORRECTION

I just noticed that in my earlier post I said that the desired pixel size was DIVIDED by 0.265. This is not correct. The size should be MULTIPLIED by 0.265.

So the values in that post are not correct.

215 * 0.265 = 56975

So this is approximately double your value.

32x32 would give a width/height value of 7.52 x 7.52.

Sorry for any confusion. I will continue investigating ;-)
(Edited)
Photo of Andrey Kazak

Andrey Kazak

  • 43 Posts
  • 4 Reply Likes
Dear colleagues, I couldn't digest your findings above so far, but I will certainly do this.

I want to go another way and get an independent measurement of topiс width/height through MM GUI. For this reason I surrounded a topiс with preferred width equal to 100.00 mm with a rectangular share and got its properties with notebook display resolution 1920×1080.
However I could not understand its units also.
Do you have any ideas about this?

(Edited)
Photo of Andrey Kazak

Andrey Kazak

  • 43 Posts
  • 4 Reply Likes
Can you share an update on the topic please?