在C#中编辑Solidwork的系统选项

时间:2015-09-18 19:12:25

标签: c# solidworks

我正在尝试通过我编写的C#程序在SolidWork的选项菜单中编辑几个设置。代码如下:

using System;
using System.IO;
using SldWorks;
using SwConst;

static void Main(string[] args)
{
  SldWorks.SldWorks swApp;
  swApp = new SldWorks.SldWorks();

  swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSingleCommandPerPick, true); /// Single command per pick
  swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swEditMacroAfterRecord, true); /// Automatically edit macro after recording
  swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swUserEnableFreezeBar, true);  /// Enable Freeze bar

  Console.WriteLine("Settings applied");
}

此程序的目的是将这三个选项(复选框)切换为true。到目前为止,这根本不起作用。即使在我运行程序后,选项仍然保持不变。我错过了什么或者我的代码错了吗?

2 个答案:

答案 0 :(得分:0)

尝试此操作(例如,鼠标速度):

//查看旋转 - 鼠标速度 bool boolstatus = swApp.SetUserPreferenceIntegerValue((int)swUserPreferenceIntegerValue_e.swViewRotationMouseSpeed,56);

感谢Solidworks API: Fiddle here

答案 1 :(得分:0)

在SolidWorks运行时尝试使用以下内容获取COM对象。

Try
{
    SldWorks swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application");
    swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSingleCommandPerPick, true); /// Single command per pick
    swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swEditMacroAfterRecord, true); /// Automatically edit macro after recording
    swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swUserEnableFreezeBar, true);  /// Enable Freeze bar



    Console.WriteLine("Settings applied");
}
catch()
{
    Console.WriteLine("Failed to get SolidWorks");
}