none
如何取得visio2010中的自定义属性值? RRS feed

  • 问题

  • 我想取得visio中的自定义属性值,但是无法取得,我使用的是Visio Code Samples Library中,“Microsoft Visual C#”|“Custom Properties (Shape Data)”|“Read Custom Property (Shape Data Item)” 的方法 ,

    我的调用如下:


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

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

    我本地的计算机中visio文件的shape sheet中shape data如下截图所示:

    http://www.57ty.com/images/uploadfile/shapesheet.png

    运行后,错误信息如下:
    "COMException was unhandled
    System.Runtime.InteropServices.COMException was unhandled
      Message=

    参数无效
      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()
      In

    • 已编辑 canbo2000 2010年9月25日 7:25 补充了截图
    2010年9月25日 7:12

全部回复

  • 我现在无法取得更改后的值shape data,

    我修改了值,保存为另一个文件,再打开这个文件后,才可以取得这个值,如果直接保存覆盖原来的文件,取不到值,为什么呢?

     

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

                    shape = page.Shapes[i];
                   
                    //shape.Name
                    //rncps.ReadANamedCustomProperty(shape, "ShapeClass.Label", true);
                    rncps.ReadANamedCustomProperty(shape, "SubShapeType.Value", false);
                }

    2010年9月25日 9:36