Custom Stencil with image placeholder, loading images on the fly

Started by georgejost, February 05, 2016, 06:31:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

georgejost

I'd like to do the following:
1) Non-programming part - create a stencil file VSS with my own set of master objects; e.g., "Wizard", "Warrior", or whatever with a placeholder to hold an image
2) I want to be able to programmatically add an image to the shape I generate using the master object.

Does anybody have any hints that might save me time.

I noticed an old post using some kind of mechism to the Shape class using Cells?

Sorry for being vague. Any hints/links/sample code would be greatly appreciated.

Yacine

You're absolutely right. Stop being vague. :D
That is so vague, none of the forum members will be capable of answering your post.
Please give more details.
Yacine

Nikolay

It's okay being vague, but could you please be vague to the very end, please no XY :)

Like, what are you trying to do basically?

Create a warrior (shape) and equip it with a (switchable) weapon (picture)?

georgejost

Quote from: Nikolay on February 05, 2016, 08:24:00 PM
Like, what are you trying to do basically?

I have 2 symbols. Warriors and Wizards. Warriors are circular, wizards are square. There are different types of each, represented by a picture but in each what I want is a "placeholder" in the right hand corner for the picture.

So, I have a stencil, (VSS file) with 2 masters, "Warrior" and "Wizard".

However, when after a drop a Warrior on my page, I want to be able to load a bitmap to that area in the right hand corner of that Shape in the same way that I alter the text label.

(Alternately, I want to generate from a directory a very large stencil with something like 500 warrior different symbols with different names based on the file name.)

JuneTheSecond

Have a look around example of Visio organization charts. They have images on the side of shapes. I hope they have any hint.
https://blogs.office.com/2012/08/20/visualize-your-organization-like-never-before-in-the-new-visio/
Best Regards,

Junichi Yoda
http://june.minibird.jp/

georgejost


georgejost

Quote from: JuneTheSecond on February 05, 2016, 11:16:51 PM
Have a look around example of Visio organization charts. They have images on the side of shapes. I hope they have any hint.
https://blogs.office.com/2012/08/20/visualize-your-organization-like-never-before-in-the-new-visio/

I'm finding the orgchart stencil is extremely difficult to use.
a) I don't know how to connect shapes using this stencil. If I use AutoConnect(), it only lets me connect one thing to a shape. (I connect parent to several children using Auto-Connect and it allows only one of those connections)
b) I don't know how to use the drop and connect functionality programatically. As a user, if I drop one shape onto another and visio makes the target the parent and the dragged object a child. As a programmer, I cannot see any methods in the CVShape class that does this.
c) Your link seems to tell me how to extend a diagram as a user without doing it programaticaly. I can easily import images. I played with that as a user but I would like to do it programatically?

Cheers, George ;-)

JuneTheSecond

I am very bad to organization chart, but I remember the detailed information was open to developer.
If you search in the web with keywords, Visio VBA organization chart.
, or in Visio.blog,,, but I am sorry I could not found I am looking for. Where is it.
Best Regards,

Junichi Yoda
http://june.minibird.jp/

georgejost

Quote from: JuneTheSecond on February 09, 2016, 10:58:13 PM
If you search in the web with keywords, Visio VBA organization chart.

Oh, yes. I was working from that actually.

Yacine

Hi George,
Junichi's hint is probably the way to go - not entirely, but at least for the fundamental principles.
The org charts with images, use a custom fillings in the shapes.
With some VBA you could select the right image in your file system, insert it in as filling background and use it in your custom shapes.

Not sure however, if you're willing to go this path? ???

Cheers,
Y.
Yacine

JuneTheSecond

#10
Then I shall return to your question.
Quote
a) I don't know how to connect shapes using this stencil. If I use AutoConnect(), it only lets me connect one thing to a shape. (I connect parent to several children using Auto-Connect and it allows only one of those connections)
I did not know AutoConnect method, it is powerful method.
But I think this org chart uses GlueTo method, because shapes of org char has connection points. Connector has to be connected to the connection point.  If you use macro recorder, it returns GlueTo method. Please try macro recorder.
Once separate some shapes moving connectors, but not delete connectors. Then start macro  recorder. And reconnect shapes again moving isolated connectors. Stop macro recorder, And watch the result. 
Best Regards,

Junichi Yoda
http://june.minibird.jp/

AndyW

I have a title box on my diagram pages and allow a logo to be changed. Images can not be updated in an existing shape, so put them in a new subshape.

Basically I find the subshape in my shape containing the logo.

I get the existing size for the image.

