我对Sketchup和ruby非常陌生,我曾经使用过java和c#,但这是第一次使用ruby。
现在我有一个问题,我需要在一个json中序列化所有的场景(场景层次,对象名称,对象材质和单个对象的位置)我该怎么做呢?
我已经为unity3D (c#)这样做了,没有任何问题。
我试过这个:
def main
avr_entities = Sketchup.active_model.entities # all objects
ambiens_dictionary = {}
ambiens_list = []
avr_entities.each do |root|
if root.is_a?(Sketchup::Group) || root.is_a?(Sketchup::ComponentInstance)
if root.name == ""
UI.messagebox("this is a group #{root.definition.name}")
if root.entities.count > 0
root.entities.each do |leaf|
if leaf.is_a?(Sketchup::Group) || leaf.is_a?(Sketchup::ComponentInstance)
UI.messagebox("this is a leaf #{leaf.definition.name}")
end
end
end
else
# UI.messagebox("this is a leaf #{root.name}")
end
end
end
end发布于 2017-08-02 18:57:42
你试过JSON library吗?
require 'json'
source = { a: [ { b: "hello" }, 1, "world" ], c: 'hi' }.to_json
source.to_json # => "{\"a\":[{\"b\":\"hello\"},1,\"world\"],\"c\":\"hi\"}"https://stackoverflow.com/questions/45456507
复制相似问题