.NET

Reply
Contributor
henrik.rudstrom
Posts: 25
Registered: ‎07-05-2012
Message 1 of 21 (427 Views)

Autocad vs autocad mechanical (Urgent!)

427 Views, 20 Replies
11-15-2013 08:15 AM

Hi,

I just finished developing an plugin for Autocad 2014 using the managed .net api

It appears that the client also want to use this addin in Autocad Mechanical 2014, but when i run netload on my dll nothing happens and my command is not available. Some googling gave me the impression that autocad mechanical only has a COM and c++ api, is that correct? is there any way i can make my code work in autocad mechanical?

 

Hope someone can give me a quick answer here!

 

Regards

 

Henrik

Distinguished Mentor
BlackBox_
Posts: 745
Registered: ‎02-25-2013
Message 2 of 21 (421 Views)

Re: Autocad vs autocad mechanical (Urgent!)

11-15-2013 08:37 AM in reply to: henrik.rudstrom

Sounds like there's an issue with your code, as (generally speaking) an assembly compiled for vanilla AutoCAD will load into one if its verticals just fine... As example, I use all of my AutoCAD plug-ins with Civil 3D on a daily basis.

 

Hard to tell for sure though, as you've not posted any code, such as any Initialize() evaluation, etc.. More information is needed.

 

Also, instead of manually NETLOADing your assembly, you might try creating an Autoload .bundle since you're using 2014.

 

Cheers



"Potential has a shelf life." - Margaret Atwood


Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

Distinguished Mentor
BlackBox_
Posts: 745
Registered: ‎02-25-2013
Message 3 of 21 (416 Views)

Re: Autocad vs autocad mechanical (Urgent!)

11-15-2013 08:43 AM in reply to: BlackBox_

BlackBox_ wrote:

Sounds like there's an issue with your code, as (generally speaking) an assembly compiled for vanilla AutoCAD will load into one if its verticals just fine... As example, I use all of my AutoCAD plug-ins with Civil 3D on a daily basis.


Apparently, I am mistaken... I'm only finding ObjectARX, and COM developer guides here:

 

http://usa.autodesk.com/adsk/servlet/index?id=14952981&siteID=123112

 

 

 

Sorry for any confusion... I wonder if these API's are only for the Mechanical aspects of the product, and that they still support AutoCAD's .NET API???



"Potential has a shelf life." - Margaret Atwood


Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

Contributor
henrik.rudstrom
Posts: 25
Registered: ‎07-05-2012
Message 4 of 21 (409 Views)

Re: Autocad vs autocad mechanical (Urgent!)

11-15-2013 09:05 AM in reply to: BlackBox_

Hi, 

Thanks for your quick reply, 

Good to know that i didnt make all that code for nothing!

 

my addin is pretty big, but below i've pasted the code for the main class,

I mananged to get it installed on my dev pc now, and with visual studio debugger i can at least see that it loads the dll and steps into the Initialize function

but any idea why my command methods are not available?

 

Just saw your second post: jup that developer guide is what scared me too.... but at least it loads, so maybe there is some hocus pocus setting somewhere that makes my commands invisible?

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Tagit;
using Application = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass(typeof(Program))]
[assembly: ExtensionApplication(typeof(Program))]
namespace Tagit 
{
    class Program : IExtensionApplication
    {
        public static TagitMainAutocad TagitMain;
        private static Document Doc;



        [CommandMethod("TTBalloon")]
        public static void PlaceBalloon()
        {
            if (TagitMain == null)
            {
                if (!ActivateDocument(true))
                    return;
            }
            TagitMain.ShowPosForm();
        }
        [CommandMethod("TTBOM")]
        public static void ShowBOMForm()
        {
            if (TagitMain == null)
            {
                if(!ActivateDocument(true))
                    return;
            }
            TagitMain.ShowForm();
        }

