Python interface definition stubs / modules (.pyi files) are a standardized way to describe API that is accessible from Python, but not implemented as Python code. They can contain type information which advanced Python editors like Visual Studio Code with the Python extension can utilize to provide very smart auto-completion and static type checking.

I have produced / generated full pyi definition for VC 4.8 Premium’s API based on the newonline help.

Here is a (silent) demo of using these with Visual Studio Code, using Pylance as type checker.

Features:

  • Includes all Python classes and their members (properties, methods, constructors, events) + constants as described in the online help.
  • Includes accurate type information where possible.
  • Includes descriptions and direct links to the online help.
  • Module organization is similar to VC. Functions from vcScript, vcCommand, vcVector etc. can be imported.

Caveats:

  • Definitions for some base classes such as vcBehaviour have to include properties that may only exist in some of the behaviours. These have a note in the description.
  • 类型检查器已不再真正支持 Python 2,因此它们会提示 print 语句和类型间赋值的问题,因为无法使用类型转换。
  • 动态创建的属性无法被识别,因此不会被包含在内。

如何在 Visual Studio Code 中使用

  • 下载并解压 pyi 文件到合适的位置。
  • 安装 VS Code、Python 扩展和 Pylance 扩展。
  • 将 pyi 模块文件夹添加到 “python.autoComplete.extraPaths” 和 “python.analysis.extraPaths”Python 扩展的设置中。 配置 VC
  • 以使用 VS Code 作为外部 Python 编辑器。从 VC 打开 Python 脚本,配置 VS Code 信任文件夹路径以启用所有编辑器功能。
  • 在 VS Code 中启用类型检查。
  • 从此处下载文件:

vcApi VC48.zip

(146.6 KB)15 个赞

PythonScrips 中外部库的自动补全

太棒了!我将 vcApi 文件夹解压到了我的 VC 安装目录下的 Python - Commands 文件夹中。我就是这样修改了 Pylance 设置并让它成功运行了。

4 个赞

哇,这真是改变游戏规则的方法,感谢分享!

在尝试了几个小时让这个在我的新机器上运行后,我终于搞定了:slight_smile:

  1. 首先按照主帖中的说明操作。
  2. 如果你懒得看那么多内容,就像@Este评论中描述的那样,把那些东西放到安装文件夹里。
    2a) 我把路径字符串贴在这里,这样你就不需要替换所有的斜杠了:"C:/Program Files/Visual Components/Visual Components Premium 4.8/Python/Commands/vcApi"
  3. 这是我的窍门: 在 Visual Studio Code 中设置工作区,设置一个工作区让自动补全功能开始工作了。我直接选择了我的 C 盘。
**主题:** 关于在 Visual Code 中跟踪 Python 程序执行的问题 **发帖人:** ZF_DJ **时间:** 2024年5月7日 上午7:39 **内容:** 大家好! 非常感谢!这太棒了。 我对 Visual Code 和在 VC 中使用 Python 编程还比较陌生,自动补全功能帮了大忙! 请问在 Visual Code 中是否能够跟踪程序的执行过程? 祝好, Lefa **回复人:** Lefa **时间:** 2024年5月7日 下午12:59 **内容:** 你好, 我不太确定是否可以通过外部编辑器跟踪执行过程,但内置的编辑器是可以做到的。 祝好, Lefa **更新人:** TSy **时间:** 2024年12月11日 下午12:21 **内容:** 已更新以匹配 VC 4.10.0 版本的 Python API。 附件:vcScript VC 410.zip (148.0 KB) 部分 AI 生成的差异摘要: 以下是 **vcApi.pyi** 文件在 4.8 和 4.10 版本之间的主要变化: **新增属性和方法**: - **vcApplication**: (具体新增内容未在摘要中详细列出)

Hi,
thank you! Thats great.
I’m quite new to Visual Code and Python programming in VC and the auto completing helps a lot!

Is it possible to trace the execution in Visual Code?

Hi,

Not sure about tracing the execution using external editor, internal ones can do that though.

br,
Lefa

Updated to match the Python API in VC 4.10.0
vcScript VC 410.zip(148.0 KB)

Partial AI-generated summary from diff:

Here are the key changes in thevcApi.pyifile between versions 4.8 and 4.10:

  • New Properties and Methods:
    • vcApplication:
      • Added**布局可视化设置** **属性:** - **新增** `SimulationWorld` 属性。 **vcBehaviour:** - **新增** 带 getter 和 setter 的 `Visible` 属性。 **vcLayout:** - **新增** 包含以下属性的新类: - `ChildLayouts` - `ParentLayout` - `Visualization` - **新增** 方法: - `Clone` - `MoveChildrenFrom` **vcLayoutVisualization 和 vcLayoutVisualizationSettings:** - **新增** 用于管理布局可视化设置的新类。 **vcLight:** - `deleteLight` 方法现在接受一个 `vcLight` 对象,而不是字符串名称。property.
      • AddedSimulationWorldproperty.
    • vcBehaviour:
      • AddedVisibleproperty with getter and setter.
    • vcLayout:
      • Added new class with propertiesChildLayouts,ParentLayout,Visualization, and methodsCloneandMoveChildrenFrom.
    • vcLayoutVisualizationandvcLayoutVisualizationSettings:
      • Added new classes for managing layout visualization settings.
    • vcLight:
      • deleteLightmethod now takes avcLightobject instead of a string name.
    • vcProcessController: 已更新文档字符串以反映进程管理服务的更改。 vcPythonProcessHandler: 已更新 `condition` 和 `triggerCondition` 方法,使其接受 `Callable[[], None]` 而非 `Callable[[], bool]`。 3 个赞 asirit 2026年2月5日 23:17 8 有人能告诉我如何解决这个 vcApplication 智能感知问题吗? 图片 681×343 26.3 KB TSy 2026年2月6日 06:20 9 我认为导入无法解析是因为在这些 API 文件中,`vcApplication` 并未被定义为一个单独的模块,其类定义位于 `vcScript` 中。 可能需要创建一个单独的 `vcApplication.pyi` 文件。:
      • Updated docstrings to reflect changes in process management services.
    • vcPythonProcessHandler:
      • UpdatedconditionandtriggerConditionmethods to acceptCallable[[], None]instead ofCallable[[], bool].
3 Likes

can someone please show me how to get rid of this vcApplication intellisense issue?

I think the import is not getting resolved becausevcApplicationis not defined as separate module in these API files, the class definition is invcScript.

Would need to make a separatevcApplication.pyi该文件包含静态模块级成员,并且需要一个空文件夹才能实现直接导入。 你或许可以直接在代码中使用 `vcApplication` 前缀,例如 `vcApplication.loadBitmap(…)`。vcApplicationfolder for that direct import to work.

You can probably just use thevcApplicationprefix in your code instead, likevcApplication.loadBitmap(…)