AutoLoad the dll on AutoCAD startup

AutoLoad the dll on AutoCAD startup

prem_kumar8SXZJ
Enthusiast Enthusiast
8,443 Views
15 Replies
Message 1 of 16

AutoLoad the dll on AutoCAD startup

prem_kumar8SXZJ
Enthusiast
Enthusiast

Hi everyone,

I have created a small plugin in AutoCAD using c# and right now I am using netload to load my dll into AutoCAD.

But I want that when I start my AutoCAD the DLL will automatically load. I tried to create a bundle file including the PackageContents.xml file and place my dll into the bundle folder. But the DLL is not loading automatically.

If anyone has any idea then please help me.

0 Likes
Accepted solutions (2)
8,444 Views
15 Replies
Replies (15)
Message 2 of 16

Ed__Jobe
Mentor
Mentor

Where do you have the bundle folder stored? In one of the areas that AutoCAD looks for them? Your personal area is located at %AppData%\Autodesk\ApplicationPlugins

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 16

_gile
Consultant
Consultant
Accepted solution

Hi,

In this reply, an example of minimalist PackageContents.xml file for autoloading a .NET DLL.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 4 of 16

prem_kumar8SXZJ
Enthusiast
Enthusiast

Hi, Where I can find this product code and upgrade code? So that I can include them in the PackageContents.xml file?

 

ProductCode="{83F90232-3CEB-40F0-88BE-2638C843CEA5}"
UpgradeCode="{B31D4C65-464B-4460-9E9F-B36D7B1C453A}"
0 Likes
Message 5 of 16

_gile
Consultant
Consultant

@prem_kumar8SXZJ wrote:

Hi, Where I can find this product code and upgrade code? So that I can include them in the PackageContents.xml file?

 

ProductCode="{83F90232-3CEB-40F0-88BE-2638C843CEA5}"
UpgradeCode="{B31D4C65-464B-4460-9E9F-B36D7B1C453A}"

