1

I need to launch the cmdled in PowerShell is hosted inside of AutoCAD. Assemblies of AutoCAD (it is host of PowerShell) are not in GAC. How can I correctly to point the assemblies of AutoCAD? Is it possible to point the set of the DLL files instead of Assembly names? All necessary assemblies already loaded in the current 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")

This is code of the ../Resources/example.cs file:

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);
        }
    }
}

But I get errors:

The name of type or namespace of "DatabaseServices" is absent in a namespace of "Autodesk.AutoCAD" (the assembly reference is passed?).
The name of type or namespace of "Application" is absent in a namespace of "Autodesk.AutoCAD.ApplicationServices" (the assembly reference is passed?)

How can I fix it?

4

1 回答 1

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
)
于 2016-02-03T15:45:26.963 回答