/adams_vscode

Primary LanguagePythonMIT LicenseMIT

MSC Adams Extension for Visual Studio Code

Visual Studio Marketplace Installs Visual Studio Marketplace Rating Stars Visual Studio Marketplace Version

This is an early version. If you are interested in using it, please reach out and let me know which features you are most interested in. Thanks!

Table of Contents

Features

Syntax highlighting

  • Adams View Command Languange (.cmd)
  • Adams Solver Dataset Files (.adm)
  • Adams Solver Command Files (.acf) ``

Adams View Command Language Intellisense

  • Adams Function Completion Provider
  • Adams Function Documentation Hover Provider

Example of Adams Function Documentation Hover Provider Example

Intellisense support for Adams View Python Interface

  • Completion provider
  • Function signature help provider
  • Type hinting

Note

You may need to manually activate the extension using msc_adams.activate for these features to work adams python autocomplete

Support for debugging python scripts in Adams View

You can debug python scripts in Adams View using the Python Extension. This extension provides a convenient button to attach the debugger to an existing Adams View process.

Steps to debug a python script in Adams View

  1. Open an Adams View session
  2. Open the python script you want to debug in Visual Studio Code
  3. Click the Debug Python Script in Adams button in the top right of the editor
    • Note: If you have multiple Adams View sessions open, you will be prompted to select one
  4. Set breakpoints in the python script
  5. In the Adams View session, import the python script
  6. The python script will break at the breakpoints.

debugging a python script in adams

Run in Adams View

Important

The command server must be running for these features to work. The demos below show how to start the command server.

Tip

Add command_server start to your startup macro (aviewAS.cmd or aview.cmd) to automatically start the command server when Adams View is opened. This will allow you to run python scripts in
Adams View without having to manually start the command server.

Run selection in Adams View (works for both CMD and Python files)

Run CMD Selection in Adams View

Run File in Adams View (This works for both CMD and Python files)

Run CMD File in Adams View

Note

For python files, the button is located within the existing python run button stack.! Alt text

Open Adams View From Explorer

  • Open Adams View in a directory from the Explorer by right clicking and selecting Open View Example of opening adams view in a directory

  • Open a .cmd model file in Adams View from the Explorer by right clicking and selecting Open In View Example of opening adams view in a directory

Snippets

  • Adams View Command Language Snippets
  • Adams View Python Interface Snippets

Extension Settings

This extension contributes the following settings:

  • msc-adams.adams_launch_command: Path to the mdi.bat file in your Adams installation.

Customizing Syntax Colors

You may override the extension's default syntax colors using the editor.tokenColorCustomizations setting. The extension uses the following scopes:

  • parameter.reference
  • variable
  • constant
  • arguments
  • parameter.definition
  • selfParameter
  • command.command
  • command.control
  • command.argument
  • command.argument.continued

The example below would change the color and font style of the variable scope

"editor.tokenColorCustomizations": {     
  "textMateRules": [
    {
      "scope": "variable",
      "settings": {
          "foreground": "#02485e",
          "fontStyle": "bold"
      }
    }
  ]
}

Run In Adams: Substitute Params

When enabled (default), the extension will substitute macro parameters (i.e. variables prefixed with $) in the macro/selection before running it in Adams View. This will only work if the parameter is defined in the the macro with a default value

For example, the following macro will run in Adams View with the parameter $part substituted with PART_1 and $mass substituted with 1.

!$part:t=part:d=PART_1
!$mass:t=real:d=1
part modify rigid_body mass_properties part=$part mass=$mass

However, the following macro will not run in Adams View because the parameter $part is not defined with a default value.

!$part:t=part
!$mass:t=real:d=1
part modify rigid_body mass_properties part=$part mass=$mass

Run In Adams: Substitute $_self

When running a macro or a selection of a macro, the extension will substitute $_self with the a user defined value. The default is .mdi. This is useful when the macro uses local variables.

Note

It is common convention to clear out local variables at the end of a macro using var del var=$_self.*. If using this convention, you should not use the default .mdi. Instead, it is recommended to create an empty library in adams view and set the value of msc-adams.runInAdams.substituteSelf to the name of the library.

Requirements

Known Issues

Attaching the Debugger to Adams View does not work in version 2023

The debugger appears to attach but fails to stop at break points.

Tip

A workaround is to simply import the threading module before attaching the debugger. The easiest way to do this is to open the adams view command line, switch to python, and run import threading. You can also automate this by adding var set var=.mdi.tmp_int int=(eval(run_python_code("import threading"))) to aviewAS.cmd.

Intellisense Adams Command Language functions does not work for every function

It's a work in progress. The help documentation for each function needs to be converted to a markdown file and I simply haven't had time to do every function.

Equal Sign In A String On A Continuation Line

An equal sign in a string on a continuation line (i.e. a line following &) breaks syntax highlighting for the rest of the file.

A workaround is to add !" after the line with the equal sign. As shown below.

Animation of issue when an equal sign is in a string on a continuation line

Contributing

...

Support

Submit issues to https://github.com/bthornton191/adams_vscode/issues