- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to write my first autocad plugin that's just a basic hello world style program that prints a string to the autocad command line but I can't get it to run and actually print the string. Netload seems to work because the name of the command appears in the command prediction menu that pops up when you start typing but when I select it nothing then happens. I think the problem is that my project targets the .NET 4.8 version and the computer I'm trying to run it on only has the 5.0 runtime installed, but to change what's installed on the later computer I need permission so I want to make sure I know what the problem is before I ask. And also when I tried to re-target my program to the 5.0 runtime it threw error codes at me that I think meant that my code won't work with that .NET version so I'm not sure if maybe I could successfully re-target my program somehow. I tried search for a solution like restoring NuGet packages but that didn't work. My current project targets .NET 4.8 and I'm trying to run it in Autocad 2021 and the machine I'm trying to run it on has a win10 enterprise OS and has the .NET 5.0.17(x64) runtime installed. And my dll doesn't display a security warning that it's been blocked in it's general properties so since it netloads but doesn't run I'm thinking it's because of the framework discrepancy but I'm not completely sure so I've attached my project files and if anyone can lend me a helping hand getting this code to run I'd really appreciate it. And I know the database object isn't used anywhere but I'm planning on using it in a future program and it got leftover and I don't think it could be causing the problem unless I'm mistake. And I know I could implement this easier with LISP but I want to learn how to use .NET for cad so I'm trying to crack this problem. And the computer I'm trying to run the program on requires admin permissions to download most things so I didn't download screencast but I made a recording of the program loading but not doing anything and uploaded it to youtube. This is the link: https://www.youtube.com/watch?v=9-oUES7qqN4
using System;
using System.Net.Http;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
namespace HelloAutocad
{
public class Class1
{
[CommandMethod("HelloAutocad")]
public void HelloAutocadFromCSharp()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor edt = doc.Editor;
edt.WriteMessage("\nHello Autocad from C#!\n");
}
}
}Thanks in advance for reading this and any help you can offer.
Solved! Go to Solution.