python - 在蚱蜢中重新编号路径时,如何修复已存在具有相同键的条目?
问题描述
在蚱蜢中编码以尝试将我的树枝从 {0}、{1}、...重新编号为分支 {230}、{234}、...的差异索引。只有第一棵树的命名更规则,第二棵树来自一棵更大的树,我选择了这些树枝,因为我需要操纵它们。但是,在操作它们时,我必须将分支索引从 {230}、{234} .... 更改为以零开头的索引,以匹配传入数据的索引。结果,我尝试在 python 中操作我的数据以反转之前所做的操作。
我在 python 中尝试了一个代码,接收我需要的分支索引并根据 Rhino/Grasshopper 语法输出修改后的索引
import rhinoscriptsyntax as rs
for i in x:
a = y.RenumberPaths("%s" %i)
具有操纵分支索引的数据树的预期输出。错误:运行时错误 (ArgumentException):已存在具有相同键的条目。
回溯:第 13 行,在脚本中
第 13 行只是说a = y.Renumber...
解决方案
我不熟悉 python API,但在 C# 中我会做类似的事情:
// inputDataTree is the tree you want to renumber, ideally you would change
// the DataTree<object> for your data type such as DataTree<Curve> or whatever.
DataTree<object> dataTree = new DataTree<object>();
for( int i = 0; i < inputDataTree.BranchCount; ++i )
{
GH_Path path = new GH_Path(i);
for( int j = 0; j < inputDataTree.Branch(i).Count; ++j )
{
// If you don't need the j index, you could compute the
// path in the outer loop. You can add logic to how you
// create branches.
// GH_Path path = new GH_Path(i, j);
dataTree.Add( inputDataTree.Branch(i)[j], path );
}
}
推荐阅读
- c# - asp.net C# gridview 分页禁用其他按钮
- git - 我可以在不更改本地存储库内容的情况下从目标分支切换到本地 master 吗?
- ide - 在 html 元素中搜索和替换文本
- dbt - 如何使用日志错误 FileNotFound 运行 dbt 以触发不为 0 的退出代码?
- sql-server - 根据记录之间的分钟数在 SQL 中递归地分组记录
- youtube - 嵌入包含所有数据的 youtube 视频,如 youtube 网站
- r - 相对于每个点,按时间和位置窗口重复有效地过滤大型数据集
- javascript - Javascript Keydown 事件处理程序无法正常工作
- c# - NReco 为每一帧设置不同的持续时间
- javascript - 如何在 Angular 中将大型 JSON 数据导出到 Excel?