Code Monkey home page Code Monkey logo

chuongmep / cadaddinmanager Goto Github PK

View Code? Open in Web Editor NEW
62.0 3.0 14.0 1.58 MB

Cad AddinManager update .NET assemblies without restart Autocad and Civil3D for developer.

Home Page: https://chuongmep.com/posts/2022-04-28-CAD-Civil3D-Addin-Manager.html

License: MIT License

Batchfile 0.03% PowerShell 1.69% C# 96.61% Visual Basic .NET 1.40% Common Lisp 0.27%
addinmanager autocad autocadapi autodesk bim cad cadapi civil3d autocad-api cadaddinmanager

cadaddinmanager's Introduction

Cad Add-in Manager

Autocad API Platform License: MIT

ReSharper Rider Visual Studio 2022 .NET Framework

Publish Github All Releases HitCount follow on Twitter

Summary

AddinManager

Usually, when developing and debugging an addin with Autocad or Civil3D API, user has to close & re-open Autocad or Civil3D each time he/she modifies the addin code and wants to re-compile. But with Add-In Manager, user can modify and run the Addin. directly without closing & re-opening Autocad or Civil3D again and again.This is a next branch from Revit Addin Manager to support multiple platform API for developer. With current technology, you can use Hot Reload to speed it up.But try this project it will be faster with any Addin.

Some feature include:

  • A newbie can create a new Add-in and explore AutoCAD or Civil3D API easy with Add-in manager.
  • Add-in tester(use Debug and Trace to test your add-in).
  • Debug / Trace : Support Show result use Debug or Trace to show result in Autocad or Civil3D.
  • Add-in manager
    • AddInManager Manual : Use for normal process load/unload addin
    • AddInManager Faceless : use for load last process before addin without UI
  • Allow user know whether plugin can load successfully or not.
  • F5 - Load fresh plugin don't need load again.
  • F1 - Go link open source report some error,bug or feature request.
  • Delete - Quick remove by use right click or use from keyboard.
  • Crt + MouseWheel - Zoom in/out by use mouse wheel in command plugin.
  • Arrow Up - Move from TreeView to search.
  • Arrow Down - Move from search to TreeView.
  • Esc - Quick Close Add-in Manager.
  • Enter - Quick Run Execute a command selected in Add-in Manager.

Add-In Manager

Command

  • AddInManagerManual
  • AddInManagerFaceless

Execute a command easily :

  1. Create a class library use .NET

  2. Add library Autocad API or Civil3D API

  3. Create a command, example:

   [CommandMethod("DoSomething")]
   public void Execute()
   {
       // do some thing code here
   }

4.Load To Add-in Manager.

5.Double click to run command.

6.Use faceless when you change code or rebuild.

Lisp Function

Execute a Lisp Function easily :

  1. Create a class library use .NET

  2. Add library Autocad API or Civil3D API

  3. Create a Lisp Function, example:

   [LispFunction("DisplayFullName")]
   public static void DisplayFullName(ResultBuffer rbArgs)
   {
       if (rbArgs != null)
       {
           string strVal1 = "";
           string strVal2 = "";
           int nCnt = 0;
           foreach (TypedValue rb in rbArgs)
           {
               if (rb.TypeCode == (int) LispDataType.Text)
               {
                   switch (nCnt)
                   {
                       case 0:
                           strVal1 = rb.Value.ToString();
                           break;
                       case 1:
                           strVal2 = rb.Value.ToString();
                           break;
                   }
                   nCnt = nCnt + 1;
               }
           }
           Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nName: " + strVal1 + " " + strVal2);
           MessageBox.Show("Updated");
       }
   }

4.Load To Add-in Manager.

5.Use Reload when you change code or rebuild.

6.Run Lisp Function example : (displayfullname "First" "Last")

Trace/Debug

  • Show/Hide result inside Dockpanel Autocad and Civil3D.
  • Show Result history inside CadAddinManager.
  • Clear Result.
  • Show Result by color.

A sample command to execute:

