CAD-страница НП | Статьи | Download | English

Н.Н.Полещук. Проблемы мастера при создании для AutoCAD 2010 каркаса приложения на C# или VB.NET

При установке мастеров ObjectARX версий 2005 и выше автоматически устанавлваются мастера для создания приложений с управляемым кодом на языках C# и Visual Basic.NET. К сожалению, каркас новых приложений в версии 2010 содержит недоработки, которые препятствуют нормальной работе пользователей.

Проблема DLL

1. При создании с помощью мастера каркаса проекта типов "AutoCAD Managed C# Project" и "AutoCAD Managed VB Project Application" возникает ошибка с таким сообщением:

Ошибка зарыта в неправильном пути поиска библиотек AcMgd.dll и AcDbMgd.dll во время работы скриптов в файлах D:\ObjectARX 2010 Wizards for AutoCAD 2010\AutoCAD Managed CS App\Scripts\1033\default.js и ObjectARX 2010 Wizards for AutoCAD 2010\AutoCAD Managed VB App\Scripts\1033\default.js (в предположении, что для установки мастеров вы указали папку D:\ObjectARX 2010 Wizards for AutoCAD 2010).
За добавление к проекту библиотек отвечает следующий кусок default.js:

//- Add references to acmgd.dll abd acdbmgd.dll
var strAcadPath = FindAutoCAD();
var strCompleteAcadPath =strAcadPath + 'acad.exe';
var strAcmgdPath =strAcadPath + 'acmgd.dll' ;
var strAcdbmgdPath = strAcadPath + 'acdbmgd.dll';
var strAcCuiPath = strAcadPath + 'AcCui.dll';
//wizard.OkCancelAlert (configMgr.Item(1).ConfigurationName);

var configs =new Enumerator (configMgr) ;
for ( ; !configs.atEnd () ; configs.moveNext () ) {
configs.item ().Properties ("StartAction").Value =1 ; //- Need to set it to Start Program
configs.item ().Properties ("StartProgram").Value =strCompleteAcadPath ;
}

//var DebugTool =config.DebugSettings //DebugTool.Command =strAcadPath ;
try {
var newRef =project.Object.References.Add (strAcmgdPath) ;
newRef.CopyLocal =false ;
newRef =project.Object.References.Add (strAcdbmgdPath) ;
newRef.CopyLocal = false;
newRef = project.Object.References.Add(strAcCuiPath);
newRef.CopyLocal = false;
}
catch (e) {
wizard.OkCancelAlert("Failed to add AutoCAD Managed DLL,\nFiles not found in default path.");
}

Значение переменной strAcadPath вычисляется функцией FindAutoCAD:

function FindAutoCAD() {
var szVersion = "1";
var szPath = "c:\\Program Files\\AutoCAD";
var acadId = "{5783F2D7-%-%-0102-0060B0CE6BBA}";
var objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");
var colSoftware = objWMIService.ExecQuery("Select * from Win32_Product Where IdentifyingNumber like '" + acadId + "' AND Vendor = 'Autodesk'");
var enumItems = new Enumerator(colSoftware);
for (; !enumItems.atEnd(); enumItems.moveNext()) {
var objItem = enumItems.item();
if (objItem.Version > szVersion) {
szPath = objItem.InstallLocation;
szVersion = objItem.Version;
}
}
return (szPath);
}

Сразу видно, что в функции FindAutoCAD начальное значение переменной szPath почему-то жестко завязано на "c:\\Program Files\\AutoCAD".
Для исправления проще всего не трогать FindAutoCAD, а задать переменной strAcadPath свой путь к папке AutoCAD 2010, закомментировав старый вариант строки, например:

//var strAcadPath = FindAutoCAD();
var strAcadPath = "D:\\Autodesk\\AutoCAD 2010 Eng-32\\";

Проблемы компиляции

2. В файлах AssemblyInfo.vb и AssemblyInfo.cs строки
<Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyFileVersion("1.0.*")>
надо заменять на
<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>
Иначе получите ошибку компиляции.

3. В файле AssemblyInfo.vb следующие строки комментариев почему-то даны с //, хотя надо с апострофом:
//
// In order to sign your assembly you must specify a key to use. Refer to the
// Microsoft .NET Framework documentation for more information on assembly signing.
//
// Use the attributes below to control which key is used for signing.
//
// Notes:
//   (*) If no key is specified, the assembly is not signed.
//   (*) KeyName refers to a key that has been installed in the Crypto Service
//       Provider (CSP) on your machine. KeyFile refers to a file which contains
//       a key.
//   (*) If the KeyFile and the KeyName values are both specified, the
//       following processing occurs:
//       (1) If the KeyName can be found in the CSP, that key is used.
//       (2) If the KeyName does not exist and the KeyFile does exist, the key
//           in the KeyFile is installed into the CSP and used.
//   (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
//       When specifying the KeyFile, the location of the KeyFile should be
//       relative to the project output directory which is
//       %Project Directory%\obj\. For example, if your KeyFile is
//       located in the project directory, you would specify the AssemblyKeyFile
//       attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
//   (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
//       documentation for more information on this.
//
Удалите эти строки или замените // на апостроф, чтобы избавиться от ошибки компиляции.

4. В файле AssemblyInfo.vb надо закомментировать строку
<Assembly: Guid("[!output GUID_ASSEMBLY]")>
т.к. не требуется GUID для сборки.


CAD-страница НП | Статьи | Download | English