        [CommandMethod("TTADD")]
        public static void CreateItem()
        {
            if (TagitMain == null)
            {
                if (!ActivateDocument(true))
                    return;
            }
            TagitMain.CurrentBOM.BOMTable.CreateItem(TagitMain);
        }

        [CommandMethod("TTCLEANUP")]
        public static void Cleanup()
        {
            if (TagitMain == null)
            {
                if (!ActivateDocument(true))
                    return;
            }
            TagitMain.CurrentBOM.Cleanup();
        }

        [CommandMethod("GetRevision")]
        public static void ReadRevision()
        {
           Doc.Editor.WriteMessage("Revision: " + TagitMain.CurrentBOM.Revision.DisplayValue + "\n\n");
        }

        [CommandMethod("SetRevision")]
        public static void WriteRevision()
        {
            var res = Doc.Editor.GetString("Enter revision");
            TagitMain.CurrentBOM.Revision = new Revision(res.StringResult);
        }
        [CommandMethod("ReadBalloons")]
        public static void ReadBalloons()
        {
            using (var tr = new QueryTransaction(TagitMain.Database))
            {
                foreach (DBObject obj in tr.Find(e => e is MLeader))
                {
                    var xdata = obj.GetXDataForApplication(TagitMainAutocad.ApplicationName);
                    if (xdata == null)
                    {
                        TagitMain.Editor.WriteMessage("No XDATA \n\n");
                        continue;
                    }
                    var array = xdata.AsArray();
                    TagitMain.Editor.WriteMessage("MLeader: " + array[0].Value.ToString() + ", " + array[1].Value.ToString() + ", " + array[2].Value.ToString() + "\n\n");
                }
            }
            
        }

        [CommandMethod("ReadItems")]
        public static void ReadBOMItems()
        {
            foreach (var block in TagitMain.CurrentBOM.BOMTable.GetTableItems())
            {
                using (var trans = new QueryTransaction(TagitMain.Database))
                {
                    string items = "";
                    foreach (var item in trans.GetBlockAttributes(block))
                    {
                        items += item.Key + ": " + item.Value + ", ";
                    }
                    items += "\n\n";
                    TagitMain.Editor.WriteMessage(items);

                }

            }
        }

        [CommandMethod("ReadXData")]
        public static void ReadXData()
        {
            using (var trans = new QueryTransaction(TagitMain.Database))
            {
                foreach (
                    BlockReference block in
                        trans.Find(e => e is BlockReference && e.Name == BOMTable.TableItemBlockName))
                {
                    var x = block.GetXDataForApplication(TagitMainAutocad.ApplicationName);
                    
                    TagitMain.Editor.WriteMessage("Xdata: " + x.ToString());
                    
                        
                    
                    
                    
                }



            }



        }


        public void Initialize()
        {
            Application.DocumentManager.DocumentActivated += DocumentManagerOnDocumentActivated;
            Application.DocumentManager.DocumentToBeDeactivated += DocumentManagerOnDocumentToBeDeactivated;
            
            
            ActivateDocument();
        }

        private void DocumentManagerOnDocumentToBeDeactivated(object sender, DocumentCollectionEventArgs e)
        {



            if (TagitMain != null)
            {
                using (e.Document.LockDocument())
                {
                    ActivateDocument();
                }
            }
            TagitMain = null;
        }



        public static bool ActivateDocument(bool showMessage = false)
        {
            var errors = TagitMainAutocad.IsValidDocument(Application.DocumentManager.MdiActiveDocument);
            if (errors.Count > 0)
            {
                if (showMessage)
                {
                    var message = "This document is not compatible with Tagit. Missing following elements: \n";
                    foreach (var error in errors)
                    {
                        message += "- " + error + "\n";
                    }
                    MessageBox.Show(message, "Tagit: Incompatible document.");
                    
                }
                return false;
            }

            TagitMain = new TagitMainAutocad();
            Doc = Application.DocumentManager.MdiActiveDocument;
            TagitMain.Initialize(Doc);
            return true;
        }

