TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: keithsCADservices on February 25, 2024, 01:09:32 PM

Title: AutoLISP Editor in 2024
Post by: keithsCADservices on February 25, 2024, 01:09:32 PM
I'm subscribing monthly to AutoCAD Full because I basically need the full functionality of VLIDE. I really don't like Visual Studio Code. It's a major step down in my opinion. Due to how it was implemented it also wasted a lot of my time. For example: Autodesk just copied and pasted their help documentation for ACAD Full to LT... Lots of the functionality of VS Code doesn't work in ACAD LT unfortunately.

The features that help me code faster with VLIDE are the LISP console, and the ability to load updated files in a single click I also use the "inspect" feature quite a bit. I don't really use debug features these days. I even use fields instead of "watch". I find the VLIDE's checking features also help me find missed brackets and other dumb little mistakes I've been making these days. VLIDE was actually really really good back in its day. A modern equivalent would be something else!! As long as it's not broken (so much stuff is broken these days).

I recall that someone uses Notepad++

I wish I could use BLADE but I can't.

It's not that hard to create a debugging console. There's just no money in it for a would-be software developer. Even me: Give me a year and I'd have something ready in .NET -> But by a year I mean full-time, so unless I was sitting on a pile of money... I personally would pay $2,000 for a LISP console that at least matches VLIDE's functionality. Or even just the features I actually use.
Title: Re: AutoLISP Editor in 2024
Post by: d2010 on February 25, 2024, 07:17:49 PM
Even  if you got the VLIDE-clone.dll; but you cannot share on the public for everyone, this VLIDE-clone.dll. Why? Because many "management-of-sellingCAD" are 30% based on 
VLIDE.dll

Eveni , if you got the VLIDE-clone.dll, then everyone got
 ++Vlide-clone-for-zwcad
 ++Vlide-clone-for-gstarcad
 ++Vlide-clone-for-SolidWork
 ++Vlide-clone-for-TurboCad
You do not get too much!! :tickedoff: if you share the sources-of "VLIDE-clone.dll" , then
you waste of time for All ??. How to sell Autocad2025, if sources-of "VLIDE-clone.dll" on 100%free inside the theGIT(as)com? Many bugs of VisualCode protect 63% the selling of AutoCad2025 and his future ;;
Code: [Select]
C:\> How to protect the BricsCad2024selling?
Title: Re: AutoLISP Editor in 2024
Post by: keithsCADservices on February 25, 2024, 08:07:44 PM
I have no f'king idea what I just read.
Title: Re: AutoLISP Editor in 2024
Post by: kdub_nz on February 25, 2024, 08:40:42 PM
That's what happens when you douse AI in ethanol.
Title: Re: AutoLISP Editor in 2024
Post by: BIGAL on February 26, 2024, 01:40:33 AM
Yep Notepad++ has a lisp formatting option so dbl brackets are easy to check, there is also a activeX plug in so can run code in the editor.

Another option is "Compare" handy when looking for that broken variable can run a log file of setvars and compare another log file of setvars very handy ay times why Dwg1 works and not Dwg2.
Title: Re: AutoLISP Editor in 2024
Post by: Lee Mac on February 26, 2024, 06:11:41 AM
I wish I could use BLADE but I can't.

Why not?
Title: Re: AutoLISP Editor in 2024
Post by: It's Alive! on February 26, 2024, 08:23:31 AM
I had a rough time getting started with VS Code & Python. Finally got things setup to where I’m pretty happy with it.
...
It’s extensible, the lisp plug in is open source, maybe the community can add features.
On the plus side, you can debug in the same environment for Acad, Gcad, and Zcad
which should make things easier if you’re developing for multiple platforms
Title: Re: AutoLISP Editor in 2024
Post by: VovKa on February 26, 2024, 08:24:46 AM
VLIDE was actually really really good back in its day.
and it still is
i'm doing some python programming at the moment and i use Wing Pro as my IDE. although it is overwhelmed with modern features but whenever i switch back to VLIDE there is only one thing that i'm missing - it's automatic highlighting of all occurrences of the selected text
Title: Re: AutoLISP Editor in 2024
Post by: kdub_nz on February 26, 2024, 05:18:28 PM
VLIDE was actually really really good back in its day.
and it still is
i'm doing some python programming at the moment and i use Wing Pro as my IDE. although it is overwhelmed with modern features but whenever i switch back to VLIDE there is only one thing that i'm missing - it's automatic highlighting of all occurrences of the selected text

and minimal control over window pane location in the IDE, but that's not a ball breaker really, just an embugerance.
I like VLIDE too.
Title: Re: AutoLISP Editor in 2024
Post by: keithsCADservices on February 26, 2024, 06:33:13 PM
Quote
and minimal control over window pane location in the IDE, but that's not a ball breaker really, just an embugerance.

