MicroStation Python: VS Code IntelliSense


 

Welcome to the world of MicroStation Python! In this wiki, we will enable IntelliSense for MicroStation Python APIs in Visual Studio Code editor. IntelliSense provides context for the objects you are using and displays available functions as you type.

 

VS Code Extension for IntelliSense

Here are the steps to install the PyLance extension in Visual Studio Code for IntelliSense to work for MicroStation Python APIs, enhancing your coding experience:

  1. Open Visual Studio Code: Launch the Visual Studio Code editor on your computer.
  2. Access the Extensions View: Click on the Extensions icon in the Activity Bar on the side of the window. Alternatively, you can open the Extensions view by pressing Ctrl+Shift+X
  3. Search for PyLance: In the Extensions view, type "PyLance" in the search bar at the top.

  1. Install PyLance: Find the PyLance extension from Microsoft in the search results and click the "Install" button.

 

Option 1: VS Code settings.json file modifications

Furthermore, the settings.json file should reference the directories containing the .PYI files. Follow these steps:

  1. Open the settings.json file: in a text editor from the following directory: C:\Users\UserName\AppData\Roaming\Code\User\

Alternatively, type "Preferences: Open User Settings (JSON)" in the Command Palette search bar.

  1. Modify the settings.json file: by adding the following lines and save the file. 
{
    "explorer.confirmDelete": false
    "python.languageServer": "Default",
    "python.analysis.stubPath": "C:/ProgramData/Bentley/PowerPlatformPython/Examples/MicroStation/Intellisense",
    "python.analysis.extraPaths": ["C:/Program Files/Bentley/MicroStation 2024/MicroStation/"],
}
  1. Restart Visual Studio Code: to ensure changes take effect.
  2. Verify IntelliSense Setup: press Ctrl+Space to open the IntelliSense window. As you type, IntelliSense will display information about the objects and functions you are using.

 

Option 2: Set PYTHONPATH System Environment Variable

Adding the following folders to the system environment variable PYTHONPATH will enable IntelliSense in Visual Studio Code. The function stubs required for IntelliSense are in the following directories.

C:/ProgramData/Bentley/PowerPlatformPython/Examples/MicroStation/Intellisense/
C:/Program Files/Bentley/MicroStation 2024/MicroStation/

 

By following these steps, you will have IntelliSense set up for MicroStation Python APIs in Visual Studio Code editor, providing context and suggestions as you code.

 

 

Python: Documentation | API Presentations | FAQs | GitHub | Samples | Wikis | Blogs