using System.Diagnostics;
using Autodesk.AutoCAD.Runtime;
public class DebugTraceTest
{
    [CommandMethod("DebugTraceTest")]
    public void Action()
    {
        //Trace or Debug Something
        Trace.WriteLine($"Warning: This is a warning");
        Trace.WriteLine($"Error: This is a error");
        Trace.WriteLine($"Add: This is a add");
        Trace.WriteLine($"Modify: This is a modify");
        Trace.WriteLine($"Delete: This is a delete");
    }
}

Installation

Please follow last release at section Release

Support Autocad or Civil3D Version : 2020, 2021, 2022, 2023.

Guideline

You can visit to wiki and read document or access by this link.


Author

Originally implemented by ChuongHo with platform WPF and add more feature to fit with the progressive development of modern technology. His focus is to work smarter and achieve the most effective practices to enhance data utilization and digital collaboration among AEC parties.


License

This sample is licensed under the terms of the MIT License. Please see the License file for full details.


Contribute

Add-In Manager is an open-source project and would be nothing without its community. You can make suggestions or track and submit bugs via Github issues. You can submit your own code to the Add-In Manager project via a Github pull request .

Many Thanks all contributors for this repository. Feel free to contribute! Please refer to the CONTRIBUTING for details.


Sponsors

Thanks for providing a free All product IDE for this project.


Credits

Known Issues

Learning Resources

cadaddinmanager's People

Contributors

chuongmep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cadaddinmanager's Issues

Does not seem to have support for LISP Functions

Is your feature request related to a problem? Please describe.
Not a problem, just something that would be a nice addition.

AutoCAD .NET API allows for exposing functions to LISP. Perhaps it would be nice to be able to test these the same way as we do CommandMethods. Perhaps they load up on another tab? Because we would have to pass in result buffers to a LISP call, we would need some way to handle that as well.

More on LISP functions at this link
http://docs.autodesk.com/ACD/2011/ENU/filesMDG/WS1a9193826455f5ff-e569a0121d1945c08-17c3.htm

Describe the solution you'd like
A request that I think would make this tool even better. There are of course other ways to test these.

Describe alternatives you've considered
Could make CommandMethods to test sub functions called in the LISP Function

Add in fails to load assembly

Describe the bug
When loading a dll the addin throws:

Loading AeciRibbonUiApi...Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'accoremgd, Version=24.2.0.0, Culture=neutral, PublicKeyToken=null'
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
   at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
   at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
   at Mono.Cecil.TypeReference.Resolve()
   at Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
   at Mono.Cecil.SignatureReader.ReadCustomAttributeEnum(TypeReference enum_type)
   at Mono.Cecil.SignatureReader.ReadCustomAttributeElement(TypeReference type)
   at Mono.Cecil.SignatureReader.ReadCustomAttributeConstructorArguments(CustomAttribute attribute, Collection`1 parameters)
   at Mono.Cecil.MetadataReader.ReadCustomAttributeSignature(CustomAttribute attribute)
   at Mono.Cecil.CustomAttribute.<Resolve>b__35_0(CustomAttribute attribute, MetadataReader reader)
   at Mono.Cecil.ModuleDefinition.Read[TItem](TItem item, Action`2 read)
   at Mono.Cecil.CustomAttribute.Resolve()
   at Mono.Cecil.CustomAttribute.get_ConstructorArguments()
   at CadAddinManager.Model.AssemLoader.ResolveDuplicateMethod(String originalFilePath)
   at CadAddinManager.Model.AssemLoader.LoadAddinsToTempFolder(String originalFilePath, Boolean parsingOnly)
   at CadAddinManager.ViewModel.AddinManager.LoadAddin(String filePath, AssemLoader assemLoader) <Osnap off>

Additional context
The reference is declared in .csproj:

<Reference Include="accoremgd">
    <HintPath>C:\Program Files\Autodesk\AutoCAD 2023\accoremgd.dll</HintPath>
    <Private>False</Private>
</Reference>

.NET Inserting Block with Embedded Resource File