        private void DocumentManagerOnDocumentActivated(object sender, DocumentCollectionEventArgs e)
        {
            using (e.Document.LockDocument())
            {
                ActivateDocument();    
            }
            
            
            
        }

        public void Terminate()
        {
            Application.DocumentManager.DocumentActivated -= DocumentManagerOnDocumentActivated;
            Application.DocumentManager.DocumentToBeDeactivated -= DocumentManagerOnDocumentToBeDeactivated;
        }
    }
}

 

Distinguished Mentor
BlackBox_
Posts: 745
Registered: ‎02-25-2013
Message 5 of 21 (405 Views)

Re: Autocad vs autocad mechanical (Urgent!)

11-15-2013 09:13 AM in reply to: henrik.rudstrom

I haven't scanned the entire code, but this jumped out to me right away... Shouldn't this line:

 

[assembly: CommandClass(typeof(Program))]

 

 

... Be this:

 

[assembly: CommandClass(typeof(Tagit.Program))]

 

Again, not sure if that's the (only?) issue, but it did get my attention.

 

HTH



"Potential has a shelf life." - Margaret Atwood


Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

Distinguished Mentor
BlackBox_
Posts: 745
Registered: ‎02-25-2013
Message 6 of 21 (404 Views)

Re: Autocad vs autocad mechanical (Urgent!)

11-15-2013 09:15 AM in reply to: BlackBox_

Sorry, just saw the using statement for Tagit namespace.

 

Please disregard.



"Potential has a shelf life." - Margaret Atwood


Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

Distinguished Mentor
BlackBox_
Posts: 745
Registered: ‎02-25-2013
Message 7 of 21 (401 Views)

Re: Autocad vs autocad mechanical (Urgent!)

11-15-2013 09:20 AM in reply to: BlackBox_

It's looking like you're going to have to use COM, my friend... Everything I'm finding for .NET + Mechanical is in COM.

 

Perhaps someone more knowledgeable than I can verify?



"Potential has a shelf life." - Margaret Atwood


Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

Contributor
henrik.rudstrom
Posts: 25
Registered: ‎07-05-2012
Message 8 of 21 (385 Views)

Re: Autocad vs autocad mechanical (Urgent!)

11-15-2013 09:43 AM in reply to: BlackBox_

jup, only found references to com and c++, but i still find it strange, ive developed for plant3d and other verticals without problem, and still find it hopeful that it actually loads the dll and enters the Initialize function, noticed that when i installed mechinical that it upgraded my vanilla autocad to service pack 1 as well (it seems to use the same autocad executable), and also now that i run it in vanilla, that my commands are not available... maybe its an upgrade issue??

strange...

 

Thanks a lot for your efforts blackbox though,

 

 

rewriting it is not really an option (3-4000 lines of code), so at least would be nice to have it from an official source that ac mechanical is not comaptible with managed .net

 

or does anyone know if the service pack makes any difference?

 

 

 

 

 

 

Distinguished Mentor
BlackBox_
Posts: 745
Registered: ‎02-25-2013
Message 9 of 21 (380 Views)

Re: Autocad vs autocad mechanical (Urgent!)

11-15-2013 10:05 AM in reply to: henrik.rudstrom

henrik.rudstrom wrote:

 

Thanks a lot for your efforts blackbox though,

 


You're welcome; I'm always happy to not help. LoL

 

Cheers



"Potential has a shelf life." - Margaret Atwood


Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

Distinguished Mentor
owenwengerd
Posts: 619
Registered: ‎08-06-2002
Message 10 of 21 (345 Views)

Re: Autocad vs autocad mechanical (Urgent!)

11-16-2013 08:48 PM in reply to: henrik.rudstrom

Put a try/catch around the code in your IExtensionApplication::Initialize function that prints the info about the caught exception, then let us know what the exception is when you try to NETLOAD your DLL.

--
Owen Wengerd
ManuSoft
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

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