.NET

Reply
Valued Mentor
Ajilal.Vijayan
Posts: 446
Registered: ‎01-12-2008
Message 1 of 6 (512 Views)

Acsmcomponents.tlb referencing from local folder

512 Views, 5 Replies
04-13-2012 07:29 AM

Hai all.

 

I am trying to reference the sheet set from C:\ObjectARX 2012\inc-win32\acsmcomponents18.tlb folder.

 

But after selecting the file from above location, the reference path is showing from the project  \bin  folder.

I have set the 'Copy local' to No also.

 

I am using Civil 3D 2012,Visual Studio 2010 and a 32bit operation system.

 

Also how we can avoid the GAC folder to reference the path ?

Sometimes when I am adding the reference to sheet set components, Autocad/ObjectDBX components loading from the GAC folder. [ See the attached Image]

 

Thanks

AJIL

*Expert Elite*
norman.yuan
Posts: 1,017
Registered: ‎04-27-2009
Message 2 of 6 (499 Views)

Re: Acsmcomponents.tlb referencing from local folder

04-13-2012 09:27 AM in reply to: Ajilal.Vijayan

Sheet set component defined in AcSmComponents18.tlb is a COM componenet, not a .NET stuff. Autodesk provides PIA (primary interop assembly) to the Acad/ObjectDBX COM components and has them installed in the GAC when Autocad is installed. Hwever, Autodesk does not supply a .NET interop wrapper.

 

So, when you manually add the reference to to it, VS will generate a .NET interop wrapper. In VS2010, VS may set the interop DLL as "Embedded". You should change it to False, and you SHOULD set "Copy Local" to True (because AutoCAd does not supply this .NET interop wrapper).

 

To use COM component in .NET application I would not use any DLL/TLB from ObjectAXR SDK. Since COM components must be installed and registered, only the registered ones work with the running computer. If you use the same DLL/TLB from other source (such as ObjectARX SDK), there is always CHANCE the DLL\TLB may be different from the ones registered with your computer. To run a program that uses COM components, only registered components matter.

Valued Mentor
Ajilal.Vijayan
Posts: 446
Registered: ‎01-12-2008
Message 3 of 6 (477 Views)

Re: Acsmcomponents.tlb referencing from local folder

04-14-2012 08:13 AM in reply to: norman.yuan

Hai

thanks for the reply.


So Instead of using the DLL/TLB files from OBJARX SDK folder, you mean it should be referenced from Autodesk shared folder from Common files folder ?

 

Also now I am getting some warnings and while using the compiled dll in autocad, when I am entering the app command I am getting error saying COM+ is required.

 

Warings

 

Warnings.jpg

 

Error

 

Error.jpg

 

 


*Expert Elite*
norman.yuan
Posts: 1,017
Registered: ‎04-27-2009
Message 4 of 6 (458 Views)

Re: Acsmcomponents.tlb referencing from local folder

04-14-2012 08:41 PM in reply to: Ajilal.Vijayan

What kind of application are you doing and where does it run? You are not doing something that runs on the server side, are you?

Valued Mentor
Ajilal.Vijayan
Posts: 446
Registered: ‎01-12-2008
Message 5 of 6 (455 Views)

Re: Acsmcomponents.tlb referencing from local folder

04-15-2012 12:54 AM in reply to: norman.yuan

 

No, I am not doing which run on server.

 

I would like to create an application which can be run in AutoCAD 2012.

 

The application will ask the user to select a *.dst file and after selecting the file , the sheet set properties will display in a dialog box where you can edit the custom properties and will have an option to write/read from an external source [ Excel or Access].

 

I am new to .NET and I have created a similar program in VBA , but as AutoCAD no longer supporting VBA and VLISP doesnt allow to access the sheet set , I am trying to create in .NET.

 

Regards

AJIL

 

 

 

*Expert Elite*
norman.yuan
Posts: 1,017
Registered: ‎04-27-2009
Message 6 of 6 (430 Views)

Re: Acsmcomponents.tlb referencing from local folder

04-16-2012 09:21 PM in reply to: Ajilal.Vijayan

I put together some simple code that works with Autocad 2012 (64bit). I tried with both VS2008 (targeting .NET 3.5, which I commented out "<supported runtime...4.0/>" in acad.exe.config) and VS2010 (target .NET 4.0). Both works.

 

In both projects, I added reference to AcSmComponents18 1.0 type library from COM tab of References dialog box (i.e. I set reference to the registered DLL/TLB installed by AutoCAd, not by browsing to the one from ObjectARX SDK). Once the reference is set, VS generate a ,NET wrapper to the COM component: Interop.ACSMCOMPONENTS18Lib.dll

 

The code as following:

 

A Sheetset utility class:

 

using ACSMCOMPONENTS18Lib;

namespace Acad2012SheetSet
{
    public class SheetSetUtil
    {
        private static SheetSetUtil _instance = null;
        private static AcSmSheetSetMgr _mgr=null;

        public SheetSetUtil()
        {
            _mgr = new AcSmSheetSetMgr();
        }

        ~SheetSetUtil()
        {
            if (_mgr != null)  _mgr.CloseAll();
        }

        public static SheetSetUtil Instance
        {
            get
            {
                if (_instance == null) _instance = new SheetSetUtil();
                return _instance;
            }
        }

        public SheetSetInfo GetSheetSetInformation(string dstFileName)
        {
            SheetSetInfo info = null;

            AcSmDatabase db = _mgr.OpenDatabase(dstFileName, false);
            AcSmSheetSet ss = db.GetSheetSet();

            info = new SheetSetInfo();
            info.SheetSetName = ss.GetName();

            return info;
        }
    }
}

 A data class:

namespace Acad2012SheetSet
{
    public class SheetSetInfo
    {
        public string SheetSetName { set; get; }
    }
}

 and finally a command class:

 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(Acad2012SheetSet.MyCommands))]

namespace Acad2012SheetSet
{
    public class MyCommands 
    {
        [CommandMethod("SSInfo", CommandFlags.Session)]
        public static void GetSheetSetName()
        {
            Document dwg = Application.DocumentManager.MdiActiveDocument;
            Editor ed = dwg.Editor;

            string ssFile = 
                @"C:\Users\norm\Documents\AutoCAD Sheet Sets\TestSet.dst";

            try
            {
                SheetSetInfo ssInfo = 
                    SheetSetUtil.Instance.GetSheetSetInformation(ssFile);
                ed.WriteMessage("\nSheetSet Name: {0}", ssInfo.SheetSetName);
            }
            catch(System.Exception ex)
            {
                ed.WriteMessage("\nError: {0}", ex.Message);
            }
        }
    }
}

 Compile and NETLOAD the code into AutoCAD, and run the command "SSInfo", the sheetset's name prints at command line correctly.

 

However, there is one thing I have to point out:

 

InVS2008 project (it would be the same as VS2010 project targeting .NET3.x), the Copy Local of the generated interop assembly should be set to True.

 

While in VS2010 targeting .NET4.0, if I set "Embedded" of the interop assembly to False and set CopyLocal to "True", I get runtime exception when the code instantiate AcSmSheetSetMgr class. I had to embed the interop assembly. This is different from what I said in previous post. However, there are reports saying embedding interop assembly in Acad add-in would not work (see this link http://www.theswamp.org/index.php?topic=41497.0).

 

So, I guess, we have to try both embed and not embed in somce cases.

 

Nonetheless, the code shown above works form me.

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.