← Back to team overview

yade-users team mailing list archive

Re: [Question #706786]: Can I add properties and color into export text file?

 

Question #706786 on Yade changed:
https://answers.launchpad.net/yade/+question/706786

Jan Stránský posted a new comment:
Hello,

> ##My Code##

please try to use MWE [1], M = minimal.
For this case, a few "hardcoded" spheres is enough for the export / import purposes (see below what I mean)

Option 1:
it is python script, so you can "manually" export anything anyhow you like.

Option2:
using yade's predefined export.textExt function [2]:
###
from yade import export
mat1 = FrictMat(label="mat1")
mat2 = FrictMat(label="mat2")
mat1id = O.materials.append(mat1)
mat2id = O.materials.append(mat2)
s1 = sphere((0,0,0),1,material=mat1,color=(0.9,0.2,0.1))
s2 = sphere((2,0,0),1,material=mat2,color=(0.3,0.4,0.8))
O.bodies.append([s1,s2])
export.textExt("test.txt",format="x_y_z_r_attrs",comment="color_r color_g color_b mat_id",attrs=["b.shape.color","b.mat.id"])
# note: b.shape.color "vector" is split into 3 numbers
###

For import you can use ymport.textExt [3]:
###
from yade import ymport
attrs = []
spheres = ymport.textExt("test.txt",format="x_y_z_r_attrs",attrs=attrs)
print(spheres)
print(attrs)
###

Cheers
Jan

[1] https://www.yade-dem.org/wiki/Howtoask
[2] https://yade-dem.org/doc/yade.export.html#yade.export.textExt
[3] https://yade-dem.org/doc/yade.ymport.html#yade.ymport.textExt

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.