爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 3781|回复: 1

[源程序] c#调用Grapher 10.1.640(未汉化版)

[复制链接]

新浪微博达人勋

发表于 2017-1-13 08:14:17 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 xyangtian 于 2017-6-10 16:20 编辑
  1. <div class="blockcode"><blockquote>using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using Microsoft.Win32;
  16. using Grapher;
  17. using System.Reflection;

  18. namespace WpfApplication1
  19. {
  20.     /// <summary>
  21.     /// MainWindow.xaml 的交互逻辑
  22.     /// </summary>
  23.     public partial class MainWindow : Window
  24.     {
  25.         public MainWindow()
  26.         {
  27.             InitializeComponent();
  28.         }
  29.         string[] fileName = new string[] { };
  30.         
  31.         List<string> listFile = new List<string>();
  32.         List<string> listFileName = new List<string>();
  33.         List<string> strListFileName = new List<string>();
  34.       
  35.         private void fileButton_Click(object sender, RoutedEventArgs e)
  36.         {
  37.             OpenFileDialog ofdName = new OpenFileDialog();
  38.             ofdName.Title = "选择网格文件";
  39.             ofdName.Filter = "dat文件|*.dat|所有文件|*.*";
  40.             ofdName.FileName = string.Empty;
  41.             ofdName.RestoreDirectory = true;
  42.             ofdName.DefaultExt = "dat";
  43.             ofdName.Multiselect = true;
  44.             if (ofdName.ShowDialog() == true)
  45.             {
  46.                 fileName = ofdName.FileNames;
  47.                 for (int i = 0; i < fileName.Length; i++)
  48.                 {
  49.                     listFile.Add(fileName[i]);

  50.                     strListFileName.Add(fileName[i].Substring(fileName[i].LastIndexOf("\") + 1, (fileName[i].LastIndexOf(".") - fileName[i].LastIndexOf("\") - 1)));
  51.                     
  52.                     listFileName.Add(fileName[i].Remove(fileName[i].LastIndexOf(".")));//移除文件后缀
  53.                 }
  54.             }
  55.             
  56.         }

  57.         private void makeButton_Click(object sender, RoutedEventArgs e)
  58.         {

  59.             for (int i = 0; i < listFile.LongCount(); i++)
  60.             {

  61.                 Type grapherType = Type.GetTypeFromProgID("Grapher.Application");
  62.                 Object grapher = System.Activator.CreateInstance(grapherType);//获取Grapher实例
  63.                 grapherType.InvokeMember("Visible", BindingFlags.SetProperty, null, grapher, new Object[] { true });//显示Grapher界面
  64.                 Object documents = grapherType.InvokeMember("Documents", BindingFlags.GetProperty, null, grapher, null);
  65.                 Object document = documents.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, documents, null);
  66.                 Object shapes = document.GetType().InvokeMember("Shapes", BindingFlags.GetProperty, null, document, null);
  67.                 Object Graph1 = shapes.GetType().InvokeMember("AddLinePlotGraph", BindingFlags.InvokeMethod, null, shapes, new Object[] { listFile[i], 1, 2 });
  68.                 Object graphTitle = Graph1.GetType().InvokeMember("Title", BindingFlags.GetProperty, null, Graph1, null);
  69.                 graphTitle.GetType().InvokeMember("Text", BindingFlags.SetProperty, null, graphTitle, new Object[] { strListFileName[i] });//设置图形名

  70.                 Object axesItem = Graph1.GetType().InvokeMember("Axes", BindingFlags.GetProperty, null, Graph1, null);
  71.                 Object yAxisItem = axesItem.GetType().InvokeMember("Item", BindingFlags.GetProperty, null, axesItem, new Object[] { 2 });//选中Y轴
  72.                 Object yAxisTitle = yAxisItem.GetType().InvokeMember("Title", BindingFlags.GetProperty, null, yAxisItem, null);//切换到Y轴的Title属性
  73.                 yAxisTitle.GetType().InvokeMember("Text", BindingFlags.SetProperty, null, yAxisTitle, new Object[] { "Emf(mV/A)" });//设置Y中的Text
  74.                 Object yAxis = Graph1.GetType().InvokeMember("Axes", BindingFlags.GetProperty, null, Graph1, new Object[] { 2 });
  75.                 yAxis.GetType().InvokeMember("Scale", BindingFlags.SetProperty, null, yAxis, new Object[] { 2 });//设置为对数(log)

  76.                 Object xAxisItem = axesItem.GetType().InvokeMember("Item", BindingFlags.GetProperty, null, axesItem, new Object[] { 1 });//选中X轴
  77.                 Object xAxisTitle = xAxisItem.GetType().InvokeMember("Title", BindingFlags.GetProperty, null, xAxisItem, null);//切换到X轴的Title属性
  78.                 xAxisTitle.GetType().InvokeMember("Text", BindingFlags.SetProperty, null, xAxisTitle, new Object[] { "T(ms)" });//设置X中的Text
  79.                 Object xAxis = Graph1.GetType().InvokeMember("Axes", BindingFlags.GetProperty, null, Graph1, new Object[] { 1 });
  80.                 xAxis.GetType().InvokeMember("Scale", BindingFlags.SetProperty, null, xAxis, new Object[] { 2 });
  81.                 document.GetType().InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, document, new Object[] {listFileName[i]+".grf"});
  82.                 grapher.GetType().InvokeMember("Quit", BindingFlags.InvokeMethod, null, grapher, null);
  83.                 System.GC.Collect(System.GC.GetGeneration(grapher));
  84.                 MessageBox.Show("ok");
  85.             }
  86.         }
  87.     }

  88.    
  89. }
复制代码
不知为何grapher不能像类一样new()新对象,一直报错。只能通过反射调用。哪位高手能够解答一下。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-6-10 16:24:13 | 显示全部楼层
有没有vb写的调用grapher的程序
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表