Insert userfield programatically

Started by kiler40, March 16, 2015, 05:17:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kiler40

Hello Everybody.
I`m trying to create shapes that have a text inside them :)
the text is controlled from prop.row value.

If i use this
    Application.ActiveWindow.Page.DrawRectangle 0.255906, 7.795276, 0.984252, 3.897638
    Set vsoshape = Visio.ActiveWindow.Selection(1)
    vsoshape.AddSection visSectionProp
    vsoshape.AddNamedRow visSectionProp, Prop_Rows_Name, visTagDefault
    vsoshape.Cells("prop.row_1").FormulaU = z
    vsoshape.AddNamedRow visSectionProp, Prop_Rows_Name, visTagDefault
    vsoshape.Cells("prop.row_2").FormulaU = """" & pN & """"
    wdth = vsoshape.Cells("width")
    hght = vsoshape.Cells("Height")
    vsoshape.Cells("Angle").FormulaU = "90 deg"
    vsoshape.Cells("width") = hght
    vsoshape.Cells("Height") = wdth
    vsoshape.CellsSRC(visSectionObject, visRowText, visTxtBlkLeftMargin).FormulaU = "0 pt"
    vsoshape.CellsSRC(visSectionObject, visRowText, visTxtBlkRightMargin).FormulaU = "0 pt"
    vsoshape.CellsSRC(visSectionObject, visRowText, visTxtBlkTopMargin).FormulaU = "0 pt"
    vsoshape.CellsSRC(visSectionObject, visRowText, visTxtBlkBottomMargin).FormulaU = "0 pt"
    vsoshape.CellsSRC(visSectionCharacter, 0, visCharacterSize).FormulaU = "48 pt"
    Set vsoCharacters1 = vsoshape.Characters
    vsoCharacters1.Text = pN & " " & "module" & vsoshape.Cells("prop.row_1").FormulaU
    vsoCharacters1.Begin = 0
    vsoCharacters1.End = P
    vsoCharacters1.CharProps(visCharacterSize) = 10


it creates shape with text inside. but later if i want to change prop.row value (i use prop.row because i still cant understand how to change the name of the row :D )
it is not active (not so hard to understand why...)

so the solution is this

    Application.ActiveWindow.Page.DrawRectangle 0.255906, 11.437008, 0.984252, 7.795276
    Set vsoshape = Visio.ActiveWindow.Selection(1)
    vsoshape.AddSection visSectionProp
    vsoshape.AddNamedRow visSectionProp, Prop_Rows_Name, visTagDefault
    vsoshape.Cells("prop.row_1").FormulaU = z
    vsoshape.AddNamedRow visSectionProp, Prop_Rows_Name, visTagDefault
    vsoshape.Cells("prop.row_2").FormulaU = """" & pN & """"
    wdth = vsoshape.Cells("width")
    hght = vsoshape.Cells("Height")
    vsoshape.Cells("Angle").FormulaU = "90 deg"
    vsoshape.Cells("width") = hght
    vsoshape.Cells("Height") = wdth
    vsoshape.CellsSRC(visSectionObject, visRowText, visTxtBlkLeftMargin).FormulaU = "0 pt"
    vsoshape.CellsSRC(visSectionObject, visRowText, visTxtBlkRightMargin).FormulaU = "0 pt"
    vsoshape.CellsSRC(visSectionObject, visRowText, visTxtBlkTopMargin).FormulaU = "0 pt"
    vsoshape.CellsSRC(visSectionObject, visRowText, visTxtBlkBottomMargin).FormulaU = "0 pt"
    vsoshape.CellsSRC(visSectionCharacter, 0, visCharacterSize).FormulaU = "48 pt"
    Set vsoCharacters1 = vsoshape.Characters
    vsoCharacters1.AddCustomFieldU "Prop.Row_2& "" "" &""module""&Prop.Row_1", visFmtNumGenNoUnits
   
    vsoCharacters1.Begin = 0
    vsoCharacters1.End = P
    vsoCharacters1.CharProps(visCharacterSize) = 10


but here comes the catch. I want the size of the txt from prop.row_2 to be 10pt and size of "module" & prop.row_1 to be 48 pt.
Text at prop.row`s initially comes from a user form.
Z is number, PN is string
and P is counting the lenght of the PN string so it know how many symbols to be 10pt

The reason i want to do this is because i have several pages with such shapes and from time to time is needed to change the Z number of some of them - Z+1 (all after certain number to be exact)

Any ideas how to accomplish this ?

Thanks in advance !
Andrei


Yacine

Hi Andrei,
1) to change the name of a row in the prop section, just click in the first column where the name is displayed and start typing.
If you record this operation, you'll get the code to do so in VBA.
2) What is the reason for creating shapes with such specific properties? The standard approach would be to create a master. The code should only modify the values of the prop fields. This way the solution becomes maintainable.
Yacine

kiler40

Hello Yacine,

Quote from: Yacine on March 16, 2015, 05:37:46 PM
1) to change the name of a row in the prop section, just click in the first column where the name is displayed and start typing.
If you record this operation, you'll get the code to do so in VBA.
i know how to do it by hand. The idea is by code. Today was the first time i tried to do this by code. I`ll follow your advice!!! (mostly i do this record - get the code stuff) 8) But not this is the question.

In the beginning of the file (considere it as a template) there is only one blank background page.
There is a routine (part of witch is the code i have posted here) that asks how many shapes with certain numbered string will there be on the page. (3 per page, so it also creates required number of pages)
But untill now, there was only option for 3 on page. and i need to change - if there is only 2 (due to size the shape need become) all other need shift their number with one +.

At the moment the shapes have a simple text that is created by a counter and puted into the shape.
The idea to get the numbers of the symbols after the last space sign and change this number only to number + 1 - it was literary nonsense for me. So shape sheet data - is what i need :)

As always i have explained with 300000 words what i need :D Your idea for use a master is great. Now i need to figure how to put it into place and redesign the code a lot.

P.S.
I don`t have a sample file on this PC to show what the file is all about. Tomorrow i`ll post it and maybe more light will come to the topic.

Thanks for the time and,
Sorry for the long post !

Cheers,
Andrei

Nikolay

> The idea to get the numbers of the symbols after the last space sign and change this number only to number + 1 - it was literary nonsense for me

Hmm.. What is the problem with this approach?
I think this might be the best you can do (unlike custom properties, this way you leave customers an option to adjust the text "by hand" if needed).
For example, Visio built-in "numbering wizard" does exactly this. BTW, maybe you can just use it?

kiler40

Honestly - i really don`t know how to do it. Since there are several specified words it is hard for me to get the last space, identyfi the number and add one to it.

Numbering shape - i don`t know how can i specify witch shape to affect the numbering... also on several pages ?

The idea with master is good. with this i can check all shapes on page, to have 2 specific prop.rows and if value of one of them is above some number to add one to it.
I`ll try to modify the code just a little. so all other functionality to stay the same :)

P.S.
Here is the file

https://dl.dropboxusercontent.com/u/10255673/modular_preparation.vsd