天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 54|回复: 0

如何将所有内容从 arx 应用程序加载到 AutoCAD 中。

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
[code]如何将所有内容从 arx 应用程序加载到 AutoCAD 中。网络程序集
//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
#include "Psapi.h"

using namespace System;
using namespace System::Reflection;
using namespace Autodesk::AutoCAD::ApplicationServices;
using namespace Autodesk::AutoCAD::DatabaseServices;
using namespace Autodesk::AutoCAD::EditorInput;

//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CGetLoadedApp : public AcRxArxApp {

public:
  CGetLoadedApp() : AcRxArxApp() {}

  virtual AcRx::AppRetCode On_kInitAppMsg(void *pkt) {
    AcRx::AppRetCode retCode = AcRxArxApp::On_kInitAppMsg(pkt);
    return (retCode);
  }

  virtual AcRx::AppRetCode On_kUnloadAppMsg(void *pkt) {
    AcRx::AppRetCode retCode = AcRxArxApp::On_kUnloadAppMsg(pkt);
    return (retCode);
  }

  virtual void RegisterServerComponents() {  }

  static void RivilisGetLoadedMGD() {
    Document^ doc = Application::DocumentManager->MdiActiveDocument;

    if (doc == nullptr) return;
    Editor^ ed = doc->Editor;
    for each (Assembly^ ass in AppDomain::CurrentDomain->GetAssemblies())
    {
      ed->WriteMessage("\nName = {0}", ass->GetName(false)->Name);
      ed->WriteMessage("\n\tFull Name = {0}", ass->FullName);
      try  {
        ed->WriteMessage("\n\tLocation = {0}", ass->Location);
      }
      catch (...) {
        ed->WriteMessage("\n\tNo Location. Possible dynamic assembly");
      };
    }
  }
};

//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CGetLoadedApp)

ACED_ARXCOMMAND_ENTRY_AUTO(CGetLoadedApp, Rivilis, GetLoadedMGD, GetLoadedMGD, ACRX_CMD_MODAL, NULL)

‎[/code]

[code]//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"

#include <atlsafe.h>
#import <mscorlib.tlb> rename("ReportEvent","ReportEventManaged")
#include <metahost.h>
#pragma comment(lib,"mscoree.lib")
#include <mscoree.h>
#include <comdef.h>

using namespace mscorlib;

//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CGetMgdFromNativeApp : public AcRxArxApp {

public:
  CGetMgdFromNativeApp() : AcRxArxApp() {}

  virtual AcRx::AppRetCode On_kInitAppMsg(void *pkt) {
    AcRx::AppRetCode retCode = AcRxArxApp::On_kInitAppMsg(pkt);
    return (retCode);
  }

  virtual AcRx::AppRetCode On_kUnloadAppMsg(void *pkt) {
    AcRx::AppRetCode retCode = AcRxArxApp::On_kUnloadAppMsg(pkt);
    return (retCode);
  }

  virtual void RegisterServerComponents() {
    //----- Self-register COM server upon loading.
    if (FAILED(::DllRegisterServer()))
      acutPrintf(_RXST("Failed to register COM server.\n"));
  }

  static void RivilisGetManagedDlls() {
    CComPtr<ICLRMetaHost> spClrMetaHost;
    // Получаем MetaHost
    HRESULT hr = CLRCreateInstance(
      CLSID_CLRMetaHost,
      IID_PPV_ARGS(&spClrMetaHost)
    );
    _ASSERT(hr == S_OK);

    // Получаем runtime-версию (соответствует .NET 4)
    CComPtr<ICLRRuntimeInfo> spCLRRuntimeInfo;
    hr = spClrMetaHost->GetRuntime(L"v4.0.30319",
      IID_PPV_ARGS(&spCLRRuntimeInfo)
    );
    _ASSERT(hr == S_OK);

    // Получаем CorRuntimeHost
    CComPtr<ICorRuntimeHost> spCorRuntimeHost;
    hr = spCLRRuntimeInfo->GetInterface(
      CLSID_CorRuntimeHost,
      IID_PPV_ARGS(&spCorRuntimeHost)
    );
    _ASSERT(hr == S_OK);

    // Стартуем CLR
    hr = spCorRuntimeHost->Start();
    _ASSERT(hr == S_OK);

    // Получаем домен приложения по-умолчанию
    CComPtr<IUnknown> spAppDomainThunk;
    hr = spCorRuntimeHost->GetDefaultDomain(&spAppDomainThunk);
    _ASSERT(hr == S_OK);

    // Конвертируем AppDomain IUnknown в _AppDomain
    CComPtr<_AppDomain> spAppDomain;
    hr = spAppDomainThunk->QueryInterface(IID_PPV_ARGS(&spAppDomain));
    _ASSERT(hr == S_OK);
    // Получаем массив сборок домена
    SAFEARRAY *pAssemblyArray = spAppDomain->GetAssemblies();

    CComSafeArray<IUnknown*> csaAssemblies;
    csaAssemblies.Attach(pAssemblyArray);
    long cAssemblies = csaAssemblies.GetCount();
    for (long i = 0; i < cAssemblies; i++)
    {
      CComPtr<_Assembly> spAssembly;
      spAssembly = csaAssemblies[i];
      if (spAssembly == NULL)
        continue;
      CComBSTR asmFullName;
      hr = spAssembly->get_FullName(&asmFullName);
      if (FAILED(hr))
        continue;
      AcString asmName = asmFullName;
      int iComma = asmName.find(L',');
      if (iComma > 0) asmName = asmName.left(iComma);
      acutPrintf(L"\n\nName:%s", asmName.constPtr());
      acutPrintf(L"\n\tFull Name:%s", asmFullName);
      CComBSTR asmLocatation;
      hr = spAssembly->get_Location(&asmLocatation);
      if (!FAILED(hr))
        acutPrintf(L"\n\tLocation: %s", asmLocatation);
      else
        acutPrintf(L"\n\tLocation not found");
    }
    // Останавливаем CLR
    hr = spCorRuntimeHost->Stop();
    _ASSERT(hr == S_OK);

  }

};

//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CGetMgdFromNativeApp)

ACED_ARXCOMMAND_ENTRY_AUTO(CGetMgdFromNativeApp, Rivilis, GetManagedDlls, GetManagedDlls, ACRX_CMD_MODAL, NULL)[/code]

‎Arx 应用程序可以是本机应用程序,也可以是混合的。无论哪种方式,都要得到一切。NET 程序集必须使用 AppDomain:: GetAssemblies 方法。对于混合代码,它非常简单:‎

 

 

 

 

如何将所有内容从 arx 应用程序加载到 AutoCAD 中。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 11:40 , Processed in 0.147004 second(s), 27 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表