Describe the bug
Using the .NET API we can insert a block into AutoCAD. For ease of project, it's nice to embed your block DWG file into your project as a resource. Using the code below, we can write this block to a Temp folder out of the resource stream and then insert it as a block file into a file.

Using this code within the CadAddinManager seems to not be able to find the resource. Using the same code when direct loading of the assembly works fine.

Can easily get around this during testing however with just hard coding temporary block path while working out other issues. Just something I noticed that would be nice if there's a fix.

Credit to Norman Yuang for this code on AutoCAD Customization Forum:
https://forums.autodesk.com/t5/net/can-vs-insert-a-dwg-file-as-a-vs-resource/td-p/8422634

public static string ExtractFileFromResource(string resourceName)
        {
            dynamic preferences = Application.Preferences;
            string filePathName =
                (string)preferences.Files.TempFilePath + @"\\" + resourceName + @".dwg";

            try
            {
                var bytes = (byte[])accGasWellDesigner.Properties.Resources.ResourceManager.GetObject(resourceName);
                if (File.Exists(filePathName)) File.Delete(filePathName);
                using (var stream = new FileStream(filePathName, FileMode.Create, FileAccess.Write))
                {
                    stream.Write(bytes, 0, bytes.Length);
                    stream.Close();
                }

                return filePathName;
            }
            catch(Exception e)
            {
                //return @"";

                return e.Message.ToString() + ": " + e.StackTrace.ToString();
            }
        }

To Reproduce
Steps to reproduce the behavior:

  1. Create a test project with an Embedded DWG file as a resource.
  2. Use the code above to write the file to a Temp folder
  3. Insert the block from the temp folder with the code above
  4. See that the block is not found.

Expected behavior
Would be nice if we can get this to find the block file.

Screenshots
'Block file not found, cannot proceed...' is coming from my code project using the above code for extracting. You can also see in screenshot 'Object reference not set to an instance of object.'
image

Desktop (please complete the following information):

  • Windows 10
  • Civil 3D 2022

Loading references

Hi
Is there a way to load references added to the project which I am debugging?

I mean, if I use nuget packages or reference another project's dll, it won't be available when I use this program -- the command will throw an exception saying that it can't find the referenced dll.

I also had this problem with netreload. I have worked around this problem by linking my source files around instead of referencing projects and instead of using nuget, I had to download source and also link it in the debugged project to be able to use netreload.

There seems to be same problem with this manager also. I don't know enough about .net to solve the problem my self.

Unable to use Fabrication API in CADmep

I am trying to use Addin Manager with the CADmep API. I receive an error Exception has been thrown by the target of an invocation. when running any methods that use the Fabrication API dll.

Running in the debugger, I found that the error comes from AddinManagerBase.cs, line 103. Activator.CreateInstance() throws an exception System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'

There are two inner exceptions.

2022-06-10 14 40 36 devenv_Ia0ZIWeZ0H

FileLoadException: Could not load file or assembly 'FabricationAPI, Version=2020.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

and

ArgumentException: System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length
   at System.String.Substring(Int32 startIndex, Int32 length)
   at CadAddinManager.Model.AssemLoader.SearchAssemblyFileInTempFolder(String assemName)

I noticed that FabricationAPI.dll is not copied to the running location.

2022-06-10 14 42 51 explorer_QJIwKsVR5U

I wonder if this has anything to do with Addin Manager not checking for FabricationAPI.dll or accore.dll in the assembly loader.

Desktop

  • OS: Windows 10
  • CadAddinManager version: 1.0.7 release
  • AutoCAD version: 2020
  • CADmep version: 2020

To Reproduce

  1. Create new Class Library
  2. Add references to acmdg.dll, accoremgd.dll, acdbmgd.dll (AutoCAD folder), and FabricationAPI.dll
  3. Paste in the example C# code
  4. Run Class1.Execute from Addin Manager
  5. Get error Exception has been thrown by the target of an invocation.
  6. Profit
using Autodesk.AutoCAD.Runtime;

