Author Topic: Getting off the Ground with .NET  (Read 11414 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12241
  • London, England
Re: Getting off the Ground with .NET
« Reply #15 on: April 01, 2011, 05:46:11 PM »
One thing I would note...

C#  ~  41 lines

LISP:

Code: [Select]
(defun c:AddLine nil
  (entmakex '((0 . "LINE") (10 5 5 0) (11 12 3 0)))
  (princ)
)

 :lol:

I think I've been spoiled with LISP

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Getting off the Ground with .NET
« Reply #16 on: April 01, 2011, 05:47:03 PM »
< .. >
BTW, should I be netloading the dll in the 'bin' > 'Debug' folder?

Yes, If you want to debug ( build can be set to either Debug or Release)


Just tried loading the example code and, after loading, typed 'AddLine' and all worked correctly! I'm off the ground  8-)

I noticed it was slightly slow to create the line though (when I say slow, I mean 0.2 secs) would this be because it has to load some dll's when called for the first time?

Good !

Yes ... you will come across the term JIT ( 'Just in Time' Compilation)

Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Lee Mac

  • Seagull
  • Posts: 12241
  • London, England
Re: Getting off the Ground with .NET
« Reply #17 on: April 01, 2011, 05:51:22 PM »
< .. >
BTW, should I be netloading the dll in the 'bin' > 'Debug' folder?

Yes, If you want to debug ( build can be set to either Debug or Release)

Gotcha, Debug when debugging, Release when releasing  :-)

Just tried loading the example code and, after loading, typed 'AddLine' and all worked correctly! I'm off the ground  8-)

I noticed it was slightly slow to create the line though (when I say slow, I mean 0.2 secs) would this be because it has to load some dll's when called for the first time?

Good !

Yes ... you will come across the term JIT ( 'Just in Time' Compilation)

Cool, thanks Kerry for all your help  8-)

sinc

  • Guest
Re: Getting off the Ground with .NET
« Reply #18 on: April 01, 2011, 05:58:12 PM »
I think I've been spoiled with LISP

As you get into it, I think you'll discover the opposite...

Little things might be simpler in Lisp.  But as you get into larger efforts, .NET code tends to be far more readable than LISP.  The tools in your .NET IDE are far superior to the VLIDE.  And .NET has a wealth of pre-existing classes that encapsulate hundreds (maybe thousands) of tasks that you typically would have to code yourself in Lisp (if the task can even be done in Lisp).

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Getting off the Ground with .NET
« Reply #19 on: April 01, 2011, 06:01:55 PM »
You're welcome.
...

Regarding the Wizard.
Personally I'd forgo it's use.
<You> need to understand what's going on, not just accept what's thrown.
The time taken to setup manually is minor ... considerably less than the time it takes to clear out all the bumpf the wizard adds.
[/personal opinion]

added:
besides, I find the mental process involved in a manual setup rather cathartic.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Lee Mac

  • Seagull
  • Posts: 12241
  • London, England
Re: Getting off the Ground with .NET
« Reply #20 on: April 01, 2011, 06:17:23 PM »
I think I've been spoiled with LISP

As you get into it, I think you'll discover the opposite...

Little things might be simpler in Lisp.  But as you get into larger efforts, .NET code tends to be far more readable than LISP.  The tools in your .NET IDE are far superior to the VLIDE.  And .NET has a wealth of pre-existing classes that encapsulate hundreds (maybe thousands) of tasks that you typically would have to code yourself in Lisp (if the task can even be done in Lisp).

That's good to hear. Being a complete beginner in this area, I definitely have a lot to discover (even with VS itself!).

Regarding the Wizard.
Personally I'd forgo it's use.
<You> need to understand what's going on, not just accept what's thrown.
The time taken to setup manually is minor ... considerably less than the time it takes to clear out all the bumpf the wizard adds.
[/personal opinion]

added:
besides, I find the mental process involved in a manual setup rather cathartic.

I think I'll take your advice. To be honest, I need all the advice I can get at this point to avoid following the wrong route in my learning and to prevent myself from developing bad habits early on. I distinctly remember when I first learnt LISP that it was about a month before I discovered the VLIDE, don't know how I coped with Notepad...

With regard to the 'bumpf' that is added by the wizard - I'm surprised by the quantity of files in a VS Project! I write a single .cs file and receive a whole directory!

Jeff H

  • Needs a day job
  • Posts: 6035
