乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 113|回复: 4

[编程交流] can't reference an assemb

[复制链接]

9

主题

17

帖子

9

银币

初来乍到

Rank: 1

铜币
45
发表于 2022-7-6 22:39:26 | 显示全部楼层 |阅读模式
Hello,
 
I'm trying to implement a simple C# application in VS 2010 and I'm having difficulty.
 
I'm going through Autodesk's .NET developer's guide and I'm trying out their examples on out-of-process applications (under Basics of the AutoCAD .NET API > Out-Of-Process versus In-Process).
 
Here's the code snippet they offer:
 
  1. using System;using System.Runtime.InteropServices;using Autodesk.AutoCAD.Interop;using Autodesk.AutoCAD.Runtime;using Autodesk.AutoCAD.ApplicationServices;[CommandMethod("ConnectToAcad")]public static void ConnectToAcad(){ AcadApplication acAppComObj = null; const string strProgId = "AutoCAD.Application.18"; // Get a running instance of AutoCAD try {     acAppComObj = (AcadApplication)Marshal.GetActiveObject(strProgId); } catch // An error occurs if no instance is running {     try     {         // Create a new instance of AutoCAD         acAppComObj = (AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true);     }     catch     {         // If an instance of AutoCAD is not created then message and exit         System.Windows.Forms.MessageBox.Show("Instance of 'AutoCAD.Application'" +" could not be created.");         return;     } } // Display the application and return the name and version acAppComObj.Visible = true; System.Windows.Forms.MessageBox.Show("Now running " + acAppComObj.Name +                                       " version " + acAppComObj.Version); // Get the active document AcadDocument acDocComObj; acDocComObj = acAppComObj.ActiveDocument; // Optionally, load your assembly and start your command or if your assembly // is demandloaded, simply start the command of your in-process assembly. acDocComObj.SendCommand("(command " + (char)34 + "NETLOAD" + (char)34 + " " +                         (char)34 + "c:/myapps/mycommands.dll" + (char)34 + ") "); acDocComObj.SendCommand("MyCommand ");}
 
Seeing as how this is supposed to work as an out-of-process application, I didn't create the project as a class library as they say to do in all the previous exercises. Instead I created it as an empty project. I brought in my .cs file as a simple code file and pasted the above in it - with a few modifications, of course: I included the following references:
 
  1. using System.Collections.Generic;using System.Linq;using System.Text;using Autodesk.AutoCAD.DatabaseServices;
 
I also created a namespace, a class, and a Main method for an entry point as it is going to run as a stand-alone application:
 
  1. [assembly: CommandClass(typeof(OutOfProcess.OutOfProcess))]namespace OutOfProcess {public class OutOfProcess{   public static void Main()   {       OutOfProcess.ConnectToAcad();   }
 
After this point, the ConnectToAcad() method appears just as in the above code snippet.
 
I only included these elements in order to get it to work and because all the previous examples had them and I'm not experienced enough to know whether or not they can, or should, be left out.
 
On top of that, I did everything the Autodesk guide told me to do whenever interfacing with AutoCAD APIs - namely: reference acmgd.dll, acdbmgd.dll, accui.dll (as needed - but I referenced them all anyway), and to set their copy local property to false. Also, to set the target framework to .NET Framework 3.5.
So I did all that, and the build gives me an error that says:
 
 
This refers to the line using Autodesk.AutoCAD.Interop;
 
Am I missing an assembly reference? I brought in all the .dll's it says (i.e. acmgd.dll, acdbmgd.dll, accui.dll) and set their copy local property to false. Is there some other assembly I need?
 
The guide says
 
 
Since the code does seem to use that ProgID, I'm assuming I do have to reference something related to COM interop (I have no idea what this is, so I'm not sure what I'm doing here).
 
Ive tried variants of the above - for example, setting the framework to 4.0, taking out the namespace stuff, etc. - but none of it works. I've also searched high and low for what kind of assembly interop requires or where to find it.
 
Any ideas?
 
Thanks
回复

使用道具 举报

RMS

9

主题

38

帖子

29

银币

初来乍到

Rank: 1

铜币
45
发表于 2022-7-6 22:55:28 | 显示全部楼层
I have not tried this method but I ran into this and thought it might help:
 
http://through-the-interface.typepad.com/through_the_interface/2007/12/launching-autoc.html
 
http://through-the-interface.typepad.com/through_the_interface/2009/05/interfacing-an-external-com-application-with-a-net-module-in-process-to-autocad-redux.html
回复

使用道具 举报

9

主题

17

帖子

9

银币

初来乍到

Rank: 1

铜币
45
发表于 2022-7-6 23:12:51 | 显示全部楼层
Those are truly invaluable links, RMS.
 
I was able to find my dll after all. It was under C:\ObjectARX 2011\inc-win32\
 
The problem was that I'm not used to Windows 7 and didn't know how to use the search feature properly. I tried searching using the start menu for Autodesk.AutoCAD.Interop.dll and couldn't find it. But later I tried searching on C:\ from an explorer window and I found what I was looking for.
 
Those links will definitely still come in handy as I will need to learn as much as I can about out-of-process and COM applications.
 
Thanks
回复

使用道具 举报

RMS

9

主题

38

帖子

29

银币

初来乍到

Rank: 1

铜币
45
发表于 2022-7-6 23:39:00 | 显示全部楼层
So you got it to run then? Just out of curiosity why would you run out-of-process?
回复

使用道具 举报

9

主题

17

帖子

9

银币

初来乍到

Rank: 1

铜币
45
发表于 2022-7-6 23:51:48 | 显示全部楼层
Just practicing my skills.
 
I got it to run but not without throwing a few exceptions. Working on it.
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 05:38 , Processed in 1.539520 second(s), 62 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表