News:

BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Getting the original Picture back out of a Visio shape

Started by Visisthebest, August 23, 2023, 05:31:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wapperdude

Most impressive!  I'd click the like button but would get carpal tunnel syndrome.

Must observe that the final result is neither simple, direct, nor intuitive.  For a user, they're totally dependent upon the code doing everything.  So, I would rate this as User unfriendly.

Off the top of my head, considering all of the embellishments, plus the need to retrieve/update/change photo, I would do something like:  on drop add to group.  Perhaps add User cell to contain image name.  The border would be another, built-in group subshapes that over lays the pic.  Either it, or the parent can contain connection points.  Note, on drop, the pic can be centered and sized according to present group settings.  Thus, replacing existing pic is merely delete (optional) and drop new pic.  DONE.   Example of possibility:  http://visguy.com/vgforum/index.php?topic=2291.msg15693#msg15693
Visio 2019 Pro

Surrogate

Quote from: Nikolay on August 25, 2023, 11:43:45 AM
It is just lying, there is "ForeignData" shape sheet cell, of course. If it existed, that would be a practical solution.
But it's not entirely wrong. If you open the VSDX file, there is "ForeignData" cell in the XML (see below)
OFFTOPIC: This cell is available via user interface or ShapeSheet?
https://github.com/MicrosoftDocs/office-developer-client-docs/blob/main/docs/visio/shapesheet_type-complextypevisio-xml.md
Data1, Data2, Data3 are also there...

Nikolay

#32
@wapperdude, you are absolutely right, it's not a user code. But we are developers here, are we not?  :)
And it's always code that is doing everything, the only difference is who's code is that, and how it's wrapped...

Here is a user-friendly (web) version running the code above 8)
User should be able to dorp any .vsdx file with images there, and get back images, with page and shape ids, as a zip archive:

https://webtools.unmanagedvisio.com/extract-images



Source:
https://github.com/nbelyh/VisioPdfTip-WebApp/blob/master/AzureFunction/ImageExtractor.cs

Visisthebest

Visio 2021 Professional

wapperdude

@Vizisthebest:  LOL.  I removed my post apparently as you were drafting your reply.  Basically, I decided to recall it.
Visio 2019 Pro

wapperdude

@Nikolay:  I would encourage you to resubmit the web development again, under Users submitted Stuff or perhaps Market....

It needs its own identity.
Visio 2019 Pro

wapperdude

#36
The ol' gray mare ain't dead, and chatGPT (???) also lied. There is a 4th known, existing method that I stumbled upon.  Here's the reference:  Selection.Export Method https://learn.microsoft.com/en-us/office/vba/api/Visio.Selection.Export

Based upon this, I did simple test.  Imported a pic onto a page and selected it.  Then ran my code to export the pic as png onto my desktop.  The method allows me to name the output file.  In the example, I called it Luc1.  It would be easy enough to embellish this two line code to use the existing Visio directory or other, and to change the file type.  I haven't investigated further than seeing if this actually works.  It does.

Here's my test code:

Sub exportPic()
    Dim MyPic As Visio.Shape
   
    Set MyPic = ActiveWindow.Selection(1)
    MyPic.Export ("C:\Users\yourusername\OneDrive\Desktop\Luc1.png")
   
End Sub


Oooops...sort of.... As I look at Yacine's post,  this is basically a stripped down version of that, sans the size and resolution statements.  Well, I'll leave it, as it may be of some value. 
Visio 2019 Pro

Visisthebest

Thank you Wapperdude, did some more testing with GPT-4 and I must say it is also pretty good at producing useless code. You have to double-check everything. Frequently there is some good stuff in there too, so there is value, but this forum is much better than GPT-4!
Visio 2021 Professional

wapperdude

#38
Curiosity still gnawing at me, I came across this 2012 forum post, Al Edlund to the rescue!
http://visguy.com/vgforum/index.php?topic=3858.0. In addition to solving the issue, early on he makes interesting comment about Visio exporting: 
QuoteAs in most methods in Visio vba, the export method is actually looking for an 'object'.
.  Ok.  I found it interesting.
Visio 2019 Pro

wapperdude

Visio 2019 Pro

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 343 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1214KB.
Tokens: post-login.
Cache hits: 14: 0.00256s for 26,734 bytes (show)
Cache misses: 3: (show)
Queries used: 16.

[Show Queries]