0

我正在尝试通过我编写的 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。到目前为止,这根本不起作用。即使在我运行程序之后,选项仍然保持不变。我错过了什么还是我的代码错了?

4

2 回答 2

0

试试这个(例如,鼠标速度):

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

感谢 Solidworks API: http ://help.solidworks.com/2012/English/api/sldworksapi/Get_and_Set_User_Preferences_Example_CSharp.htm

于 2015-09-30T20:42:52.067 回答
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");
}
于 2016-05-03T18:19:50.487 回答