Image Placeholder

Started by thalantyrdsl, July 12, 2017, 10:13:45 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

thalantyrdsl

Quote from: metuemre on July 14, 2017, 06:49:23 AM
Please try this one.
.vsd file is for those who have Visio 2010 or older versions

That works fine now, and wow, that's awesome!

The only issue I can see is that it's rotating images 90-degrees counter-clockwise, and then stretching them.

wapperdude

#31
QuoteThanks Wapper. Sorry if I'm getting confused.
These are the steps I've taken to get the error:

That's not how it should work.  It is supposed to start adding shapes at ID = 1, not 6.  Seems as though Visio is behaving differently on your PC.  That may be a behavior change since V2007.

I'll have to see if there's an easy, universal fix.  As for distinguishing pictures, I see no such object type in the Visio model.  The best would be to allow more than 8 shapes.  The 1st 8 will be placed.  If you have fewer than 8 pictures, you could put blank shapes in those spots.  Then add the other items as desired.  But, that complicates things if you subsequently want to add more pictures.

So, I think the other two approaches are better options.

Wapperdude
Visio 2019 Pro

metuemre

Quote from: thalantyrdsl on July 14, 2017, 06:52:35 AM
Quote from: metuemre on July 14, 2017, 06:49:23 AM
Please try this one.
.vsd file is for those who have Visio 2010 or older versions

That works fine now, and wow, that's awesome!

The only issue I can see is that it's rotating images 90-degrees counter-clockwise, and then stretching them.

I used the same command in the code with Insert picture button on the Ribbon menu. You can try to insert the same picture with Insert-Pictures button on the ribbon and see if the picture is rotated. In my computer pictures are inserted as it is, not rotated

thalantyrdsl

Quote from: metuemre on July 14, 2017, 07:01:52 AM
I used the same command in the code with Insert picture button on the Ribbon menu. You can try to insert the same picture with Insert-Pictures button on the ribbon and see if the picture is rotated. In my computer pictures are inserted as it is, not rotated

Ok, I tested it by 'Insert Picture'. It did the same thing.
I then opened my template file that I use and tried it again, and it inserted it correctly, without rotating.

There's something different between the two documents. The one I'm using is .vsdx, but I don't know if it was created originally as a .vsd or .vsdx

Any thoughts on why one would insert correctly and one rotate?

thalantyrdsl

Quote from: wapperdude on July 14, 2017, 06:56:18 AM
QuoteThanks Wapper. Sorry if I'm getting confused.
These are the steps I've taken to get the error:

That's not how it should work.  It is supposed to start adding shapes at ID = 1, not 6.  Seems as though Visio is behaving differently on your PC.  That may be a behavior change since V2007.

I'll have to see if there's an easy, universal fix.  As for distinguishing pictures, I see no such object type in the Visio model.  The best would be to allow more than 8 shapes.  The 1st 8 will be placed.  If you have fewer than 8 pictures, you could put blank shapes in those spots.  Then add the other items as desired.  But, that complicates things if you subsequently want to add more pictures.

So, I think the other two approaches are better options.

Wapperdude

Thank you very much for the help Wapper. That code will come in handy for something else that I do along the way. The ideal script is definitely for a double click insert as then I can edit the page, lock things down, and preset everything where I want it. Thank you again.

thalantyrdsl

Quote from: metuemre on July 14, 2017, 07:01:52 AMI used the same command in the code with Insert picture button on the Ribbon menu. You can try to insert the same picture with Insert-Pictures button on the ribbon and see if the picture is rotated. In my computer pictures are inserted as it is, not rotated

Is there a way for me to add your code to my current template? That may work out better as I'll end up having to do it anyway.

metuemre

You can import attached code files to your template.

Open the VBA Editor with Developer-Visual Basic button. Then right click on wherever you want at Project Explorer on the left and click Import File and select attached files. After that copy the 8 frame shapes and paste to your template and you are ready to go.


Yacine

@Wapperdude, your solution is also very nice.
Some thoughts however:
- instead of working with shape IDs with hard coded positions, you might divide the canvas into rows and columns by defining custom props "rows" and "columns". Depending upon where the picture was placed (its pinX and pinY), you could recalculate the position, depending upon the region (row/column). rowNum = intup(pinX/pagewidth*thepage!prop.rows) and vice versa for the column.
Yacine

thalantyrdsl

Quote from: metuemre on July 14, 2017, 08:05:03 AM
You can import attached code files to your template.

Open the VBA Editor with Developer-Visual Basic button. Then right click on wherever you want at Project Explorer on the left and click Import File and select attached files. After that copy the 8 frame shapes and paste to your template and you are ready to go.

That is awesome Metuemre! I've imported it and it works perfectly. I've used it the same image for my cover page also. Thank you very much, it's exactly what I wanted.

Thank you to everyone who chipped in with this one. I really appreciate it.

wapperdude

#39
Well, even though the horse is out of the barn, I apparently have too much idle time.  So, couldn't leave this with incomplete solution.  Bit the bullet and abandoned the auto placement approach.  Instead, took an approach similar to Metuemre's, i.e., double click a shape to set the location of the picture.  All of the sizing / aspect ratio stuff is holdover from before.  Added the Windows Explorer method to find the file.  Also added a right click option to the page to show / hide the shape placement locators.  Gives the option to hide the unused locators.

Enjoy.
Now I can rest in peace...unless a bug is discovered.   :o

wapperdude
Visio 2019 Pro

Crazy Squirrel

Quote from: metuemre on July 14, 2017, 08:05:03 AM
You can import attached code files to your template.

Open the VBA Editor with Developer-Visual Basic button. Then right click on wherever you want at Project Explorer on the left and click Import File and select attached files. After that copy the 8 frame shapes and paste to your template and you are ready to go.

Hi metuemre,

Is there a way to add a picture but have it locked to the shape?  i.e. if the picture imported is rotated 90 degrees, it stays within the shape?

wapperdude

In metujemre's solution, ImportPicture.vsdm, edit the ImportPic module and replace the If .ShowOpen code section with code below.  This will invoke a MSGBOX after initial picture placement and asks rotation is desired.  I did it this way so that picture is viewable after placement.  IF answer is No, then all proceeds as before.  If Yes, picture is rotated and properly sized to fit the placement frame and maintain the picture aspect ratio.


        If .ShowOpen Then
            strfilename = .FileName
            Application.ActiveWindow.Page.Import strfilename
            Set Pic = ActiveWindow.Selection.PrimaryItem
            aspRat = Pic.Cells("Height").Result("") / Pic.Cells("Width").Result("")
            usrAns = MsgBox("Rotate Pic?", vbYesNo, "User Choice")
            Pic.Cells("PinX").Formula = Frame.Cells("PinX").Result("")
            Pic.Cells("PinY").Formula = Frame.Cells("PinY").Result("")
            If usrAns = vbYes Then
                Pic.Cells("Angle").Formula = "90 deg"
                Pic.Cells("Width").Formula = Frame.Cells("Height").Result("")
                Pic.Cells("Height").Formula = Pic.Cells("Width").Result("") * aspRat
            Else
                Pic.Cells("Width").Formula = Frame.Cells("Width").Result("")
                Pic.Cells("Height").Formula = Frame.Cells("Height").Result("")
            End If
        End If
       

Visio 2019 Pro