Visual Studio VS Code (VSCode) AutoLISP Extension: Good? Global variables report? Error trace?

Visual Studio VS Code (VSCode) AutoLISP Extension: Good? Global variables report? Error trace?

hawstom
Advocate Advocate
1,250 Views
29 Replies
Message 1 of 30

Visual Studio VS Code (VSCode) AutoLISP Extension: Good? Global variables report? Error trace?

hawstom
Advocate
Advocate

(Update: I am putting my happy commitment report in a follow-up reply and marking it as an Accepted Solution)


AutoCAD froze a couple times with the VLISP/VLIDE window open. So I thought I would use some down time to evaluate again the idea of moving from VLISP/VLIDE to Visual Studio Code (VS Code) with the AutoLISP Extension. The AutoCAD help showed me how to get up and running, set breakpoints,  step through code, and format code. But I am left with some questions before I can get to work in this environment:
1. Is anybody using the AutoLISP Extension in VS Studio for seriously large projects? (Mine has 25000 lines in 241 files including 6000 lines in the file I am most interested in working on lately.) Do any experts recommend it instead of good old VLIDE/VLISP?
2. How can I do the equivalent of "Check window" or "Check selection" with statistics (list global variables) enabled to help me manage local variable declarations?
3. How can I do the equivalent of "View error trace" when my code crashes while debugging?

4. How can I control case of various symbol classes when formatting like I can in VLIDE/VLISP?
5. How can I Rebuild FAS files for my old Visual Lisp project?

 

Thanks in advance for your expert advice, especially regarding the first question or any silver linings or workarounds!

 

Tom

0 Likes
Accepted solutions (2)
1,251 Views
29 Replies
Replies (29)
Message 21 of 30

Sea-Haven
Mentor
Mentor

@DGCSCAD I would recommend you get a copy of Notepad++ its free and has an inbuilt format as lisp code, has bracket checking, including dcl's, color formatting.  A run code from within Notepad++ which is a great feature.

Message 22 of 30

DGCSCAD
Collaborator
Collaborator

Thanks Sea-Haven.

I have it installed and have used it briefly. It's a matter of having enough time to get used to it. I'm hopeful I'll find some time to dig into new (to me) tools in the near future though.

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 23 of 30

BlackBox_
Advisor
Advisor

@DGCSCAD wrote:

Thanks Sea-Haven.

I have it installed and have used it briefly. It's a matter of having enough time to get used to it. I'm hopeful I'll find some time to dig into new (to me) tools in the near future though.


I'm also a fan of Notepad++ and use it often for all of my XML files, like Autoloader's PackageContents.xml, etc. 

 

The ComparePlus plugin has been invaluable as well:

 

https://github.com/pnedev/comparePlus/releases/tag/cp_2.1.1


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes
Message 24 of 30

DGCSCAD
Collaborator
Collaborator

I do use the Compare feature along with ET sysvdlg for narrowing down error's between users.

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 25 of 30

hawstom
Advocate
Advocate

Interesting. Can you say a little more as an introduction about "Compare feature along with ET sysvdlg"?

0 Likes
Message 26 of 30

DGCSCAD
Collaborator
Collaborator

@hawstom 

 

Sure, when there's an issue with one user and all other users are functioning as normal, I'll save a copy of the errant PC's system variables (.SVF) through the sysvdlg and compare it with a working PC's exported system variables (.SVF) in Notepad++ to see if something has been set differently.

 

sysvdlg is an Express Tool that displays and exports all system variables.

 

 

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 27 of 30

hawstom
Advocate
Advocate

@DGCSCAD, oh. Very cool.

Tom

0 Likes
Message 28 of 30

Sea-Haven
Mentor
Mentor

You can also use Logfileon and do setvar ? * yes have to press enter a lot. Then do Logfileoff and a log file is saved to your temporary location and like others I have used compare to work out what is wrong.

 

I would also recommend download the ActiveX plugin allows you to run lisp code from with Notepad++ a very handy feature.

0 Likes
Message 29 of 30

hawstom
Advocate
Advocate
Accepted solution

# Update
I've been programming a lot these ten days, trying out VS Code the entire time. And generally I am very happily committed to VS Code (VSCode) now. I went back to VLIDE just once for code formatting (the grass was not much greener there); I may go back again to Rebuild FAS. I feel like I am programming better already.

 

In this reply I am listing Solutions to my original post, features that are Winning me over. Good features, WorkaroundsBad features, and my new Wish List. Maybe this should be a blog post. 😅

 

