BIGAL Posted April 15, 2022 Posted April 15, 2022 Hi I have been using the Notepad++ run lisp extension for ages and its stopped working after installing an upgrade, I tried going to the web site link https://sourceforge.net/projects/nppactivexplugin/ and have just gone around in circles trying to join so could send a message re problem, is anyone else having problems ? Do you have a sourceforge account and could send a message would be appreciated. ; This routine runs the code in the active editor of NotePad++ from AutoCAD: (defun C:n++ nil (C:RunFromNotePadPP)) ; Quick Run (defun C:RunFromNotePadPP ( / scr *error* err np++ npeditor npSS npMS r ) ; NOTE: Requires ActiveX plugin(by David Gausmann) installed on the NP++ ; https://sourceforge.net/projects/nppactivexplugin/ (defun *error* (m) (foreach x (reverse (list np++ npeditor npSS npMS)) (vl-catch-all-apply (function vlax-release-object) (list x)) ) (gc) (gc) (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\nError: " msg)))) (princ) ); defun *error* (setq err (vl-catch-all-apply (function (lambda nil ; THIS WORKS - IT GETS THE ACTIVE DOCUMENT CODE IN NOTEPAD !!! (setq np++ (vlax-get-or-create-object "NotepadPlusPlus.Application")) (setq npeditor (vlax-get np++ 'ActiveEditor)) (vlax-invoke-method npeditor 'selectAll) (setq npSS (vlax-get npeditor 'selections)) (setq npMS (vlax-get npSS 'mainSelection)) (setq r (vlax-get-property npMS 'text)) (vlax-invoke npSS 'setRange 0 0 0 0) ); lambda ); function ); vl-catch-all-apply ); setq err (*error* nil)(princ) (if (and r (not (vl-catch-all-error-p err))) (eval (read (strcat "(list\n" r "\n)"))) ) ); defun Quote
BIGAL Posted April 16, 2022 Author Posted April 16, 2022 i have been using every day for years just turned off after last Notepad++ update, I have lodged a ticket at Sourceforge. Was wondering if anybody else has had the problem. Uninstalled and reinstalled plugin no go Bricscad and Autocad. Quote
abra-CAD-abra Posted April 19, 2022 Posted April 19, 2022 BIGAL, I just tried this using the following (portable) version: npp.8.2.1.portable.x64 It works fine. Out of interest, what do you use it for? Is it to execute scripting language on NP++ files or other files (*.dwg), or both? This post has plunged me into the NP++ plugin world! Thanks BIGAL Quote
BIGAL Posted April 20, 2022 Author Posted April 20, 2022 (edited) I use it to code and run Lisp from N++ you can make your test code as big or break it into little code segments as needed. The closing bracket check is a great help. I did get a response from David @ Sourceforge, awaiting some further comment. Edited April 20, 2022 by BIGAL Quote
abra-CAD-abra Posted April 20, 2022 Posted April 20, 2022 I have used NP++ for a while now but never really looked at the plugins. I have installed a few now, including the brackets check plugin. The N++ function you shared above is really useful - I can see why you are keen to get this plugin working again Quote
BIGAL Posted April 21, 2022 Author Posted April 21, 2022 Load "Compare" plugin its really handy use with entget when changing 1 variable and trying to find dxf numbers. Same with setvar. use replace ") (" with ")\r(" when comparing entgets. 1 Quote
ymg3 Posted 1 hour ago Posted 1 hour ago @BIGAL, I am quite sure you settled your issue in N++ a long time ago. I was facing the same situation so maybe the following will be of interest to you. I am using NppExec to Validate and Load a file to Autocad. The NPPexec either save either a Selection or the Whole active window of Notepad++ in a tempfile called "D:\Lisp\NppVal.lsp". This has to be a trusted Autocad Location. NppExec then transfer execution to a PowerShell script called ValidateAndLoad.ps1. This script is placed in directory "C:\Scripts\ValidateAndLoad.ps1" . The powershell validates the lisp and then if valid, Load it in Autocad. It then Activate the Autocad Window and brings it into view. All that need to be done is to start the command you just loaded. To Activate and bring in View, all the usual command were failing until I found a little utility called nircmd. So that is what the ps1 script uses. You will need to downlad it from https://www.nirsoft.net/utils/nircmd.html and place it in same directory "C:\Scripts" as the ps1 script. Following is the NppExec script: npp_console 1 env_set NPP_FILENAME = $(FILE_NAME) // Get selection info sci_sendmsg SCI_GETSELECTIONSTART set local pos_start = $(MSG_RESULT) sci_sendmsg SCI_GETSELECTIONEND set local pos_end = $(MSG_RESULT) sci_sendmsg SCI_LINEFROMPOSITION $(pos_start) set local start_line = $(MSG_RESULT) // Create temp file for current context if $(pos_start) == $(pos_end) then // No selection: Save whole file sci_sendmsg SCI_SELECTALL sel_saveto "D:\lisp\NppVal.lsp" sci_sendmsg SCI_SETEMPTYSELECTION $(pos_start) cmd /c powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\ValidateAndLoad.ps1" -FilePath "D:\lisp\NppVal.lsp" -ScintillaLine 0 -IsSelection 0 else // Selection exists sel_saveto "D:\lisp\NppVal.lsp" cmd /c powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\ValidateAndLoad.ps1" -FilePath "D:\lisp\NppVal.lsp" -ScintillaLine $(start_line) -IsSelection 1 endif env_unset NPP_FILENAME Note: NPP script does not save your file by design, when debugging I don't want to Save. Following is the ValidateAndLoad.ps1 param( [string]$FilePath, [int]$ScintillaLine = 0, [int]$IsSelection = 0 ) $ErrorActionPreference = 'Stop' $TargetDir = 'D:\lisp' $TargetFile = Join-Path $TargetDir 'NppVal.lsp' $NirCmdPath = 'C:\scripts\nircmd.exe' $MaxRetries = 10 $RetryDelayMs = 300 if (-not $FilePath) { Write-Output "ERROR: No file path provided." exit 1 } if (-not (Test-Path -LiteralPath $FilePath)) { Write-Output "ERROR: File not found: $FilePath" exit 1 } try { $enc = [System.Text.Encoding]::GetEncoding(1252) $Text = [System.IO.File]::ReadAllText($FilePath, $enc) } catch { Write-Output "ERROR: Failed to read file: $($_.Exception.Message)" exit 1 } $FileName = [System.Environment]::GetEnvironmentVariable("NPP_FILENAME") if (-not $FileName) { $FileName = "Unsaved Document" } Write-Output "VALIDATING: $FileName" $level = 0 $inString = $false $inComment = $false $inBlockComment = $false if ($IsSelection -eq 1) { $line = $ScintillaLine + 1 } else { $line = 1 } $col = 0 $bracketStack = [System.Collections.Generic.List[PSCustomObject]]::new() $expressionStack = @() $global:defunCount = 0 function New-ValidateExpression { param( [string]$ExprText, [int]$StartLine, [int]$StartCol, [boolean]$IsQuoted ) $cleanText = $ExprText -replace "\([^\(\)]*\)", " #EXPR " $cleanText = $cleanText.Replace("`r", " ").Replace("`n", " ").Trim() $tokens = $cleanText -split '\s+' | Where-Object { $_ -ne "" } if ($tokens.Count -eq 0) { return } $firstToken = ([string]$tokens).ToLower() if (-not $IsQuoted) { if ($firstToken -like '"*') { Write-Output "ERROR: First element in expression cannot be a string literal at line $StartLine, col $StartCol" exit 1 } if ($firstToken -match '^[+-]?[0-9]+(\.[0-9]+)?$') { Write-Output "ERROR: First element in expression cannot be a numeric literal at line $StartLine, col $StartCol" exit 1 } } if ($firstToken -eq "setq") { $argCount = $tokens.Count - 1 if ($argCount -eq 0) { Write-Output "ERROR: 'setq' requires at least one symbol-value pair at line $StartLine, col $StartCol" exit 1 } if ($argCount % 2 -ne 0) { Write-Output "ERROR: 'setq' has an odd number of arguments ($argCount) at line $StartLine, col $StartCol" exit 1 } } } for ($i = 0; $i -lt $Text.Length; $i++) { $c = $Text[$i] $col++ if ($c -eq "`n") { $line++ $col = 0 } if (-not $inString) { if ($inBlockComment) { if ($c -eq '|' -and $i + 1 -lt $Text.Length -and $Text[$i+1] -eq ';') { $inBlockComment = $false $i++ $col++ } continue } if ($inComment) { if ($c -eq "`n") { $inComment = $false } continue } if ($c -eq ';' -and $i + 1 -lt $Text.Length -and $Text[$i+1] -eq '|') { $inBlockComment = $true $i++ $col++ continue } if ($c -eq ';') { $inComment = $true continue } } if ($c -eq '"') { $isEscaped = $false if ($i -gt 0 -and $Text[$i-1] -eq '\') { $slashCount = 0 $k = $i - 1 while ($k -ge 0 -and $Text[$k] -eq '\') { $slashCount++ $k-- } if ($slashCount % 2 -ne 0) { $isEscaped = $true } } if ($isEscaped) { if ($expressionStack.Count -gt 0) { $expressionStack[-1] += $c } continue } $inString = -not $inString if ($expressionStack.Count -gt 0) { $expressionStack[-1] += $c } continue } if ($inString) { if ($expressionStack.Count -gt 0) { $expressionStack[-1] += $c } continue } if ($c -eq '(') { $level++ $isListQuoted = $false if ($i -gt 0 -and $Text[$i-1] -eq "'") { $isListQuoted = $true } elseif ($bracketStack.Count -gt 0) { $isListQuoted = $bracketStack[-1].IsQuoted } $bracketStack.Add([PSCustomObject]@{ Line = $line Col = $col IsQuoted = $isListQuoted }) $expressionStack += "" if (-not $isListQuoted -and $i + 10 -lt $Text.Length) { $lookAheadSlice = $Text.Substring($i + 1, 10).ToLower() if ($lookAheadSlice -match '^\s*defun(-q)?(\s|$)') { $global:defunCount++ } } if ($i + 1 -lt $Text.Length -and $Text[$i+1] -eq ')') { $isDefunArgs = $false if ($expressionStack.Count -gt 1) { $parentExpr = $expressionStack[-2].Trim().ToLower() if ($parentExpr -like "defun*" -or $parentExpr -match "(^|\s)defun(-q)?(\s|$)") { $isDefunArgs = $true } } $isQuotedList = $isListQuoted if ($i -gt 1 -and $Text[$i-1] -match '\s' -and $Text[$i-2] -eq "'") { $isQuotedList = $true } if (-not $isDefunArgs -and -not $isQuotedList) { Write-Output "ERROR: Empty parentheses () found outside of a function definition at line $line, col $col" exit 1 } } continue } if ($c -eq ')') { $level-- if ($level -lt 0) { Write-Output "ERROR: Unexpected closing parenthesis ')' at line $line, col $col" exit 1 } if ($bracketStack.Count -gt 0) { $finishedExpr = $expressionStack[-1] $lastIndex = $bracketStack.Count - 1 $currentBracket = $bracketStack[$lastIndex] $bLine = $currentBracket.Line $bCol = $currentBracket.Col $bQuoted = $currentBracket.IsQuoted New-ValidateExpression -ExprText $finishedExpr -StartLine $bLine -StartCol $bCol -IsQuoted $bQuoted $bracketStack.RemoveAt($lastIndex) if ($expressionStack.Count -gt 1) { $expressionStack = $expressionStack[0..($expressionStack.Count - 2)] $expressionStack[-1] += " #EXPR " } else { $expressionStack = @() } } continue } if ($expressionStack.Count -gt 0) { $expressionStack[-1] += $c } } if ($level -gt 0) { $lastOpen = $bracketStack[-1] Write-Output "ERROR: Unclosed parenthesis '(' starting at line $($lastOpen.Line), col $($lastOpen.Col)" exit 1 } Write-Output "SUCCESS: Validated $global:defunCount function(s) successfully." if (-not (Test-Path -LiteralPath $TargetDir)) { New-Item -ItemType Directory -Path $TargetDir -Force | Out-Null } try { $enc = [System.Text.Encoding]::GetEncoding(1252) [System.IO.File]::WriteAllText($TargetFile, $Text, $enc) } catch { Write-Output "ERROR: Failed to write $TargetFile : $($_.Exception.Message)" exit 2 } if (Test-Path -LiteralPath $NirCmdPath) { try { Start-Process -FilePath $NirCmdPath -ArgumentList 'win activate stitle AutoCAD' -WindowStyle Hidden | Out-Null Start-Sleep -Milliseconds 500 } catch { } } $acad = $null for ($i = 1; $i -le $MaxRetries; $i++) { try { $acad = [Runtime.InteropServices.Marshal]::GetActiveObject('AutoCAD.Application') if ($acad) { break } } catch { Start-Sleep -Milliseconds $RetryDelayMs } } if (-not $acad) { Write-Output "ERROR: Could not attach to a running AutoCAD instance." exit 4 } try { $safePath = $TargetFile.Replace('\', '\\') $acad.ActiveDocument.SendCommand("(load `"$safePath`")`n") Write-Output "SUCCESS: Loaded $TargetFile" exit 0 } catch { Write-Output "ERROR: Failed to send load command to AutoCAD: $($_.Exception.Message)" exit 5 } Notes: Autocad has to running and a drawing open in order to load. If validation fails you are dumprd back to N++ with the NppExec console showing you where it fails. If you double click on the error line you cursor in N++ will go to that line. Bear in mind that the error location is not perfect, but you are normally in the right function. Finally to get the error lines and Success lines to appear in red, you have to set the NppExec Console Filters as shown in the below image. Phew!! that was a long post. ymg Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.