【Python工具开发】k3q_arxml 简单但是非常好用的arxml编辑器,可以称为arxml杀手包

k3q_arxml

介绍

仓库地址1
仓库地址2

极简的arxml编辑库,纯python实现

用法

python 复制代码
from pprint import pp # 可以美化打印对象,不然全打印在一行
import k3q_arxml
# 加载arxml文件
io_arxml = k3q_arxml.IOArxml(filepaths=['test/model_merge.arxml'])

# 打印arxml字符串绑定的python arxml实例
io_arxml.print(print_filepath='model_merge.txt')

# 刷新ref缓存数据,因为ref/ar/ref_to_ref/locate_filename访问的都是缓存数据,如果修改了数据后,影响到了ref,就需要主动刷新
io_arxml.scan_ref()

# 增/改
io_arxml.ref(('Implementations', 'HWIO')).resource_consumption = k3q_arxml.autosar.ResourceConsumption(
    short_name=k3q_arxml.autosar.Identifier(value='resourceConsumption'))

# 删
del io_arxml.ref(('Implementations', 'HWIO')).resource_consumption
io_arxml.ref(('Implementations', 'HWIO')).resource_consumption = None

# 查
## 根据ref查arxml实例
io_arxml.ref(('Implementations', 'HWIO'))
## 根据ref查哪些arxml实例用到了该ref
io_arxml.ref_to_ref(('Implementations', 'HWIO'))
## 根据标签查arxml实例(该需要带有short_name属性)
io_arxml.ar(clazz=k3q_arxml.autosar.ResourceConsumption)
## 根据标签查arxml实例,但限定ref路径下查找(该需要带有short_name属性)
io_arxml.ar(clazz=k3q_arxml.autosar.ResourceConsumption, ref_prefix=('Implementations',))

# 辅助函数
## 控制台打印uuid到ref的映射关系,能通过uuid快速定位ref路径,辅助编码
io_arxml.scan_ref(debug_uuid=True)
## 获取路径在那个arxml文件里
io_arxml.locate_filename(ref=('Implementations',))

# 切换autosar_00052版本,默认为autosar_00048
from autosar import autosar_00052
k3q_arxml.autosar = autosar_00052

# 回写到文件
io_arxml.flush_to_file()

技巧

  1. 手动添加完成后的arxml和原始arxml,都通过io_arxml.print函数打印在文件里
  2. 通过对比软件对比源arxml和打印的arxml,找出需要修改的arxml内容
  3. 该内容就是对象的定义代码,可以复制出来粘贴到代码里
相关推荐
土豆.exe5 分钟前
IfAI v0.3.0 - 从“文本“到“多模态“的感知升级
人工智能·编辑器
无限进步_17 分钟前
【C语言&数据结构】二叉树遍历:从前序构建到中序输出
c语言·开发语言·数据结构·c++·算法·github·visual studio
ai_top_trends42 分钟前
不同 AI 生成 2026 年工作计划 PPT 的使用门槛对比
人工智能·python·powerpoint
花北城1 小时前
【C#】MES消耗类数量逻辑处理(物料消耗、打包装箱、生产订单派工等)
开发语言·c#
半夏知半秋1 小时前
kcp学习-skynet中的kcp绑定
开发语言·笔记·后端·学习
扶苏-su1 小时前
Java--标准输入输出流
java·开发语言
adayabetter1 小时前
Python自动化办公提效相关脚本
python·自动化·自动化脚本
奋斗的小青年!!1 小时前
Flutter跨平台开发OpenHarmony应用:个人中心实现
开发语言·前端·flutter·harmonyos·鸿蒙
石头wang2 小时前
jmeter java.lang.OutOfMemoryError: Java heap space 修改内存大小,指定自己的JDK
java·开发语言·jmeter
二狗哈2 小时前
czsc入门8:Signal信号
python·量化·czsc