Unable to Rename Master

Started by ksjflsdjgbhdfg, July 06, 2017, 08:50:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ksjflsdjgbhdfg

Hi all,

I'm having a problem with accessing one of my custom master and dropping it onto the active page in C#.

Here's my code (please ignore all the hard coding, its only there for testing purposes) :


//Opening my masters file
Globals.companyName.Application.Documents.OpenEx(
  @"C:\conception\Gabarits\!PrototypeBD.vssx",
  (short)vis.VisOpenSaveArgs.visAddDocked);

//Getting the master in question
var ttt = Globals.companyName.Application.ActiveDocument.Masters.
  ItemU["Sonde de température"]; //*************The problem is here

//Dropping the shape onto the active visio page
Globals.RegulvarAutoConception.Application.ActivePage.Drop(
  ttt,
  Double.Parse(shape.Cells["PinX"].FormulaU.Split(' ')[0])/25.4,
  Double.Parse(shape.Cells["PinY"].FormulaU.Split(' ')[0])/25.4
);



Visio :

http://imgur.com/a/97bpE

As you can see, the name i wish to use / rename my master to is : 595aae65427a55cbb492f5d2 (a mongoDB id)
But even after i renamed it, i am still unable to access it in c# with ItemU["595aae65427a55cbb492f5d2"]. I get an error saying that it's not found.

Instead, when i use ItemU["Sonde de température"], it actually works. Even if the name of the master itself is 595aae65427a55cbb492f5d2.

My question is, how am i able to get the shape / master in question named "595aae65427a55cbb492f5d2" ? And why the name changes when i drag it onto the active page?

Thank you

metuemre

#1
Try Item instead of ItemU

ksjflsdjgbhdfg

#2
I do not have a method of "Item" for Globals.companyName.Application.ActiveDocument.Masters

ksjflsdjgbhdfg

#3
bump

vojo

#4
Might want to try ItemU[<Actual UUID not a string version of UUID>]

ItemU takes all kinds of formats and you named the shape with an actual UUID...not the string version of UUID

ksjflsdjgbhdfg

Quote from: vojo on July 10, 2017, 02:41:54 PM
Might want to try ItemU[<Actual UUID not a string version of UUID>]

ItemU takes all kinds of formats and you named the shape with an actual UUID...not the string version of UUID

Unsure what you mean by this.

I tried ItemU["595aae65427a55cbb492f5d2"] but i get the error "name is not found". ItemU[595aae65427a55cbb492f5d2] doesn't work, of course, since that produce a compilation error (not a string or variable).
I can rename the shape to say, "flower" and i'll still get the error of "name is not found" unless i enter "Sonde de température". "flower" wont be found.

Please let me know if I'm missing something obvious.

Thank you.

ksjflsdjgbhdfg

#6
I figured out the problem. It was pretty dump from my end :

Instead of doing :


Globals.companyName.Application.Documents.OpenEx(@"C:\conception\Gabarits\!PrototypeBD.vssx", (short)vis.VisOpenSaveArgs.visAddDocked);

//Getting the master in question
var ttt = Globals.companyName.Application.ActiveDocument.Masters.ItemU["Sonde de température"]


I store the reference from openex and access the master from there instead :


var asd = Globals.companyName.Application.Documents.OpenEx(path, (short)vis.VisOpenSaveArgs.visAddDocked);
               
var ttt = asd.Masters.ItemU["595aae65427a55cbb492f5d2"];

Visio Guy

#7
There should be Item and ItemU, not sure if that is the problem. Is your type-library/reference to Visio off somehow?

Also, try getting the master the other way, then Debug.WriteLine($"{mst.Name}, {mst.NameU}"); to see if the names are really both there.


For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Visio Guy

You can also use the VBA environment to test if code works (or should work):
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Visio Guy

I heard long ago that when doing COM things with .NET it is good to have a variable for every step of the way (which is annoying), because then the variables go out of scope, and get properly garbage collected.

I don't know if this is still true. It has been many years since I heard this advice.

If it still applies, you should then do things like:

var visApp = GetVisio();
var doc = visApp.OpenEx(...);
var mst = doc.Masters["somename"];
var pg = visApp.ActivePage;
var shp = pg.Drop(mst, 0, 0);
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010