The window sizing issues kill me. Along with a few other things. The search functions are really helpful. Along with the console and "inspect". I'm otherwise very manual with code so I might just switch to Notepad++

Quote
I had a rough time getting started with VS Code & Python. Finally got things setup to where I’m pretty happy with it.

I speak with a bit of inexperience, but VS Code is really dependent on the plugins available for the code you want to write. Instructions on how to implement those plugins can be hit or miss. Given that Python so popular it's guaranteed that there'll be something good out there. VS Code is supposed to be minimalistic so if it takes me longer to figure things out compared to say, Visual Studio, all advantages are lost.

Quote
Why not?

I own a copy of BricsCAD (V21 I think). If I program for BricsCAD then I still need to debug in AutoCAD. This is worse than it sounds because my LISP extensively uses dynamic blocks (BricsCAD seems a little behind in that category). It seems like in recent years LISP API's are diverging unfortunately. If I have to go through that much trouble I would just use .NET and not spend the
BLADE was AWESOME. It had some focus issues that the developer was going to fix in the next release (relating to a window losing focus, it's buried somewhere in the forums). But even with that... I'm surprised it wasn't more popular. But I guess LISP itself isn't very popular.

Title: Re: AutoLISP Editor in 2024
Post by: JohnK on February 26, 2024, 10:23:07 PM
I think some of your problems with VSCode is lack of finding the tools that are there. VSCode has a console, paren jumping, (re)formatting, etc.. Also you may not have set yourself up properly. For example, using actual folders and sub folders for your projects (AutoLispers tend to host all their projects in one folder which is very bad). I would, if I were you, take a moment to reevaluate how you program in Lisp and use the "VSCode switch" to step up your game a bit and you may like it. For example, VSCode integrates nicely with Git, give that a try (Git or any version control software is really cool!).

I did a basic writeup on VSCode where I provided a batch script you double click when you start a new project. That script created all the directories, JSON files, etc. you'd need. All you have to do is create lisp files. I can find it if you really want to give it a shot.

You certainly don't have to stick with VSCode and you can choose your own editor (however, sadly, there are only about 10,000 text editors to choose from). I use Vim. UltraEdit I hear is a great editor. Notepad++ seems popular. And, I'm surprised more AutoLispers don't use Emacs (you extend that editor with Lisp).

The powerhouse editors are Emacs and Vim; no editor will ever surpass the amount of features those two editors have amassed for themselves with plugins/extensions/etc. (I have heard that emacs has "tens of thousands of commands") but that's not saying much if you don't use multiple operating systems or program in multiple languages so most editors out there will be great. Pick one that has a good feature base and give it a try. Before I choose Vim I really liked "Crimson Editor"; it was old and not fancy but it was FAST!

Title: Re: AutoLISP Editor in 2024
Post by: 57gmc on February 27, 2024, 10:29:59 AM
Probably the biggest advantage to vlide is that you don't have to set up debugging, it's already integrated. I just never had the time to figure out how to debug lisp in vscode and I don't do that much lisp. But vscode has an advantage of Intellisense.
Title: Re: AutoLISP Editor in 2024
Post by: JohnK on February 27, 2024, 11:56:17 AM
In VSCode debugging is launched with <F5>. Doesn't get much easier.

EDIT:
And stopped with Shift+<F5>
Title: Re: AutoLISP Editor in 2024
Post by: 57gmc on February 27, 2024, 12:57:06 PM
In VSCode debugging is launched with <F5>. Doesn't get much easier.

EDIT:
And stopped with Shift+<F5>
Yes, but don't you have to configure it to start AutoCAD?
Title: Re: AutoLISP Editor in 2024
Post by: JohnK on February 27, 2024, 01:06:15 PM
Not really. If you use the batch script I made to create new projects (folders and whatnot) I create a JSON file in the directory; that file can be very useful in that you can customize how you launch AutoCAD. For example, you can specify a profile to launch AutoCAD with for a given lisp project, if you need to.
Title: Re: AutoLISP Editor in 2024
Post by: JohnK on February 27, 2024, 01:09:53 PM
By-the-way. Here were my notes on starting to use VSCode for AutoLisp which includes a simple batch script that creates directories and stuff.
https://www.theswamp.org/index.php?topic=55696.msg598040#msg598040
Title: Re: AutoLISP Editor in 2024
Post by: 57gmc on February 27, 2024, 01:34:33 PM
hmm. I'll have to see if I can find your batch. I seem to remember reading when you posted it some time ago.
Title: Re: AutoLISP Editor in 2024
Post by: keithsCADservices on February 27, 2024, 02:13:09 PM
I know that there is a way to make VS Code recognize an active session of AutoCAD. But I need to stress that 99% of the time I don't want my debugger to launch a new ACAD session. That's one of the biggest reasons I'm faster in AutoLISP than C#. Yes there is "hot reload" (Visual Studio full) but it's kind of funny that these features so widely touted in recent years in all their glory offer slightly less utility compared to features we've been using for years.

I've spent around the same amount of time fumbling with VS Code as I have with VLIDE. That alone is a bit of a deal breaker given that I've written about 0.001% of my AutoLISP code in VS Code. I wouldn't be opposed to all of this manual configuration if there was actually some benefit for it. Even in the best case scenario it takes hours to sort out (that feels strange to me).

And now the big kicker: VS Code doesn't work with AutoCAD LT... well I mean it works with anything, but the functionality is greatly reduced. And using it with AutoCAD clones? Good luck!
Title: Re: AutoLISP Editor in 2024
Post by: JohnK on February 27, 2024, 03:00:00 PM
I dont know what `manual configuration` you are talking about. You can just open VSCode, start a new file, save that file as a lisp, then hit <F5> to start debugging. What configuration do you do?
Title: Re: AutoLISP Editor in 2024
Post by: kdub_nz on February 27, 2024, 03:15:15 PM
Instead of 'fumbling' :

Title: Re: AutoLISP Editor in 2024
Post by: keithsCADservices on February 27, 2024, 09:04:52 PM
I dont know what `manual configuration` you are talking about. You can just open VSCode, start a new file, save that file as a lisp, then hit <F5> to start debugging. What configuration do you do?

Once you get to step 3:

https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-7BE00235-5D40-4789-9E34-D57685E83875

Then this:

https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-A7CC8D30-D74E-418A-9F03-51878E512163

Which includes "In the launch.json editor window, make the following changes..."

And now onto Debugging (note that at this point I'm already at 10x the amount of time it took to learn VLIDE):

https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-09B4C574-F9FB-4F97-8728-5EAB64E13595

Once major issue with debugging in VS Code is that you aren't as connected to AutoCAD as you are with VLIDE. In VLIDE I can run one line of code at a time (or a statement). I can also inspect elements. I can dump object... etc...

I know for a lot of stuff you can copy and paste into ACAD's command line. But VLIDE's console is just better (I like having the option to do both).

After I finally got VS Code working I realized that all the effort was basically just to have a slightly worse option compared to VLIDE, except with intellisense. Is it hard to set up? Well... yes and no. Truth be told I didn't even spend a second "reading up on" how to use VLIDE. I learnt as I went. And improved my knowledge as needed as I got into more and more advanced code. Imagine someone just starting out with AutoLISP and before ever even getting started, they have to f'k around with json files? The help documentations is also far more verbose compared to anything required to get someone up and running with VLIDE. So relatively, it takes exponentially more effort to set up compared to VLIDE. I find the docs also aren't as well written as documentation on VLIDE; mainly because 3rd parties have created guides for VLIDE, but we only have Autodesk's take on how to setup VS CODE.




Title: Re: AutoLISP Editor in 2024
Post by: JohnK on February 27, 2024, 09:49:41 PM
Slow down! You're not reading.

Step #3 (read it again):
Quote
...>%
Note: Previously, the AutoCAD Debug Attach and AutoCAD Debug Launch configurations were defined and stored in a launch.json file contained within the working folder.
So that means you do not "NEED" the JSON files.

On to the second link:
If you look at your extension version they added an entry to just put a path to AutoCAD in there and have the "attach/launch" feature work instead of the JSON files. -i.e. Same as above; you do not "NEED" the JSON files. But you can use them for other things besides "attach/launch".

Last link:
Yep, same as the VLIDE. You can run, breakpoint, etc.. So that's nothing new.


I create the JSON files when I use VSCode because I prefer to have the option to do what I want when I want. I automate stuff.
Title: Re: AutoLISP Editor in 2024
Post by: Lastknownuser on February 29, 2024, 03:27:52 AM
I really wanted to move onto VS Code, but VLIDE seems much more practical

The biggest issue for me is, and I tried searching for answer but didnt find it maybe someone here knows how to do it, is there a way to like in VLIDE choose by double click everything in closed brackets? I know about Select To Bracket command, but Alt+Shift+right is not practical combination and also you have be be inside brackets... I want double click on the outside of bracket like in VLIDE. If this can be done in VS Code I'll start exploring it more
Title: Re: AutoLISP Editor in 2024
Post by: EnM4st3r on February 29, 2024, 04:09:35 AM
I have been using AutoLisp for around 8 months now, and i also do not understand why most people keep using VLIDE, i have to admit i have never used VLIDE much but VScode feels much more smooth for me.
Title: Re: AutoLISP Editor in 2024
Post by: keithsCADservices on February 29, 2024, 01:46:11 PM
My plan is to explore Notepad++. I would rather invest my time in that if I have to spend time on something. I am also eventually switching to AutoCAD LT or another CAD program. The "other" CAD's I've tried have similar/worse issues with VS Code... just poorly document procedures and in one case the thing didn't even work. I did get ZWCAD's to work. GstarCAD's was broken and they didn't even care.

Quote
Slow down! You're not reading.

Oh believe me... I've read it... and more than once. The last time I read it I read the documentation that they copied and pasted into the AutoCAD LT help (many of VS Code's features are disabled in ACAD LT). I probably also first read the help either before the update, or they left an old tutorial up (which they're known to do). There is still some manual setup involved. Not a lot but more than VLIDE. I don't mind investing time into something like this if there's a clear benefit.
The last time I set up VS CODE it would have been for ZWCAD or GstarCAD, which at the time, they still required the JSON files. Better than nothing I guess has neither of those programs has its own Visual LISP editor.

As I burn money using AutoCAD Full just for VLIDE I'm actively thinking about what I can and cannot live without. I keep seeing more and more reasons I need to stick with VLIDE. Use whatever "feels" best for sure. I just wish "upgrades" were decisive upgrades and not "gain this lose that" type affairs; we are paying ludicrous subscription fees after all.
Title: Re: AutoLISP Editor in 2024
Post by: JohnK on February 29, 2024, 02:26:01 PM
If you are reading, then what was all the complaining about JSON files about? ...honestly, never mind.

I'm sure Notepad++ will work just fine for you. I hear good things about it. I think I remember there was an AutoLisp syntax file posted here (by MP) but you'd have to search for it. Good luck.
Title: Re: AutoLISP Editor in 2024
Post by: 57gmc on February 29, 2024, 03:25:29 PM
I was just playing around with vscode and the Intellisense is a great feature. Just hover over a lisp function and it shows a bunch of help. You also don't need the json file. You create a lisp project and then you add lisp files to the project. They don't even have to be in the same folder as the prj file. The project stores the full path to the lisp file. So it can be in the deployment folder.
Title: Re: AutoLISP Editor in 2024
Post by: kdub_nz on February 29, 2024, 04:55:05 PM

If vsCode plugin had a 'evaluateSelection' option I'd probably never open VLIDE  :-)

feel free to add requests
https://github.com/Autodesk-AutoCAD/AutoLispExt/issues/232
Title: Re: AutoLISP Editor in 2024
Post by: Lonnie on February 29, 2024, 05:04:09 PM
If you are reading, then what was all the complaining about JSON files about? ...honestly, never mind.

I'm sure Notepad++ will work just fine for you. I hear good things about it. I think I remember there was an AutoLisp syntax file posted here (by MP) but you'd have to search for it. Good luck.

here?
https://nedcad.nl/tools/
Title: Re: AutoLISP Editor in 2024
Post by: BIGAL on February 29, 2024, 07:41:33 PM
Interesting in that link is the words "is targeted towards more skilled LISP coders" so I use it every day but I started with version 1.4 of Autocad, yeah look up the date of issue. I tried to install VS and it failed so gave up. I occasionally use VLIDE and Blade when  I get real stuck.

The most common problem is mis matched brackets or a bracket in the wrong place Notepad++ is really useful for this. I always check 1st and last as most obvious problem, often defuns are not closed.
Title: Re: AutoLISP Editor in 2024
Post by: EnM4st3r on March 01, 2024, 01:55:22 AM

If vsCode plugin had a 'evaluateSelection' option I'd probably never open VLIDE  :-)


isnt that standart built in? Look attachment
Also i really like the 'Rename Symbol' option, the IntelliCode and similar to what BIGAL said the colored Brackets
Title: Re: AutoLISP Editor in 2024
Post by: kdub_nz on March 01, 2024, 03:18:32 AM

@EnM4st3r

Thanks for that information,
I'll have another look  :-)

Regards,
Title: Re: AutoLISP Editor in 2024
Post by: JohnK on March 01, 2024, 10:58:45 AM
I have serious doubts, but I hope VSCode will force AutoLispers to use more or better documentation habits in their code.

For example to get the hover tips on a custom function you have to add a function header which looks like this:
Code - Auto/Visual Lisp: [Select]
  1. ;|
  2.   Squares a number
  3.   @Param nu number
  4.   @Returns `nu` squared
  5. |;
  6. (defun square (nu)
  7.   (* nu nu))
Title: Re: AutoLISP Editor in 2024
Post by: 57gmc on March 03, 2024, 12:46:39 PM

@EnM4st3r

Thanks for that information,
I'll have another look  :-)

Regards,
Thanks for the tip.
Title: Re: AutoLISP Editor in 2024
Post by: 57gmc on March 03, 2024, 12:50:01 PM
I have serious doubts, but I hope VSCode will force AutoLispers to use more or better documentation habits in their code.

For example to get the hover tips on a custom function you have to add a function header which looks like this:
Code - Auto/Visual Lisp: [Select]
  1. ;|
  2.   Squares a number
  3.   @Param nu number
  4.   @Returns `nu` squared
  5. |;
  6. (defun square (nu)
  7.   (* nu nu))
Good reminder.
Title: Re: AutoLISP Editor in 2024
Post by: Lastknownuser on March 04, 2024, 01:44:56 AM
Inspired by this thread I played with VS code this weekend, and I'm starting to like it, but I'd like to change color theme for the AutoLisp extension. Anyone know how to do that, since there are no themes available for this extension? I should probably create a new one, but how to add it to this extension? Mainly because I don't like how the variables and numeric values are the same color
Title: Re: AutoLISP Editor in 2024
Post by: danAllen on March 04, 2024, 03:50:09 PM
For lisp I still use Textpad v5 from 2011 with lisp syntax files, mostly because I don't have VLIDE or Blade with Bricscad v15. But I also tried other editors and miss the carot placement consistency when using up/down arrows. (see links for more info)
https://sourceforge.net/p/notepad-plus/discussion/331754/thread/d1ea2bcd/
https://forum.sublimetext.com/t/smart-horizontal-cursor-positioning/2050/18

When I have bugs it is usually missing closing parens, but CTRL+M toggle back & forth which usuall works for me.

I have been using VScode for beginning code in other languages, and I like it. But too set in my ways to move my autolisp editing to it. (Plus missing that darn down arrow feature)
Title: Re: AutoLISP Editor in 2024
Post by: EWCAD on March 05, 2024, 10:58:07 AM
Just thought I would add my opinion here. I actually like VScode for other languages but prefer to use Notepad++ for lisp. Also if you are eventually switching to AutoCAD LT you will have no way debug (other than saving and reloading the lisp every edit) so there would be little benefit from using VScode over Notepad++ anyways.
Title: Re: AutoLISP Editor in 2024
Post by: JohnK on March 05, 2024, 11:12:22 AM
If debugging is your only problem, you can use `vl-bt` to debug instead of using VLIDE:

Define a simple error handler with:
Code - Auto/Visual Lisp: [Select]
  1. (defun *error* (msg) (vl-bt))
or
Code - Auto/Visual Lisp: [Select]
  1. (set '*error* (lambda (msg) (vl-bt)))
Create your code:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:bug () (/ 2 0))
debug your code on the command line.
Code: [Select]
Backtrace:
[0.47] (VL-BT)
[1.43] (#<SUBR @00000158a9fa6278 -lambda-> "divide by zero")
[2.39] (_call-err-hook #<SUBR @00000158a9fa6278 -lambda-> "divide by zero")
[3.33] (sys-error "divide by zero")
:ERROR-BREAK.28 nil
[4.25] (/ 2 0)
[5.19] (C:BUG)
[6.15] (#<SUBR @00000158a9fa6548 -rts_top->)
[7.12] (#<SUBR @00000158b0659750 veval-str-body> "(C:BUG)" T #<FILE internal>)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 0)

After your bugs are dead (-i.e. switch to production code), just (setq *error* nil) and/or replace/use your standard error handler.
Title: Re: AutoLISP Editor in 2024
Post by: dexus on March 05, 2024, 11:18:02 AM
I have serious doubts, but I hope VSCode will force AutoLispers to use more or better documentation habits in their code.

For example to get the hover tips on a custom function you have to add a function header which looks like this:
Code - Auto/Visual Lisp: [Select]
  1. ;|
  2.   Squares a number
  3.   @Param nu number
  4.   @Returns `nu` squared
  5. |;
  6. (defun square (nu)
  7.   (* nu nu))
I can't seem to get any hover tips working for autolisp in VSCode.
Do you have a specific plugin that finds the function headers to display them as a tip?
Title: Re: AutoLISP Editor in 2024
Post by: JohnK on March 05, 2024, 11:34:33 AM
I can't seem to get any hover tips working for autolisp in VSCode.
Do you have a specific plugin that finds the function headers to display them as a tip?

Do you have the AutoCAD AutoLisp extension installed?
Quote
Name: AutoCAD AutoLISP Extension
Id: Autodesk.autolispext
Description: This is a vscode extension for AutoCAD AutoLISP
Version: 1.6.2
Publisher: Autodesk
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=Autodesk.autolispext


Title: Re: AutoLISP Editor in 2024
Post by: JohnK on March 05, 2024, 11:37:22 AM
If debugging is your only problem, you can use `vl-bt` to debug instead of using VLIDE:
... >%
Expanding on that concept.

Define a `DEBUG` mode and set up some simple unit testing.
Code - Auto/Visual Lisp: [Select]
  1. (setq DEBUG T)
  2.   (DEBUG
  3.     (set '#assert
  4.          (lambda ( result expected )
  5.            (equal (eval result) expected)))
  6.  
  7.     (set '*error* (lambda (msg) (vl-bt)))
  8.     )
  9.   (T (set '#assert nil) (set '*error* nil))
  10.   )

Now you can use something like this to debug/test (you don't have to, but building tests for code is good practice).

Code - Auto/Visual Lisp: [Select]
  1. (#assert '(/ 2 0) 0)
  2. (#assert '(+ 2 2) 4)
  3.  
  4. (defun c:four () (+ 2 2))
  5. (#assert '(c:four) 4)
Title: Re: AutoLISP Editor in 2024
Post by: 57gmc on March 05, 2024, 11:54:24 AM

If vsCode plugin had a 'evaluateSelection' option I'd probably never open VLIDE  :)


isnt that standart built in? Look attachment
Also i really like the 'Rename Symbol' option, the IntelliCode and similar to what BIGAL said the colored Brackets
How did you get the panel added to the rt+clk menu? Mine doesn't have it.
Title: Re: AutoLISP Editor in 2024
Post by: JohnK on March 05, 2024, 12:01:53 PM
Did you install the extension to VSCode?

File -> Preferences -> Extensions ---> Search for "AutoLisp"
Load the: "AutoCAD AutoLISP Extension"
Title: Re: AutoLISP Editor in 2024
Post by: 57gmc on March 05, 2024, 12:05:59 PM
Did you install the extension to VSCode?

File -> Preferences -> Extensions ---> Search for "AutoLisp"
Load the: "AutoCAD AutoLISP Extension"
I figured it out. You have to have a debug session running, i.e. F5. This is counterintuitive, as I just wanted to load the selected lisp, not the whole form, which F5 does.
Title: Re: AutoLISP Editor in 2024
Post by: JohnK on March 05, 2024, 12:21:24 PM
Did you install the extension to VSCode?

File -> Preferences -> Extensions ---> Search for "AutoLisp"
Load the: "AutoCAD AutoLISP Extension"
I figured it out. You have to have a debug session running, i.e. F5. This is counterintuitive, as I just wanted to load the selected lisp, not the whole form, which F5 does.

It is not counterintuitive at all. VSCode is a totally different process, you need to instruct it to "attach to autocad's process" in order to send information to it (and get information back). Not sure if you've ever heard of the client-server model (https://en.wikipedia.org/wiki/Client%E2%80%93server_model) for programs but that's what using VSCode is.

However, the fact that VSCode will send the entire files contents upon establishing the "connection" is annoying (what Kdub said earlier).
When I do this in POSIX C I use a named pipe [file], this is probably the same on Windows but I'd guess that when VSCode makes the connection it dumps the current files contents to the named pipe instead of just opening the pipe. This is a bit deep but I guess, I offer up the above gibberish to hopefully shed some light on what is happening in the background (10,000 foot overview).
Title: Re: AutoLISP Editor in 2024
Post by: 57gmc on March 05, 2024, 12:27:30 PM
"Counterintuitive" was probably not the right word. It's just that it was not documented I guess and up to you to figure it out. Yeah it's too bad that you can't just attach to acad without loading all the code in your lisp file. If you have a bug in it, you might want to test a piece at a time.
Title: Re: AutoLISP Editor in 2024
Post by: JohnK on March 05, 2024, 12:45:04 PM
I guess, if we were coding this connection we would have made: "attach", "load", and "connect" but...*meh*

"Not documented" is the mantra for most Windows developers. Here's a spotlight, do you have documentation/comments for/in your code?! :) :p

But seriously, if you take a look at some good coders, they typically have the good habit of documenting their code.
Title: Re: AutoLISP Editor in 2024
Post by: 57gmc on March 05, 2024, 01:29:17 PM
I can't seem to get any hover tips working for autolisp in VSCode.
Do you have a specific plugin that finds the function headers to display them as a tip?
I'm not getting the inline comment to work either. The hover tip says <undocumented>

One problem I'm having is that I'm trying to change the comments for Lee's LM:GetAttributeValues function. Here's what I have.
Code - Auto/Visual Lisp: [Select]
  1. ;/
  2.     Get Attribute Values  -  Lee Mac
  3.     Returns an association list of attributes present in the supplied block.
  4.     @Param blk <[ent] Block (Insert) Entity Name>
  5.     @Returns <[lst] Association list of ((<tag> . <value>) ... )>
  6. /;
  7.  
VS isn't reading the whole thing as an inline comment. It highlights list and Insert and tries to evaluate them.
Title: Re: AutoLISP Editor in 2024
Post by: 57gmc on March 05, 2024, 01:35:11 PM
I guess, if we were coding this connection we would have made: "attach", "load", and "connect" but...*meh*

"Not documented" is the mantra for most Windows developers. Here's a spotlight, do you have documentation/comments for/in your code?! :) :p

But seriously, if you take a look at some good coders, they typically have the good habit of documenting their code.
Yes, I try to comment all my code. I got started when I found out about C#'s xml export of comments. Now, I'm trying to implement the lisp comment you showed, but can't find any documentation on the format. All I can find is the use of ;;;. I found some mention of ;/ /; but not how to format it for VS comments.
Title: Re: AutoLISP Editor in 2024
Post by: JohnK on March 05, 2024, 01:41:57 PM
Try double-clicking a function name, then right-click and choose "Generate Documentation" (which should just place a header above your function that looks like the one I provided). Save the file too (maybe)? I don't think I did anything special (I don't really use VSCode myself so mine is pretty stock, but I may start using it more now; some of these features are pretty cool).

BTW, my files will start to look like this now.
Code - Auto/Visual Lisp: [Select]
  1. ;;; ------------------------------------------------------x- LSP -x----
  2. ;;; FOUR.LSP
  3. ;;; A program that will change the world!
  4. ;;;
  5. ;;; HISTORY
  6. ;;;     version 1.0 - Mar 05 2024
  7. ;;; -------------------------------------------------------------------
  8.  
  9. ;;;;
  10. ;; unit testing framework.
  11. (setq DEBUG nil)                                        ; -True  = debugging mode.
  12.                                                         ;  False = regular mode. (default)
  13.   (DEBUG
  14.     ;|
  15.       Asserts an expression is equal to an expected result.
  16.       @param result an expression to run.
  17.       @param expected a result to check equality to.
  18.       @returns boole (`T` or `nil`)
  19.     |;
  20.     (defun #assert (result expected)
  21.          (lambda ( result expected )
  22.            (equal (eval result) expected)))
  23.     (defun *error* (msg) (vl-bt))
  24.     )
  25.   (T (set '#assert nil) (set '*error* nil))
  26.   )
  27.  
  28. ;;;;
  29. ;; Support procedures
  30.  
  31. ;|
  32.   Returns the number 4.
  33.   @param `nil`
  34.   @returns `4`
  35. |;
  36. (defun c:four () (+ 2 2))
  37.  
  38. ;|
  39.   Squares a number
  40.   @Param nu number
  41.   @Returns `nu`^2
  42. |;
  43. (defun square (nu)
  44.   (* nu nu))
  45.  
  46. ;|
  47.   cubes a number
  48.   @Param x number
  49.   @Returns `x`^3
  50. |;
  51. (defun cube (x)
  52.   (* x x x))
  53.  
  54.  
  55. ;;;;
  56. ;; Testing.
  57.  
  58.   (DEBUG
  59.     (#assert '(/ 2 0) 0)                                ; -Assert we can divide by zero.
  60.     (#assert '(+ 2 2) 4)                                ; -Assert 2+2 = 4.
  61.     (#assert '(c:four) 4)                               ; -Assert `four` returns 4.
  62.     )
  63.   )
  64.  
  65. ;;;;
  66. ;; main code
  67.  
  68. (c:four)                                                ; -Call our main procedure to change the world.
  69.  
Title: Re: AutoLISP Editor in 2024
Post by: JohnK on March 05, 2024, 01:50:01 PM
Oh?! VSCode has folds too!
If you highlight a bunch of code, right click and choose "insert region" you get this:

Code - Auto/Visual Lisp: [Select]
  1. ;#region unit testing
  2.   (DEBUG
  3.     (#assert '(/ 2 0) 0)                                ; -Assert we can devide by zero.
  4.     (#assert '(+ 2 2) 4)                                ; -Assert 2+2 = 4.
  5.     (#assert '(c:four) 4)                               ; -Assert `four` returns 4.
  6.     )
  7.   )
  8. ;#endregion

Check the gutter and you get a collapse feature.  But it looks like it will also hide any breakpoints collapsed in the region though (Come on MS, give me a symbol in the gutter that there is a hidden breakpoint in the collapsed region!).
Title: Re: AutoLISP Editor in 2024
Post by: 57gmc on March 05, 2024, 02:00:25 PM
Try double-clicking a function name, then right-click and choose "Generate Documentation"
Aha! I did that and it used a vertical pipe, not a forward slash as shown in your example. At least that's what it looks like in the code window.
Title: Re: AutoLISP Editor in 2024
Post by: 57gmc on March 05, 2024, 02:06:13 PM
Oh?! VSCode has folds too!
Check the gutter and you get a collapse feature.  But it looks like it will also hide any breakpoints collapsed in the region though (Come on MS, give me a symbol in the gutter that there is a hidden breakpoint in the collapsed region!).
It works on all functions automatically too. Just hover to the left.
Title: Re: AutoLISP Editor in 2024
Post by: kdub_nz on March 05, 2024, 06:23:23 PM

BTW, my files will start to look like this now.

 >>>> snip

And I see that as a good thing for a goal.

but if I see any
;_ Function-Closing   comments in your code I'll find out where you live  :-)




Title: Re: AutoLISP Editor in 2024
Post by: JohnK on March 05, 2024, 08:56:20 PM
Wasn't the "official method" to use: ");_end <function>" but seeing as how I use the "other style" mostly that might make for some very interesting code!! :)

Code - Auto/Visual Lisp: [Select]
  1. (defun squareandcube (nu)
  2.   (* (* nu nu) nu);|_end multiply|; );|_end defun|;
...seems readable.
Title: Re: AutoLISP Editor in 2024
Post by: kdub_nz on March 06, 2024, 12:00:31 AM
So does
Code - Auto/Visual Lisp: [Select]
  1. (defun squareandcube (nu)
  2.   (* nu nu nu)
  3. )
  4.  
. .  :-D

Title: Re: AutoLISP Editor in 2024
Post by: keithsCADservices on March 06, 2024, 10:33:29 PM
"Counterintuitive" was probably not the right word. It's just that it was not documented I guess and up to you to figure it out. Yeah it's too bad that you can't just attach to acad without loading all the code in your lisp file. If you have a bug in it, you might want to test a piece at a time.

For what it's worth I found the documentation to be lacking as well. I was able to get acquainted with Visual Studio (the "big" more complex code editor) quicker than VS Code (for C# programming). That was probably one of the biggest factors in forming my conclusion: VS Code is supposed to be quick, light and easy.
Title: Re: AutoLISP Editor in 2024
Post by: keithsCADservices on March 06, 2024, 10:56:47 PM
If debugging is your only problem, you can use `vl-bt` to debug instead of using VLIDE:

Define a simple error handler with:
Code - Auto/Visual Lisp: [Select]
  1. (defun *error* (msg) (vl-bt))
or
Code - Auto/Visual Lisp: [Select]
  1. (set '*error* (lambda (msg) (vl-bt)))
Create your code:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:bug () (/ 2 0))
debug your code on the command line.
Code: [Select]
Backtrace:
[0.47] (VL-BT)
[1.43] (#<SUBR @00000158a9fa6278 -lambda-> "divide by zero")
[2.39] (_call-err-hook #<SUBR @00000158a9fa6278 -lambda-> "divide by zero")
[3.33] (sys-error "divide by zero")
:ERROR-BREAK.28 nil
[4.25] (/ 2 0)
[5.19] (C:BUG)
[6.15] (#<SUBR @00000158a9fa6548 -rts_top->)
[7.12] (#<SUBR @00000158b0659750 veval-str-body> "(C:BUG)" T #<FILE internal>)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 0)

After your bugs are dead (-i.e. switch to production code), just (setq *error* nil) and/or replace/use your standard error handler.

All the info you're sharing has been immensely helpful. The lack of debugging was another big check in the "VS Code sucks" column for myself. Perhaps Autodesk should pay you to write a better userguide.

I was pretty miffed when I found out that you couldn't debug in AutoCAD LT. At that time they (Autodesk) had just copy-pasted the help docs from Full to LT which let me down a bit of a dead end. They've since fixed it at least. There's defintely work-arounds to make up for it... but for myself I've still had to spent $$$ on ACAD full to make sure I can code at full pace. I'm dying to ditch ACAD Full for either LT or something else.
Title: Re: AutoLISP Editor in 2024
Post by: 57gmc on March 07, 2024, 10:33:17 AM
"Counterintuitive" was probably not the right word. It's just that it was not documented I guess and up to you to figure it out. Yeah it's too bad that you can't just attach to acad without loading all the code in your lisp file. If you have a bug in it, you might want to test a piece at a time.

For what it's worth I found the documentation to be lacking as well. I was able to get acquainted with Visual Studio (the "big" more complex code editor) quicker than VS Code (for C# programming). That was probably one of the biggest factors in forming my conclusion: VS Code is supposed to be quick, light and easy.
I found an issue request on Github. This is a known problem since 2021. I posted a reminder that it's still broken and it was acknowledged. So maybe it will be available in a future release.