namespace FabricationAddin
{
    public class FabricationInteractions
    {
        [CommandMethod("DoFabricationThing")]
        public void Execute()
        {
            var m = Autodesk.Fabrication.DB.Database.Materials;
        }
    }
}

Is can also work.in autocad 2017 or autocad 2019

**Is your feature work in autocad 2107

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Custom WPF Tooltip Throws Error and Locks up Civil 3D

Describe the bug
I have a custom Tooltip in my project that replaces the AutoCAD / Civil 3D tooltip with my own WPF version. This works fine when loading in session, but when using in CadAddinManager it crashes. More on how to implement the custom WPF Tooltip from this blog: https://drive-cad-with-code.blogspot.com/2016/12/custom-autocad-entity-tool-tip.html

Seems it cannot find/load AeccUiWindows.Aero2

To Reproduce
Steps to reproduce the behavior:

  1. Add the tooltip into a test project
  2. Load into CadAddinManager
  3. Wait for the tooltip to appear
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
This error appears - seems it cannot load AeccUiWindows.Aero2
image

Desktop (please complete the following information):

  • OS: Windows 10
  • Civil 3D 2022 (likely happens on others as well)

Additional context
I'll try to post a test project soon with a tooltip implemented.

FILE [dll] is not valid in 2023 but it is in 2024

dll info:
accoremdg C:\Program Files\Autodesk\AutoCAD 2023\accoremgd.dll version 24.2.0.0

when i try to open on 2023 a msgbox display file is not valid so I try on C3D 2024 and load fine. Get back to C3D 2023 and now dll is load
image

but when I run a single command to get RXClass follow message is shown on command line

Command: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'accoremgd, Version=24.2.0.0, Culture=neutral, PublicKeyToken=null'
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
   at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
   at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
   at Mono.Cecil.TypeReference.Resolve()
   at Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
   at Mono.Cecil.SignatureReader.ReadCustomAttributeEnum(TypeReference enum_type)
   at Mono.Cecil.SignatureReader.ReadCustomAttributeElement(TypeReference type)
   at Mono.Cecil.SignatureReader.ReadCustomAttributeConstructorArguments(CustomAttribute attribute, Collection`1 parameters)
   at Mono.Cecil.MetadataReader.ReadCustomAttributeSignature(CustomAttribute attribute)
   at Mono.Cecil.CustomAttribute.<Resolve>b__35_0(CustomAttribute attribute, MetadataReader reader)
   at Mono.Cecil.ModuleDefinition.Read[TItem](TItem item, Action`2 read)
   at Mono.Cecil.CustomAttribute.Resolve()
   at Mono.Cecil.CustomAttribute.get_ConstructorArguments()
   at CadAddinManager.Model.AssemLoader.ResolveDuplicateMethod(String originalFilePath)
   at CadAddinManager.Model.AssemLoader.LoadAddinsToTempFolder(String originalFilePath, Boolean parsingOnly)
   at CadAddinManager.Command.AddinManagerBase.RunActiveCommand()

Same command on 2024

image

Cannot load assembly. Error details: Autodesk.AutoCAD.Runtime.Exception: eDuplicateKey

Describe the bug
Cannot load assembly. Error details: Autodesk.AutoCAD.Runtime.Exception: eDuplicateKey
at Autodesk.AutoCAD.Runtime.CommandClass.AddCommand(ICommandLineCallable ca, MethodInfo mi)
at Autodesk.AutoCAD.ApplicationServices.AutoCADApplicationHolder.Initialize(Assembly assembly)
at Autodesk.AutoCAD.ApplicationServices.ExtensionLoader.ProcessAssembly(Assembly assembly)

To Reproduce
Steps to reproduce the behavior:

  1. Open Add-in Manager.
  2. Click on command execute.
  3. See error.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
image

Additional context
This is problem is know, please help me fix if you can! it not affect to process execute new code update assembly, please ignore it.I will come back to this bug soon when I have time.
https://adndevblog.typepad.com/autocad/2014/01/detecting-net-command-duplicates-programmatically.html

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.