Community
    • Login

    PythonScript 3.0.24.0 - "PluginsManager:runPluginCommand Exception" dialog with "Access Violation" with one of my scripts.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    pythonscriptpythonerrorscriptingaccess violationplugins
    1 Posts 1 Posters 14 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Jay SJ
      Jay S
      last edited by Jay S

      Overview

      Hi, I need help with the Python3 version of PythonScript.

      I’m using the latest release from here: https://github.com/bruderstein/PythonScript/releases/tag/v3.0.24

      My current scripts are all working fine, but I created a new script today (via Claude Opus 4.5) to transform a specific JSON format to another. Claude has never failed me until today.

      The script is intended to convert valid RGB values in the input, and then replace each value with the equivalent HTML Hex value.

      This is my script (FM TransformColorJsonRgbToHex.py):

      # -*- coding: utf-8 -*-
      """
      RGB to Hex Color Converter for Notepad++ PythonScript
      Converts RGB color values like "22, 22, 24" to hex format "#161618"
      Handles selection or entire document with full undo support.
      """
      
      import re
      
      def rgb_to_hex(match):
          """
          Convert an RGB string match to hex format.
          
          Args:
              match: Regex match object containing RGB values
              
          Returns:
              Hex color string in format "#RRGGBB"
          """
          try:
              r = int(match.group(1).strip())
              g = int(match.group(2).strip())
              b = int(match.group(3).strip())
              
              # Clamp values to valid RGB range
              r = max(0, min(255, r))
              g = max(0, min(255, g))
              b = max(0, min(255, b))
              
              return '"#{:02X}{:02X}{:02X}"'.format(r, g, b)
          except (ValueError, AttributeError):
              # Return original if conversion fails
              return match.group(0)
      
      
      def convert_rgb_to_hex(text):
          """
          Convert all RGB color values in text to hex format.
          
          Matches patterns like:
              "22, 22, 24"
              "255, 128, 0"
              " 22 , 22 , 24 " (with extra whitespace)
          
          Args:
              text: Input text containing RGB color values
              
          Returns:
              Text with RGB values converted to hex
          """
          # Pattern matches quoted RGB values: "R, G, B"
          # Captures three groups of digits separated by commas
          # Allows flexible whitespace
          pattern = r'"(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})"'
          
          return re.sub(pattern, rgb_to_hex, text)
      
      
      def main():
          """Main entry point for the script."""
          
          # Check if there's a selection
          selection_start = editor.getSelectionStart()
          selection_end = editor.getSelectionEnd()
          has_selection = selection_start != selection_end
          
          # Begin undo action for single-step undo
          editor.beginUndoAction()
          
          try:
              if has_selection:
                  # Process only selected text
                  selected_text = editor.getSelText()
                  converted_text = convert_rgb_to_hex(selected_text)
                  
                  if selected_text != converted_text:
                      editor.replaceSel(converted_text)
                      notepad.messageBox(
                          "RGB to Hex conversion complete (selection).",
                          "Conversion Complete",
                          0
                      )
                  else:
                      notepad.messageBox(
                          "No RGB color values found in selection.",
                          "No Changes",
                          0
                      )
              else:
                  # Process entire document
                  full_text = editor.getText()
                  converted_text = convert_rgb_to_hex(full_text)
                  
                  if full_text != converted_text:
                      # Preserve cursor position
                      current_pos = editor.getCurrentPos()
                      editor.setText(converted_text)
                      
                      # Restore cursor (adjust if position is now out of bounds)
                      new_length = editor.getTextLength()
                      editor.gotoPos(min(current_pos, new_length))
                      
                      notepad.messageBox(
                          "RGB to Hex conversion complete (entire document).",
                          "Conversion Complete",
                          0
                      )
                  else:
                      notepad.messageBox(
                          "No RGB color values found in document.",
                          "No Changes",
                          0
                      )
          finally:
              # Always end undo action, even if an error occurs
              editor.endUndoAction()
      
      
      # Execute the script
      main()
      

      This is my input (I’ve tried running on selection as well as the whole file):

      {
        "Name": "Some Name",
        "BackgroundColor": "22, 22, 24",
        "LightBackgroundColor": "19, 19, 21",
        "DarkBackgroundColor": "14, 14, 15",
        "TextColor": "227, 227, 239",
        "BorderColor": "39, 39, 42",
        "CheckerColor": "213, 188, 170",
        "CheckerColor2": "212, 146, 146",
        "CheckerSize": 17,
        "LinkColor": "95, 136, 255",
        "MenuHighlightColor": "44, 44, 52",
        "MenuHighlightBorderColor": "28, 28, 34",
        "MenuBorderColor": "28, 28, 34",
        "MenuCheckBackgroundColor": "186, 219, 130",
        "MenuFont": "Roboto, 14px",
        "ContextMenuFont": "Roboto, 14px",
        "ContextMenuOpacity": 100,
        "SeparatorLightColor": "255, 75, 238",
        "SeparatorDarkColor": "25, 25, 28"
      }
      

      Error when Running Script

      When I run the script, Notepad++ throws up an “Access Violation” dialog.

      Access Violation Error

      PluginsManager::runPluginCommand Exception
      Access Violation
      

      Other Screenshots:

       
      Entire Window

      About

      Config

      I have a lot of custom toolbar customization, ignore that please for now.


      Ways to debug this?

      This is really frustrating to diagnose because even though I have the “Show Console” enabled for PythonScript globally, it doesn’t seem to show the error in the console at all, and I have no way of knowing what line or specific section of code is throwing this error.

      All of my old scripts work completely fine, so I don’t think this is an installation issue. Can someone possibly spot what’s wrong with my script or at least provide me with a better way to debug this? I have no clue what to do in order to diagnose this bug.

      Any help would be super amazing!

      Thanks.

      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      The Community of users of the Notepad++ text editor.
      Powered by NodeBB | Contributors