# Solutions
1. Large projects: This is a winner. Navigation and overview are noticeably better. See my Winning features section.
2. Globals: See Globals under Workarounds
3. View Error Trace: Similar hyperlinked crash point information is provided in the PROBLEMS tab of the bottom pane on crash.
4. Formatting and Case: See Case under the Good section. You can't do this once and for all in your formatting settings. Since I am getting older, I chose to standardize on upper case for everything except User Interface text; this makes coding easier for me to see. I decided generally to adjust to what Format does without worrying about how it will affect my git logs. I still am learning the nuances of how Format reacts to my existing line breaks.
5. Rebuild FAS: See this Solution reply by @paullimapa.

 

# Winning features

These seal the deal.
- Fold/Collapse blocks/expressions plus file #regions: This does wonders for my 6000-line file (see my open source code base at github). I promptly added foldable #regions to the files I am editing (cnm.lsp and edclib.lsp). And I refactored all my defuns there to have (DEFUN FUNCTION_NAME (ARGUMENTS / LOCALS) on the same line.
- Find all references in block/file, Shift+Alt+F12, puts a very handy hyperlinked list in the left pane of the defun and all calls for the function name under the cursor. This is surprisingly helpful for auditing a process from top to bottom.
- Start of current block/expression is always automatically shown/frozen/scroll-locked at top of window. This took me a little while to notice, but it's very helpful.
- Debug editing: I can edit my code during debug and then hit reload midstream if I choose. It is a surprising convenience to have run-time values shown while I am editing and to have the reload button always available.
- Debug inspection: I am free of Inspect and Add to Watch because the variables I care about are intuitively available by hovering or in the left pane Locals list. As a bonus, when I focus on the left pane Locals list, Globals management is mostly natural and intuitive; encouraging better habits. And I expect that there are more efficiencies left for me to discover and notice.
- Layout: The fact that the screen is organized into panes instead of windows turns out to be very productive. For example, I rarely visited the Visual Lisp Console because it was not at a reliable standard location across installations, machines, and sessions. In VSCode, I am there all the time.

- Keyboard shortcuts: I am learning keyboard shortcuts that are making me more productive; better habits.

- Snippets: I defined the few code snippets I need most. Very worthwhile. See the end of this reply.

- App switching: Switching between VS Code and AutoCAD seems less buggy. And it's nice to be able to run VS Code without AutoCAD if I get to like VS Code enough.

 

# Good

(alphabetical order)
- Block Start automatically shown/locked at top of tab. I didn't notice this at first. Very helpful.
- Case to upper: Ctrl+Shift+P > Upper (type the letters "Up" then Enter)
- Collapse sections: (see Fold)
- Duplicate line: Shift + Alt + Down Arrow or Shift + Alt + Up Arrow.
- Find all references in block/file: Shift+Alt+F12 with cursor on a function name. Well implemented. Play with it.
- Fold or unfold file: Ctrl+K > Ctrl+0 (fold all) or Ctrl+J (unfold all)
- Fold or unfold this block: Ctrl+K > Ctrl+[ or ]. Very good to "open" a single region or function.
- Fold any file levels deeper than X: Ctrl+K > Ctrl+2 (for level 2). To be honest, I haven't exactly figured this out.
- Goto Definition in split screen: Ctrl+Alt+Click. Very helpful. But I stopped using it as much as "Find all references" above.
- Inspect during debug: See Locals list in left pane (good programming practice) or hover over any variable.
- Select block (expand/shrink): Alt+Shift+Right/Left

- Snippets: Ctrl+Shift+P > Snippets then Ctrl+Shift+P > DevRe to create your own code snippets in autolisp.json and load them. My additions are at the end of this reply.
- Watch automatically in "Variables" under "Run and Debug" in the left pane during debug.

 

# Workarounds
- Globals: Locals are listed in the (left side) Run and Debug pane during debug. If a variable doesn't appear there, it is global. This is poor insurance. But I think it encourages good programming practice with incremental and natural Locals management. At least it can be a heads up and a clue. And it is a very handy watch list. If still desperate for a good old complete list of globals, I'll try this workaround by @john_uhden.

 

# Bad
- Formatting: (Mark block w/ repeated Alt+Shift+Right then Ctrl+K, Ctrl+F.) Yuck. I'm working with it and trying to understand it better.

- The AutoLISP Extension or VS Code sometimes hangs. My tab key stops working; I restart VSCode. Auto-indent stops working; I Reload the file (seems to restart the extension).

 

# Wish list