Re: Getting off the Ground with .NET
« Reply #21 on: April 01, 2011, 06:29:00 PM »
That is good news,
I have been debating learning Lisp so I could see how you guys think but this way I do not have to look at
Code: [Select]
(12 34((sset 34 34(56) 66 (entgo 67 )
(setq l (35 wathma '34')
......................


and think uh????

great news.

Lee Mac

  • Seagull
  • Posts: 12241
  • London, England
Re: Getting off the Ground with .NET
« Reply #22 on: April 01, 2011, 06:40:25 PM »
 :-D

Thanks Jeff  :-)

LE3

  • Guest
Re: Getting off the Ground with .NET
« Reply #23 on: April 01, 2011, 06:50:37 PM »
i tried on my early c# days to port my lisp routines, that help me but very little, until i started to think just in c# (same happen when learned c++) so forget all about lisp right now  :evil:  :-P

gile

  • Water Moccasin
  • Posts: 2222
  • Marseille, France
Re: Getting off the Ground with .NET
« Reply #24 on: April 01, 2011, 07:25:38 PM »
Even playeng with .NET, you may keep on LISPing (see this thread)
Speaking English as a French Frog

Jeff H

  • Needs a day job
  • Posts: 6035
Re: Getting off the Ground with .NET
« Reply #25 on: April 01, 2011, 10:37:44 PM »
I have attempted to run the 'ArxWizads.msi' file  --> This informs me that I need an instance of MS Visual Studio 2008 on the target machine.

Those wizards are ObjectArx(C++) and you can not use or build with VS 2010 until 2012 I think but does not matter since you are using .NET.
For .NET wizards go here and download AutoCAD 2011 .Net Wizards.zip ---(Compatible with AutoCAD 2011 and 2012)  
I had problems with 64-bit but make sure before you un-zip right-click and select properties and click unblock button if available.

DOH! I noticed you are using 2010 I still have the zip file downloaded for 2010 .NET wizards if needed

This will be way more useful MgdDbg


LE3

  • Guest
Re: Getting off the Ground with .NET
« Reply #26 on: April 02, 2011, 01:05:13 PM »
Even playeng with .NET, you may keep on LISPing (see this thread)

That it is for sure Gile!

I was joking on: so forget all about lisp right now  :lol:

I'm still use lisp once in a while, not that much, but it is there :)

Lee Mac

  • Seagull
  • Posts: 12241
  • London, England
Re: Getting off the Ground with .NET
« Reply #27 on: April 02, 2011, 02:08:42 PM »
i tried on my early c# days to port my lisp routines, that help me but very little, until i started to think just in c# (same happen when learned c++) so forget all about lisp right now  :evil:  :-P

I'll definitely never be able to forget LISP - that shall haunt me for life I think  ;-)

Even playeng with .NET, you may keep on LISPing (see this thread)

Thanks Gile - another great thread to link the two languages :-)

Lee Mac

  • Seagull
  • Posts: 12241
  • London, England
Re: Getting off the Ground with .NET
« Reply #28 on: April 19, 2011, 08:11:38 AM »
Over the past few days I've been delving into this a little more: following a C# tutorial and also trying a few programs from the .NET forum. Inevitably, I have a few more (novice) questions if you have time  :-)

After browsing the .NET Geometry Routine thread, I thought I'd try this code from Gile (works great BTW).

This is the procedure I followed:

1) Open VS2010, created a New Project (Visual C# Class Library) named 'ConvexHull'.

2) Copied Gile's code to a '.cs' file called 'ConvexHull.cs' within said project.

3) Added 'AcDbMgd.dll' and 'AcMgd.dll' to the list of References and set 'Copy Local' to false.

4) Set the Project Properties to '.NET Framework 3.5' and Build for 'Active (Any CPU)'.

5) Build the Solution (F6)

6) Opened AutoCAD to a Drawing, NetLoad'ed the 'bin > Debug > ConvexHull.dll' file

7) Typed 'ch' to start the program ==> All worked fine.


Now for the Questions:

*  Firstly, am I following the correct procedure to test the code I linked to?

*  Are the Project/File names arbitrary?

*  In Step (3):

     i)  Is there a way to automatically have those DLLs added as References?

    ii)  How does one know which DLL's are required, i.e. would I always need both AcDbMgd and AcMgd?

   iii)  VS2010 automatically adds quite a few other References:

       

        Are these needed?

*  In Step (4):  Is is possible to automatically set these properties?

*  In Step (5):  What is the difference between Building the Solution (F6) and Building using (Shift+F6)?



Sorry for the long post - It seems the more I delve into this, the more questions I have...

Thanks for your time and advice.

Lee


gile

  • Water Moccasin
  • Posts: 2222
  • Marseille, France
Re: Getting off the Ground with .NET
« Reply #29 on: April 19, 2011, 09:15:52 AM »
Quote
*  Firstly, am I following the correct procedure to test the code I linked to?

Yes it's correct, but you can do it easier (not sure about translations, but may be closed to):
- right click the Project and choose 'Properties', in the 'Debug' tab hit 'Start external program' and browse to the acad.exe you want to start.

- you can also automate the NETLOADing adding this LISP expression to an acaddoc.lsp or MNL file :

Code: [Select]
;; Check if debugging .NET & load the DLL if so
(defun DebugNET (/ path fn)
  (setq path (getvar "DWGPREFIX"))
  (if (wcmatch (strcase path) "*bin\\DEBUG*")
    (foreach fn (vl-directory-files path "*.DLL" 1)
        (if (wcmatch (strcase path) (strcat "*\\" (vl-filename-base (strcase fn)) "\\*"))
          (command "._NetLoad" fn)
        )
      )
  )
  (princ)
)

Another way to automate NETLOADing on debugging is to add a script file to your project:
- right click the project > Add > New element > Text file
- copy the following string in the file and save it as "start.scr" (take care it finish with a space):
Code: [Select]
netload "..\..\bin\debug\ConvexHull.dll" - in the (now well known) project 'Property' > Debug tab, add to 'Arguments of the command line':
Code: [Select]
/nologo /b "..\..\bin\debug\start.scr"
Using the LISP way or the script way when you type F5 in Visual Studio AutoCAD starts and the dll is NETLOADed.
More, you can add a specific filename in the 'Arguments of the command line' so that AutoCAD starts and open this file:
Code: [Select]
"D:\Some test drawing\ConvHull.dwg" /nologo /b "..\..\bin\debug\start.scr".

Quote
*  Are the Project/File names arbitrary?
Yes.

Quote
*  In Step (3):
I recommand you to save some projects as Templates (after removing unusefull code):
File menu -> 'Export the template'
All references, properties, script file, and so on wil be saved with this template and Visual Studio will purpose you to choose it ine the New project window.
« Last Edit: April 24, 2016, 12:42:37 PM by gile »
Speaking English as a French Frog