How to Call Visio 2010 SDK's ReadANamedCustomPropertySample.cs Method?

Started by canbo, September 20, 2010, 03:38:38 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

canbo

I called in this way,

ReadANamedCustomPropertySample rncps = new ReadANamedCustomPropertySample();
rncps.ReadANamedCustomProperty(shape, "canborowname", true);

but i run it , the code run to this"
System.Windows.Forms.MessageBox.Show(
                            "This shape does not have a Custom Property\r\n" +
                            "with the universal name '" + rowNameU + "'.");
"
what can i call the ReadANamedCustomProperty?

Paul Herber

Look at the shape's custom properties (Shape data in Visio 2010). Does it have the custom properties you expect? Is there a row called "canborowname" ?

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Visio Guy

I'm not sure where you got that code, I'm not finding ReadANamedCustomPropertySample.cs amongst the VisioSDK files.

Anyway, with Shape Data, there are a number of things to remember:


  • Shape Data fields used to be called Custom Properties
  • The row names in the ShapeSheet are still start with "Prop."
  • Shape Data fields have labels. The label is what a user names the field.
  • Shape Data fields have row names. The row name is what a developer names the field.
  • If a data field has a label, this is what the user sees in the Shape Data window
  • In the ShapeSheet, data fields can have custom row names, such as Prop.Cost instead of Prop.Row_1
  • Row names are not used by the UI to determine when shapes have the same data field(s)
  • Labels ARE used by the UI to determine when shapes have the same data field(s)

So let's say:

Shape1 has:

  Prop.Row_1
  Prop.Row_1.Label = "Bob"


Shape2 has:

  Prop.Buddy
  Prop.Buddy.Label = "Bob"

If you select both of these shapes, the Shape Data field will let you set the field "Bob" for both shapes at the same time. This means that programmers have to do a lot more work. They have to search through all shape data rows in shapes to find labels that match. shp.CellExists(...) isn't enough.

I believe labels are also used by Data Graphics for various purposes.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

canbo

i download the code from "Visio Code Samples Library",in"Visio Code Samples Library","Microsoft Visual C#"|"Custom Properties (Shape Data)"|"Read Custom Property (Shape Data Item)",this article。

the next is how to call the method:

ReadANamedCustomPropertySample rncps = new ReadANamedCustomPropertySample();
            for (int i = 0; i < page.Shapes.Count;i++ )
            {

                rncps.ReadANamedCustomProperty(page.Shapes, "ValveType.Label", true);
            }

I run the code ,it's error message is next:
"COMException was unhandled
System.Runtime.InteropServices.COMException was unhandled
  Message=

参数无效(unvalidate args)。
  Source=Microsoft Visio
  ErrorCode=-2032465751
  StackTrace:
       at Microsoft.Office.Interop.Visio.ShapesClass.get_Item(Object NameUIDOrIndex)
       at Visio2010Dev.Form1.button4_Click(Object sender, EventArgs e) in C:\Users\canbo\Documents\Visual Studio 2010\Projects\Visio2010Dev\Visio2010Dev\Form1.cs:line 108
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Visio2010Dev.Program.Main() in C:\Users\canbo\Documents\Visual Studio 2010\Projects\Visio2010Dev\Visio2010Dev\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
"

Paul Herber

There is something about the way you've copied and pasted this code that stops it from displaying correctly, it is different when quoted, in particular the line
rncps.ReadANamedCustomProperty(page.Shapes, "ValveType.Label", true);
is really
rncps.ReadANamedCustomProperty(page.Shapes, "ValveType.Label", true);
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

canbo

"
rncps.ReadANamedCustomProperty(page.Shapes, "ValveType.Label", true);
is really
rncps.ReadANamedCustomProperty(page.Shapes, "ValveType.Label", true);
"

any different ?

::)

rncps.ReadANamedCustomProperty(shape, "SubShapeType.Value", false);
I resolved it,ok!!!

Paul Herber

Quote from: canbo on September 26, 2010, 01:27:36 AM
"
rncps.ReadANamedCustomProperty(page.Shapes, "ValveType.Label", true);
is really
rncps.ReadANamedCustomProperty(page.Shapes, "ValveType.Label", true);
"

any different ?

::)

rncps.ReadANamedCustomProperty(shape, "SubShapeType.Value", false);
I resolved it,ok!!!
If you click the "Quote" link on my message you will see the difference. I think this forum software is removing bits from the code as it is not in CODE quotes.

rncps.ReadANamedCustomProperty(page.Shapes, "ValveType.Label", true);

is really

rncps.ReadANamedCustomProperty(page.Shapes[i], "ValveType.Label", true);

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/