Possible to debug my plugin without launching AutoCAD again and again?

Possible to debug my plugin without launching AutoCAD again and again?

soonhui
Advisor Advisor
1,328 Views
18 Replies
Message 1 of 19

Possible to debug my plugin without launching AutoCAD again and again?

soonhui
Advisor
Advisor

Currently in my VS 2022, I set AutoCAD as my external program, and the VS can hook ACAD into my plugin, which allows me to step into my code via a debugger.

 

The downside is that I would always have to relaunch AutoCAD whenever I recompile my plugin and... AutoCAD is slow! I'm talking about I want split second launching of the software and not some 10 seconds. 

 

So I wonder whether is it possible for me to somehow don't have to close down and reopen my AutoCAD for the debugging? The plugin just dynamically reloads and I can still step into my plugin via debugger. 

 

Any idea?

##########

Ngu Soon Hui

##########

I'm the Benevolent Dictator for Life for MiTS Software. Read more here


I also setup Civil WHIZ in order to share what I learnt about Civil 3D
0 Likes
1,329 Views
18 Replies
Replies (18)
Message 2 of 19

cuongtk2
Advocate
Advocate

If you add code during debugging, it still works without needing to rebuild the plugin.

0 Likes
Message 4 of 19

kerry_w_brown
Advisor
Advisor

@soonhui 

 

Try Enabling Hot Reload

 

https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-enable-and-disable-edit-and-continue?...


// 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
Message 5 of 19

soonhui
Advisor
Advisor

@kerry_w_brown , @cuongtk2 ,

 

I'm aware of hot reload from VS 2022, but it's not always working right? In fact as I tried it, it didn't work most of the case because this is plugin development?

##########

Ngu Soon Hui

##########

I'm the Benevolent Dictator for Life for MiTS Software. Read more here


I also setup Civil WHIZ in order to share what I learnt about Civil 3D
0 Likes
Message 6 of 19

kerry_w_brown
Advisor
Advisor

@soonhui 

I use it faultlessly daily debugging code , using Visual Studio 2022 Preview to open AutoCad and netloading the assembly.

Are you doing something different ?


// 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
Message 7 of 19

cuongtk2
Advocate
Advocate

in Compile event: copy "$(TargetPath)" "C:\ProgramData\Autodesk\ApplicationPlugins\YourPlugin.bundle\Contents" .  Enable hot reload and debug. You can develop the code while debugging.

0 Likes
Message 8 of 19

kerry_w_brown
Advisor
Advisor

@soonhui wrote:

@kerry_w_brown , @cuongtk2 ,

 

I'm aware of hot reload from VS 2022, but it's not always working right? In fact as I tried it, it didn't work most of the case because this is plugin development?


 

Exactly what do you mean by  >>> because this is plugin development

 and why is it different to creating a .DLL that can be NETLOADED into AutoCAD and perform a task . . . . which is what we do every day.

 

Regards,

 


// 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
Message 9 of 19

pari_dhanakoti
Enthusiast
Enthusiast

I downloaded the NetReload.dll from the original post . Placed it in C:\ProgramFiles\Autodek\ApplicationPlugins and unblocked the security restriction on the executable. In Civil3D 2024, I  ran the NETLOAD command, It is asking for the path of the assembly file which I provide (fully qualified path for the NetReload.dll). However when I try the NRL command, it is not found. What am I missing?

pari_dhanakoti_0-1733495652281.png

 

0 Likes
Message 10 of 19

fieldguy
Advisor
Advisor

You should also have a "Commands.cs" file with the download.  Everything you need is in there.  I assume your downloaded "NetReload.dll" file has issues with reference files.  If you want to use it, I suggest you start from scratch and build your own solution (NET Framework 4.8 Class Library) with CommandMethod "NRL" and "Commands.cs".  If you want to try that, I would start with "Hello World" and once that is working, you can add the contents of the downloaded "Commands.cs" file piece by piece, starting with the "Helper Classes".

 

0 Likes
Message 11 of 19

soonhui
Advisor
Advisor