You do not "find" them, you create them (there's a "Create GUID" in the Visual Studio Tools menu and many other on the web).

ProductCode shoud be changed a each new version. UpgradeCode should never be changed.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 16

prem_kumar8SXZJ
Enthusiast
Enthusiast

Hi I have created a product code using GUID and Created a folder with a .bundle file and also created all the sub folders and PackageContents.xml file and Paste that bundle folder in C:\Program Files (x86)\Autodesk\ApplicationPlugins\Trapeze.bundle this directory, But still, my dll is not loading why?

0 Likes
Message 7 of 16

_gile
Consultant
Consultant

The 'Trapeze.bundle' was just an example you have to adapt to suit your needs.

Name the .bundle as you need (typically as you project), create new GUIDs for both the ProductCode and the UpgradeCode, change the application Name, Set the SeriesMin and SeriesMax value to the AutoCAD releases you want your app to run on, change the AppName and, for sure, the ModuleName.

You should read this topic and the related references.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 8 of 16

prem_kumar8SXZJ
Enthusiast
Enthusiast

Hi, I have made all the changes and when I open AutoCAD it also shows the message "Stretch Utility has been successfully loaded" where Stretch Utility is my Application name. But then again when I give the command to run some functionality that I written in the Dll, It is saying Unknown command. If I use Netload and then use the command everything is working fine. I don't understand what is going on with the bundle file.

 

<?xml version="1.0" encoding="utf-8"?>
<ApplicationPackage
  SchemaVersion="1.0"
  AppVersion="1.0.0"
  ProductCode="{04A0B285-1593-4604-B4B1-714A231770CD}"
  Name="Stretch Utility"
  AutodeskProduct="AutoCAD"
  ProductType="Application">
  <Components>
    <RuntimeRequirements OS="Win32|Win64" Platform="AutoCAD|AutoCAD*" SeriesMin="R24.3" SeriesMax="R24.3" />
    <ComponentEntry
      AppName="Stretch Utility"
      Version="1.0.0"
      ModuleName="./Contents/AutoCAD_3DProject.dll"
      LoadOnAutoCADStartup="True">
    </ComponentEntry>
  </Components>
</ApplicationPackage>
0 Likes
Message 9 of 16

_gile
Consultant
Consultant
Accepted solution

Do not care about your application Status is "Unknown App" in the application manager dialog. This is due to the fact you application is not one from the Autodesk Application Store.

Does your application contains a class which implements IExtensionApplication? If so, your issue may be due to what does the Initialize method because this method is not called in the same context when the application is autoloaded or when it is netloaded.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 10 of 16

prem_kumar8SXZJ
Enthusiast
Enthusiast

Yes, my class does implement IExtensionApplication because I am creating a ribbon tab and some buttons. I just removed the code for the ribbon tab and now it is loading perfectly. Thanks.
One more question is If I don't use the IExtensionApplication then how I am going to create a ribbon tab and some buttons? Is it through cuix file or there is any other way?

0 Likes
Message 11 of 16

_gile
Consultant
Consultant

You can use IExtensionApplication, but you have to take care of the context the Initialize() method is run.

Typically, you just subscribe to the Application.Idle event in the Initialize method and do your stuff in the event handler to ensure the code is not run before AutoCAD completed its own initialization.

Here's a example:

 

internal class ExtensionApplication : IExtensionApplication
{
    public void Initialize()
    {
        Application.Idle += OnIdle;
    }

    private void OnIdle(object? sender, EventArgs e)
    {
        var doc = Application.DocumentManager.MdiActiveDocument;
        if (doc != null)
        {
            Application.Idle -= OnIdle;
            try
            {
                // Do the initialization stuff here.
            }
            catch (System.Exception ex)
            {
                doc.Editor.WriteMessage($"\nInitilization error: {ex.Message}");
            }
        }
    }

    public void Terminate()
    { }
}

 

You can also use this ExtensionApplicationAsync abstract class from @ActivistInvestor.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 12 of 16

prem_kumar8SXZJ
Enthusiast
Enthusiast

Okay, Thanks for this 😀

0 Likes
Message 13 of 16

OttoDV
Contributor
Contributor

My apologies, I know this is an old topic, but I'm still struggling with this same issue too. I have tried several combinations and followed plenty of manuals in setting up the PackageContents.xml file, even the one above, to no avail. Is there anyone that can help loading my DLL in Civil 3D specific. I've even tried the just AUTOCAD one too. I've attched my file for scrutiny.

0 Likes
Message 14 of 16

ActivistInvestor
Mentor
Mentor

My XML viewer app (on Android) can't open the file, and displays the following error:

 

This page contains the following errors:

error on line 32 at column 20: Opening and ending tag mismatch: Command line 28 and Commands

 

0 Likes
Message 15 of 16

CodeDing
Mentor
Mentor

@OttoDV ,

 

I fixed your tags (added 3 "/" marks), I did not check anything else.

Attached is XML

 

Best,

~DD

0 Likes
Message 16 of 16

kerry_w_brown
Mentor
Mentor

Perhaps this will solve the issue  . . . at least for file structure ?

Summary of Changes:
1. Fixed invalid nesting of <Command> tags.
2. Added missing closing tags for <RuntimeRequirements> and <Components>.
3. Removed unnecessary spaces in attributes.
4. Added comments for clarity.
5. Ensured the XML structure is valid and consistent.

 

<?xml version="1.0" encoding="utf-8"?>
<ApplicationPackage
   SchemaVersion="1.0"
   AppVersion="1.0.1"
   ProductCode="{79A0236D-3C13-47FB-8BC0-C84EC8A3656E}"
   UpgradeCode="{AD0E3688-98E2-440E-8F51-D4EA8CC1AC24}"
   Name="RSA Cogo Importer"
   Description="A custom plugin for Civil 3D to import RSA Cogo points"
   AutodeskProduct="AutoCAD"
   ProductType="Application">

   <!-- Runtime Requirements -->
   <Components>
      <RuntimeRequirements
         OS="Win64"
         Platform="AutoCAD|AutoCAD*"
         SeriesMin="R25.0"
         SeriesMax="R26.3">
      </RuntimeRequirements>

      <!-- Component Entry -->
      <ComponentEntry
         AppName="RSA_Cogo_importer"
         Version="1.0.1"
         ModuleName=".\Contents\RSA_Cogo_importer.dll"
         LoadOnAutoCADStartup="True">

         <!-- Commands -->
         <Commands GroupName="MyPluginCommands">
            <Command
               Local="RSACSVIMPORT"
               Global="RSACSVIMPORT"
               StartupCommand="True" />
            <Command
               Local="RSAUNLOADDIA"
               Global="RSAUNLOADDIA"
               StartupCommand="True" />
         </Commands>
      </ComponentEntry>
   </Components>
</ApplicationPackage>

Stay well,


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes