我需要在PowerShell中启动cmdled托管在AutoCAD内部。 AutoCAD的程序集(它是PowerShell的主机)不在GAC中。如何正确指向AutoCAD的装配?是否可以指向DLL文件的集合而不是程序集名称?已加载到当前AppDomain中的所有必需程序集。
$asm = ([System.AppDomain]::CurrentDomain.GetAssemblies()) | where { `
($_.FullName).StartsWith("acdbmgd") -or ($_.FullName).StartsWith("acmgd") `
-or ($_.FullName).StartsWith("accoremgd")}
$src =[Io.File]::ReadAllText(($PSScriptRoot + "../Resources/example.cs"))
Add-Type -ReferencedAssemblies $asm -TypeDefinition $src -Language CSharp
# Launch our static `Bushman.CAD.PowerShellUtils.Example.WriteMsg()` method:
[Bushman.CAD.PowerShellUtils.Example]::WriteMsg("`nHello from CS-file!`n")
这是../Resources/example.cs
文件的代码:
using System;
using Autodesk.AutoCAD.Runtime;
using cad = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
namespace Bushman.CAD.PowerShellUtils {
public class Example {
public static void WriteMsg(String msg) {
Document doc = cad.DocumentManager.MdiActiveDocument;
if (null == doc || String.IsNullOrEmpty(msg)) {
return;
}
Editor ed = doc.Editor;
ed.WriteMessage(msg);
}
}
}
但我得到错误:
" DatabaseServices"的类型或命名空间的名称在...中缺席 " Autodesk.AutoCAD"的命名空间(程序集引用已通过?) "应用程序"的类型或命名空间的名称在...中缺席 " Autodesk.AutoCAD.ApplicationServices"的名称空间(集会 引用已通过?)
我该如何解决?
答案 0 :(得分:1)
是的,有可能。您需要使用Location
对象的Assembly
属性:
$asm = @(
[System.AppDomain]::CurrentDomain.GetAssemblies() |
Where-Object {
$_.FullName.StartsWith("acdbmgd") -or
$_.FullName.StartsWith("acmgd") -or
$_.FullName.StartsWith("accoremgd")
} |
Select-Object -ExpandProperty Location
)