@kerry_w_brown , you can try the below code

 

 

 

        [CommandMethod(nameof(TestMarkPointLaneCreation))]
        public void TestMarkPointLaneCreation()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;

            using Transaction tr = doc.TransactionManager.StartTransaction();

            var assId = CivilApplication.ActiveDocument.AssemblyCollection.Add("Test", AssemblyType.UndividedCrownedRoad, Point3d.Origin);
            var markPointTemplateId = CivilApplication.ActiveDocument.SubassemblyCollection.ImportStockSubassembly("MarkPoint", "Subassembly.MarkPoint", Point3d.Origin);
           

            var markPointTemplate = tr.GetObject(markPointTemplateId, OpenMode.ForWrite) as Subassembly;
            var pointName = markPointTemplate.ParamsString["PointName"];
            pointName.Value = "FirstMarkPoint";
            var ass = assId.GetObject(OpenMode.ForWrite) as Assembly;
            var assemblyGroupRight = ass.AddSubassembly(markPointTemplateId);
            assemblyGroupRight.Name = "Right";

            var medianRaiseSlopeId = CivilApplication.ActiveDocument.SubassemblyCollection.ImportStockSubassembly("MedianRaisedConstantSlope", "Subassembly.MedianRaisedConstantSlope", Point3d.Origin);
            var median = tr.GetObject(medianRaiseSlopeId, OpenMode.ForWrite) as Subassembly;
            var medianMarkPointName = median.ParamsString["MarkedPoint"];   
            medianMarkPointName.Value = pointName.Value;
            ass.AddSubassembly(median.ObjectId, markPointTemplate.Points[0]);

            //var medianDepressedId = CivilApplication.ActiveDocument.SubassemblyCollection.ImportStockSubassembly("MedianDepressed", "Subassembly.MedianDepressed", Point3d.Origin);
            //var medianDepressed = tr.GetObject(medianDepressedId, OpenMode.ForWrite) as Subassembly;
            //var markedPointName = medianDepressed.ParamsString["MarkedPointName"];
            //markedPointName.Value = pointName.Value;

            //var slope1Val = medianDepressed.ParamsDouble["Slope1"];
            //slope1Val.Value = -1/2.0; // somehow this value is exactly the inverse of what you see in the UI...
            //Debug.Assert(-1/2.0 == slope1Val.Value);

            //ass.AddSubassembly(medianDepressed.ObjectId, markPointTemplate.Points[0]);


            tr.Commit();
        }

 

 

 

And instead of adding subassembly MedianRaisedConstantSlope, you add MedianDepressed subassembly,

 

I mean, if you comment out the MedianRaisedConstantSlope, and you uncomment the MedianDepressed code, all while you are attaching to the VS debugger and you rely on hot reload to refresh the code,

 

then you can see that no, hot reload doesn't always work. You will have to stop the debugging and recompile for it to work. 

##########

Ngu Soon Hui

##########

I'm the Benevolent Dictator for Life for MiTS Software. Read more here


I also setup Civil WHIZ in order to share what I learnt about Civil 3D
0 Likes
Message 12 of 19

kerry_w_brown
Advisor
Advisor

@soonhui 

Sorry, I don't use Civil'

Do you have an AutoCAD compatible  Class that you can't Hotload ?

Regards,  


// 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
Message 13 of 19

kerry_w_brown
Advisor
Advisor

@soonhui stated:

>>> And instead of adding subassembly MedianRaisedConstantSlope, you add MedianDepressed subassembly, and you can see that no, hot reload doesn't always work.


Is it possible the issue is with Civil3D using MedianDepressed rather than with Visual Studio.

. . and what constitutes "doesn't always" 

How often does it work,

Under what conditions doesn't it work ?
and what does it do inplace of "work" ?


Anyone ??

 

 


// 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
Message 14 of 19

soonhui
Advisor
Advisor

Sorry, I didn't write my question properly. I've updated it. Essentially, what I mean is:

 

if you comment out the MedianRaisedConstantSlope, and you uncomment the MedianDepressed code, all while you are attaching to the VS debugger and you rely on hot reload to refresh the code,

 

then you can see that no, hot reload doesn't always work. You will have to stop the debugging and recompile for it to work. 


 




##########

Ngu Soon Hui

##########

I'm the Benevolent Dictator for Life for MiTS Software. Read more here


I also setup Civil WHIZ in order to share what I learnt about Civil 3D
0 Likes
Message 15 of 19

kerry_w_brown
Advisor
Advisor

Did you read my last 2 posts ?


// 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
Message 16 of 19

kerry_w_brown
Advisor
Advisor

@soonhui 

Perhaps if you made two methods in this case.  

One for testing each situation . . . and just comment out the method calls from a control method.

Less confusing for testing.

 

Does your VS Editor offer a reason for needing to re-compile : Perhaps you're expecting it to handle too big a change ??


// 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
Message 17 of 19

soonhui
Advisor
Advisor

@kerry_w_brown , I read all of your posts.

 

The hot reload is a hit and miss thing, I do see that sometimes it works though. But I can never say for sure when. So it's unreliable ( just like how other situations independent of C3D plugin debugging) 

##########

Ngu Soon Hui

##########

I'm the Benevolent Dictator for Life for MiTS Software. Read more here


I also setup Civil WHIZ in order to share what I learnt about Civil 3D
0 Likes
Message 18 of 19

kerry_w_brown
Advisor
Advisor

 

 

 


@soonhui wrote:

@kerry_w_brown , I read all of your posts.

 

The hot reload is a hit and miss thing, I do see that sometimes it works though. But I can never say for sure when. So it's unreliable ( just like how other situations independent of C3D plugin debugging) 


You may have read them, but you seem to have ignored the questions I asked.
They were asked in an attempt to help resolve your issues. I may not be able to assist, but others may, and your response will give them more info to make a useful evaluation.
If you choose to ignore questions you'll find that people will tend to ignore you.
Help yourself . . provide the information needed.

 

Regards,


// 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
Message 19 of 19

kerry_w_brown
Advisor
Advisor

Just a reminder about restrictions :

https://learn.microsoft.com/en-us/visualstudio/debugger/supported-code-changes-csharp?view=vs-2022

 

https://learn.microsoft.com/en-us/visualstudio/debugger/supported-code-changes-csharp?view=vs-2022#u...

 

https://learn.microsoft.com/en-us/visualstudio/debugger/supported-code-changes-csharp?view=vs-2022#u...


// 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