group.ofs 2.95 KB
Newer Older
1
core.clearAll()
Matthias Möller's avatar
Matthias Möller committed
2
3
//Group 20 Objects
for (i=0; i < 20;++i)
4
5
6
{
  primitivesgenerator.addSphere()
}
Matthias Möller's avatar
Matthias Möller committed
7
8
datacontrol.setAllTarget()
var list = datacontrol.getTargetObjects(DataType("TriangleMesh"));
9
10

//Check, if group was created
Matthias Möller's avatar
Matthias Möller committed
11
groupid = datacontrol.groupObjects(list)
12
13
14
15
16
17
if (groupid == -1)
{
  print("unable to create a group with 20 objects")
  core.exitFailure()
}

Matthias Möller's avatar
Matthias Möller committed
18
19
if (datacontrol.groupCount() != 1)
{
Matthias Möller's avatar
Matthias Möller committed
20
  print("Group 20 Objects failed")
21
22
23
24
  print("unexpected group count")
  print("number of groups: " + datacontrol.groupCount())
  print("expected number of groups: 1") 
  core.exitFailure()
Matthias Möller's avatar
Matthias Möller committed
25
26
27
28
29
30
31
32
33
}
datacontrol.clearAllTarget()

//Group Object and Group
id = primitivesgenerator.addSphere()
list = [groupid,id]
datacontrol.groupObjects(list)
if (datacontrol.groupCount() != 2)
{
Matthias Möller's avatar
Matthias Möller committed
34
  print("Group Object and Group failed")
35
36
37
38
  print("unexpected group count")
  print("number of groups: " + datacontrol.groupCount())
  print("expected number of groups: 2") 
  core.exitFailure()
Matthias Möller's avatar
Matthias Möller committed
39
40
41
42
43
44
45
46
47
}
datacontrol.clearAllTarget()

//Group multiple Groups
id = primitivesgenerator.addSphere()
id2 = primitivesgenerator.addSphere()
list = [id2,id]
groupid2 = datacontrol.groupObjects(list)

48
49
if (datacontrol.groupCount() != 3)
{
Matthias Möller's avatar
Matthias Möller committed
50
  print("Group multiple Groups failed")
51
52
53
54
  print("unexpected group count")
  print("number of groups: " + datacontrol.groupCount())
  print("expected number of groups: 3") 
  core.exitFailure()
Matthias Möller's avatar
Matthias Möller committed
55
56
57
58
59
60
61
62
63
64
65
}

//Ungroup
datacontrol.unGroupObject(groupid2)
if (datacontrol.groupCount() != 2)
{
  print("Ungroup failed")
  print("unexpected group count")
  print("number of groups: " + datacontrol.groupCount())
  print("expected number of groups: 2") 
  core.exitFailure()
66
67
68
69
70
71
72
73
74
}

//add object to existing group
core.clearAll()
id1 = primitivesgenerator.addSphere()
id2 = primitivesgenerator.addSphere()
id3 = primitivesgenerator.addSphere()

groupid = datacontrol.groupObjects([id1,id2])
Matthias Möller's avatar
Matthias Möller committed
75
datacontrol.addObjectToGroup(id3,groupid)
76
77
78
79
80
81
82
83
84
85
86

datacontrol.groupObjects([id1,id2,id3])//Can be done, if all objects are in the same group
if (datacontrol.groupCount() != 2)
{
  print("Add to Group failed.")
  print("unexpected group count")
  print("number of groups: " + datacontrol.groupCount())
  print("expected number of groups: 2") 
  core.exitFailure()
}

Matthias Möller's avatar
Matthias Möller committed
87
if (datacontrol.addObjectToGroup(id3,id2))
88
89
90
{
  print("Could add an object to an object which is not a Group.")
  core.exitFailure();
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
}

//Get group elements
id1 = primitivesgenerator.addSphere()
id2 = primitivesgenerator.addSphere()
elements = [id1,id2]
groupid = datacontrol.groupObjects(elements)
resuldList = datacontrol.getGroupElements(groupid)

if (resuldList.length != elements.length)
{
  print("error: getGroupElements")
  print("number of received elements is: "+elements.length+" expected was: "+resuldList.length)
  core.exitFailure();
}
for (i = 0; i < resultId; ++i)
{
   if (resuldList[i] != groupId[i])
  {
    print("error: getGroupElements")
    print("id of received object differs")
    print("expected was: "+groupId[i]+" result is: "+resuldIdList[i])
    core.exitFailure();
  }
}