Import my new image into my top level shape.

Scale my image to suit.

Rename the old logo.

Set the name of my new image.

Copy over settings from the old image subshape, pin position, size etc

Finally delete the old shape.

           

'vsoShape is my topl-level shape, with a 'CustomLogo' subshape.

            On Error Resume Next

            Set oOldLogoShape = vsoShape.Shapes("CustomLogo")
               
            On Error GoTo 0
               
            If Not oOldLogoShape Is Nothing Then
                                           
                With oOldLogoShape
                    intOldWidth = .CellsSRC(visSectionObject, visRowXFormOut, visXFormWidth).ResultInt(visMillimeters, 0)
                    intOldHeight = .CellsSRC(visSectionObject, visRowXFormOut, visXFormHeight).ResultInt(visMillimeters, 0)
                End With
               
                Set oNewLogoShape = vsoShape.Import(strFileName)
                   
                With oNewLogoShape
                   
                    intNewWidth = .CellsSRC(visSectionObject, visRowXFormOut, visXFormWidth).ResultInt(visMillimeters, 0)
                    intNewHeight = .CellsSRC(visSectionObject, visRowXFormOut, visXFormHeight).ResultInt(visMillimeters, 0)
                       
                    dblWidthRatio = intOldWidth / intNewWidth
                    dblHeightRatio = intOldHeight / intNewHeight
                       
                    If dblHeightRatio < dblWidthRatio Then
                        dblRatio = dblHeightRatio
                    Else
                        dblRatio = dblWidthRatio
                    End If
                       
                    oOldLogoShape.name = "OldCustomLogo"
                       
                    .name = "CustomLogo"
                               
                    .CellsSRC(visSectionObject, visRowXFormOut, visXFormPinX).FormulaU = oOldLogoShape.CellsSRC(visSectionObject, visRowXFormOut, visXFormPinX).FormulaU
                    .CellsSRC(visSectionObject, visRowXFormOut, visXFormPinY).FormulaU = oOldLogoShape.CellsSRC(visSectionObject, visRowXFormOut, visXFormPinY).FormulaU
                    .CellsSRC(visSectionObject, visRowXFormOut, visXFormWidth).FormulaU = oOldLogoShape.CellsSRC(visSectionObject, visRowXFormOut, visXFormWidth).FormulaU
                    .CellsSRC(visSectionObject, visRowXFormOut, visXFormHeight).FormulaU = oOldLogoShape.CellsSRC(visSectionObject, visRowXFormOut, visXFormHeight).FormulaU
                    .CellsU("FillPattern").FormulaU = oOldLogoShape.CellsU("FillPattern").FormulaU
                    '.CellsU("ImgWidth").FormulaU = "width*" + CStr(dblRatio) '"Width*.95"
                    '.CellsU("ImgHeight").FormulaU = "Height*" + CStr(dblRatio) '"Height*.95"
                    .CellsU("ImgOffsetX").FormulaU = "(Width-ImgWidth)/2"
                    .CellsU("ImgOffsetY").FormulaU = "(Height-ImgHeight)/2"
                    .CellsSRC(visSectionObject, visRowLine, visLinePattern).FormulaU = 1
                    .CellsSRC(visSectionObject, visRowLine, visLineWeight).FormulaU = .Parent.CellsSRC(visSectionObject, visRowLine, visLineWeight).FormulaU
                       
                End With
                           
                Call oOldLogoShape.Delete
Live life with an open mind

Yacine

To explain the idea with the custom fill patterns.
I prepared a vsd with 3 custom patterns containing each a different image.
The shape  on the page will display a different image depending on the property ShapeType.

Now you can easily record a macro, in which you'd create a new fill pattern and insert in it an image from file.
Yacine

georgejost

Andy, I get the impression you may have answered my question. I need to delve further.

Quote from: Yacine on February 10, 2016, 09:14:02 PM
Hi George,
Junichi's hint is probably the way to go - not entirely, but at least for the fundamental principles.
The org charts with images, use a custom fillings in the shapes.
With some VBA you could select the right image in your file system, insert it in as filling background and use it in your custom shapes.

Not sure however, if you're willing to go this path? ???

Cheers,
Y.

my path is worse, I'm using c++ but need to know the api better. sample code like Andy's would help. I'm about to digest his but it sounds like you know how to do what I want?

I owe you guys a bit of what I learned but just switched tasks. stand bye tho.

jCant use Juns because that library isn't open source and I'm on a network that doesn't allow me to use unapproved binaries. If I had Dimtrys source, it is 100 percent likely his utility knows how to do it.