我正在尝试创建一个脚本,该脚本将选择对象属性“便利性”等于“学校”的所有对象。有些人可以帮我确定以下代码有什么问题吗?

 

from scripting import *

# get a CityEngine instance
ce = CE()

def selectByAttribute(attr, value):
    objects = ce.getObjectsFrom(ce.scene)
    selection = []
    
    for item in objects:
        attribute = ce.getAttribute(item, attr)
        if attribute == value:
                selection.append(item)
        
    ce.setSelection(selection)

if __name__ == '__main__':
    selectByAttribute("/ce/geometry/amenity", "school")



For object attributes you don’t need any prefix just write selectByAttribute(“amenity”, “school”) and your script should work.

I suggest two other small improvements to your script:

  • Add @noUIupdate before your function. This makes sure the UI will be refreshed only after the function is run through. Depending on the size of the scene and what your function does this can speed up the run significantly
  • In your case you don’t need to query all objects from the scene, you can limit it to shapes only if you write objects = ce.getObjectsFrom(ce.scene, ce.isShape)

对于对象属性,您不需要任何前缀,只需编写 selectByAttribute(“便利设施”、“学校”),您的脚本应该可以工作。

我建议对脚本进行另外两个小改进:

  • 在函数之前添加@noUIupdate。这可确保仅在函数运行后刷新 UI。根据场景的大小和函数的作用,这可以显着加快运行速度
  • 在您的情况下,您不需要查询场景中的所有对象,仅当您编写对象 = ce.getObjectsFrom(ce.scene, ce.isShape) 时,您才能将其限制为形状

本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。

最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。 若排除这种情况,可在对应资源底部留言,或联络我们。

对于会员专享、资源素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。

如果您已经成功付款但是网站没有弹出成功提示,请联系站长提供付款信息为您处理

资源属于虚拟商品,具有可复制性,可传播性,一旦授予,不接受任何形式的退款、换货要求。请您在购买获取之前确认好 是您所需要的资源