- Refactoring: I wish it were easier to pull out a code block to a function. This is a pervasive need and a common feature. Eventually I will be taking time to figure it out.

 

I ran this by Grok AI assistant for ideas, which was helpful.

 

Tom

# Snippets

	// Reload with Ctrl+Shift+P > DevRe

"Cond UC": {
	"prefix": "COND",
	"body": [
		"(COND",
		"  (${1:TESTEXPR1}",
		"   ${2:[THENEXPR1 ...]}",
		"  )",
		"  (${3:TESTEXPR2}",
		"   ${4:[THENEXPR2 ...]}",
		"  )",
		")",
		""
		],
	"description": "Conditional function"
},

"Defun UC": {
	"prefix": "DEFUN",
	"body": [
		"(DEFUN ${1:NAME} (${2:ARGS} / ${3:LOCALVARS})",
		"  ${4:[EXPR ...]}",
		")",
		""
		],
	"description": "Defun Upper Case"
},

"Mapcar Lambda UC": {
	"prefix": "MAPCAR LAMBDA",
	"body": [
		"(MAPCAR",
		"  '(LAMBDA (${1:ARGS} / ${2:LOCALVARS})",
		"    ${3:[EXPR ...]}",
		"  )",
		"  ${4:LIST}",
		")",
		""
		],
	"description": "Mapcar lambda block"
},

// This is neither my style nor the VS Code Format style. I could change this later.
"Setq UC": {
	"prefix": "SETQ",
	"body": [
		"(SETQ",
		"  ${1:SYM1}",
		"   ${2:[EXPR1 ...]}",
		")",
		""
		],
	"description": "Setq function"
},

 

Message 30 of 30

Chris_GILMERRTXWM
Enthusiast
Enthusiast

After years of doing the same, as I find them, I add the errant system variable and the preferred setting to a setvars.lsp file.

I load this file every time a drawing is opened and setvars are reset to their preferred value.

 

Typically, they get reset to what they already are, but that one time it's needed... I don't get bothered.

This has greatly cut down the amount of time spent figuring out 'what is wrong with this machine'.

 

Here is my current copy of this file.

 

;;;
;;; Plot Style Table Search Path
;;;
(if (not (wcmatch (getenv "PrinterStyleSheetDir") "*drv:\\path\\path\\path\\P_Plotstyles*"))
	(progn
	 (setenv "PrinterStyleSheetDir" (strcat "drv:\\path\\path\\path\\P_Plotstyles;" (getenv "PrinterStyleSheetDir")))
	 (if (wcmatch (getenv "PrinterStyleSheetDir") "*drv:\\path\\path\\path\\P_Plotstyles*")
		(princ "\n    '..\\P_Plotstyles' path successfully added to Plot Style Table Search Path")
	 )
	)
	(princ "\n    '..\\P_Plotstyles' path already part of Plot Style Table Search Path")
)

;;;
;;; individual setvars
;;;
(setvar "MAXSORT" 32767)			;;; the maximum number of symbol names sorted by listing commands.
(setenv "CMDHISTLINES" "2048")		;;; the maximum number of lines in the command history dialog
(setvar "HPASSOC" 1)				;;; 1 - controls whether hatch patterns and gradient fills are associative.  Hatch patterns and gradient fills are associated with their boundaries and are updated when the boundaries change,

(setvar "SAVETIME" 10)				;;; turns on autosave and sets time for 10 minutes
(setvar "HPDRAWORDER" 1)			;;; The hatch or fill is sent to the back of all other objects.
(setvar "PICKFIRST" 1)				;;; Select objects before you start a command.

(setvar "BINDTYPE" 1)				;;; sets [xref > bind] to insert mode
(setvar "PROXYNOTICE" 0)			;;; Turns off the notice for choosing to display proxy objects
(setvar "PROXYSHOW" 1)				;;; Displays proxy objects

(setvar "ELEVATION" 0.0)			;;; set current UCS elevation to 0'-0"
(setvar "SNAPSTYL" 0)				;;; sets crosshairs to orthogonal mode
(setvar "SNAPANG" 0.0)				;;; snap, grid and crosshair rotation angle for the current viewport.

(setvar "LUNITS" 2)					;;; set unit type to decimal
(setvar "LUPREC" 4)					;;; set unit precision for 0.0000
(setvar "LAYEREVALCTL" 0)			;;; turns off the evaluation and notification of new layers

(setvar "XLOADCTL" 2)				;;; Turns on demand-loading but uses a temporary copy of the xref. The original file is not locked, allowing others to modify it.

 

0 Likes