Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Armature.c « api2_2x « python « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bae9b1b0db412119d8b95d74450cbf302b91afd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
/*
 * $Id$
 *
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version. The Blender
 * Foundation also sells licenses for use in proprietary software under
 * the Blender License.  See http://www.blender.org/BL/ for information
 * about this.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 * All rights reserved.
 *
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
*/

#include "Armature.h" //This must come first

#include "BKE_main.h"
#include "BKE_global.h"
#include "BKE_armature.h"
#include "BKE_library.h"
#include "BKE_depsgraph.h"
#include "BKE_utildefines.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "MEM_guardedalloc.h"
#include "Bone.h"
#include "NLA.h"
#include "gen_utils.h"

#include "DNA_object_types.h" //This must come before BIF_editarmature.h...
#include "BIF_editarmature.h"

//------------------EXTERNAL PROTOTYPES--------------------
extern void make_boneList(ListBase* list, ListBase *bones, EditBone *parent);
extern void editbones_to_armature (ListBase *list, Object *ob);

//------------------------ERROR CODES---------------------------------
//This is here just to make me happy and to have more consistant error strings :)
static const char sBoneDictError[] = "ArmatureType.bones - Error: ";
static const char sBoneDictBadArgs[] = "ArmatureType.bones - Bad Arguments: ";
static const char sArmatureError[] = "ArmatureType - Error: ";
static const char sArmatureBadArgs[] = "ArmatureType - Bad Arguments: ";
static const char sModuleError[] = "Blender.Armature - Error: ";
static const char sModuleBadArgs[] = "Blender.Armature - Bad Arguments: ";

//################## BonesDict_Type (internal) ########################
/*This is an internal psuedo-dictionary type that allows for manipulation
* of bones inside of an armature. It is a subobject of armature.
* i.e. Armature.bones['key']*/
//#####################################################################

//------------------METHOD IMPLEMENTATIONS-----------------------------
//------------------------Armature.bones.items()
//Returns a list of key:value pairs like dict.items()
static PyObject* BonesDict_items(BPy_BonesDict *self)
{
	if (self->editmode_flag){
		return PyDict_Items(self->editbonesMap); 
	}else{
		return PyDict_Items(self->bonesMap); 
	}
}
//------------------------Armature.bones.keys()
//Returns a list of keys like dict.keys()
static PyObject* BonesDict_keys(BPy_BonesDict *self)
{
	if (self->editmode_flag){
		return PyDict_Keys(self->editbonesMap);
	}else{
		return PyDict_Keys(self->bonesMap);
	}
}
//------------------------Armature.bones.values()
//Returns a list of values like dict.values()
static PyObject* BonesDict_values(BPy_BonesDict *self)
{
	if (self->editmode_flag){
		return PyDict_Values(self->editbonesMap);
	}else{
		return PyDict_Values(self->bonesMap);
	}
}
//------------------ATTRIBUTE IMPLEMENTATION---------------------------
//------------------TYPE_OBECT IMPLEMENTATION-----------------------
//------------------------tp_doc
//The __doc__ string for this object
static char BPy_BonesDict_doc[] = "This is an internal subobject of armature\
designed to act as a Py_Bone dictionary.";

//------------------------tp_methods
//This contains a list of all methods the object contains
static PyMethodDef BPy_BonesDict_methods[] = {
	{"items", (PyCFunction) BonesDict_items, METH_NOARGS, 
		"() - Returns the key:value pairs from the dictionary"},
	{"keys", (PyCFunction) BonesDict_keys, METH_NOARGS, 
		"() - Returns the keys the dictionary"},
	{"values", (PyCFunction) BonesDict_values, METH_NOARGS, 
		"() - Returns the values from the dictionary"},
	{NULL, NULL, 0, NULL}
};
//-----------------(internal)
static int BoneMapping_Init(PyObject *dictionary, ListBase *bones){
	Bone *bone = NULL;
	PyObject *py_bone = NULL;

	for (bone = bones->first; bone; bone = bone->next){
		py_bone = PyBone_FromBone(bone);
		if (!py_bone)
			return -1;

		if(PyDict_SetItem(dictionary, 
			PyString_FromString(bone->name), py_bone) == -1){
			return -1;
		}
		Py_DECREF(py_bone);
		if (bone->childbase.first) 
			BoneMapping_Init(dictionary, &bone->childbase);
	}
	return 0;
}
//-----------------(internal)
static int EditBoneMapping_Init(PyObject *dictionary, ListBase *editbones){
	EditBone *editbone = NULL;
	PyObject *py_editbone = NULL;

	for (editbone = editbones->first; editbone; editbone = editbone->next){
		py_editbone = PyEditBone_FromEditBone(editbone);
		if (!py_editbone)
			return -1;

		if(PyDict_SetItem(dictionary, 
			PyString_FromString(editbone->name), py_editbone) == -1){
			return -1;
		}
		Py_DECREF(py_editbone);
	}
	return 0;
}
//----------------- BonesDict_InitBones
static int BonesDict_InitBones(BPy_BonesDict *self)
{
	PyDict_Clear(self->bonesMap);
	if (BoneMapping_Init(self->bonesMap, self->bones) == -1)
		return 0;
	return 1;
} 
//----------------- BonesDict_InitEditBones
static int BonesDict_InitEditBones(BPy_BonesDict *self)
{
	PyDict_Clear(self->editbonesMap);
	if (EditBoneMapping_Init(self->editbonesMap, &self->editbones) == -1)
		return 0;
	return 1;
}
//------------------------tp_repr
//This is the string representation of the object
static PyObject *BonesDict_repr(BPy_BonesDict *self)
{
	char str[2048];
	PyObject *key, *value;
	int pos = 0;
	char *p = str;
	char *keys, *vals;

	p += sprintf(str, "[Bone Dict: {");

	if (self->editmode_flag){
		while (PyDict_Next(self->editbonesMap, &pos, &key, &value)) {
			keys = PyString_AsString(key);
			vals = PyString_AsString(value->ob_type->tp_repr(value));
			if( strlen(str) + strlen(keys) + strlen(vals) < sizeof(str)-20 )
				p += sprintf(p, "%s : %s, ", keys, vals );
			else {
				p += sprintf(p, "...." );
				break;
			}
		}
	}else{
		while (PyDict_Next(self->bonesMap, &pos, &key, &value)) {
			keys = PyString_AsString(key);
			vals = PyString_AsString(value->ob_type->tp_repr(value));
			if( strlen(str) + strlen(keys) + strlen(vals) < sizeof(str)-20 )
				p += sprintf(p, "%s : %s, ", keys, vals );
			else {
				p += sprintf(p, "...." );
				break;
			}
		}
	}
	sprintf(p, "}]");
	return PyString_FromString(str);
}

//------------------------tp_dealloc
//This tells how to 'tear-down' our object when ref count hits 0
static void BonesDict_dealloc(BPy_BonesDict * self)
{
	Py_DECREF(self->bonesMap);
	Py_DECREF(self->editbonesMap);
	BLI_freelistN(&self->editbones); 
	BonesDict_Type.tp_free(self);
	return;
}
//------------------------mp_length
//This gets the size of the dictionary
static int BonesDict_len(BPy_BonesDict *self)
{
	if (self->editmode_flag){
		return BLI_countlist(&self->editbones);
	}else{
		return BLI_countlist(self->bones);
	}
}
//-----------------------mp_subscript
//This defines getting a bone from the dictionary - x = Bones['key']
static PyObject *BonesDict_GetItem(BPy_BonesDict *self, PyObject* key)
{ 
	PyObject *value = NULL;

	if (self->editmode_flag){
		value = PyDict_GetItem(self->editbonesMap, key);
	}else{
		value = PyDict_GetItem(self->bonesMap, key);
	}
	if(value == NULL){  /* item not found in dict. throw exception */
		char buffer[128];
		char* key_str;
		key_str = PyString_AsString( key );
		if( !key_str ){  /* key not a py string */
			key_str = "";  /* use empty string for printing */
		}
  
		PyOS_snprintf( buffer, sizeof(buffer),
					   "bone %s not found", key_str);
			
        return EXPP_ReturnPyObjError(PyExc_KeyError, buffer );
	}
	return EXPP_incr_ret(value);
}
//-----------------------mp_ass_subscript
//This does dict assignment - Bones['key'] = value
static int BonesDict_SetItem(BPy_BonesDict *self, PyObject *key, PyObject *value)
{
	BPy_EditBone *editbone_for_deletion;
	struct EditBone *editbone = NULL;
	char *key_str = "";

	if (self->editmode_flag){
		//Get the key name
		if(key && PyString_Check(key)){
			key_str = PyString_AsString(key);
		}else{
			goto AttributeError;
		}
		//parse value for assignment
		if (value && EditBoneObject_Check(value)){
			//create a new editbone
			editbone = MEM_callocN(sizeof(EditBone), "eBone");
			BLI_strncpy(editbone->name, key_str, 32);
			unique_editbone_name(editbone->name);
			editbone->dist = ((BPy_EditBone*)value)->dist;
			editbone->ease1 = ((BPy_EditBone*)value)->ease1;
			editbone->ease2 = ((BPy_EditBone*)value)->ease2;
			editbone->flag = ((BPy_EditBone*)value)->flag;
			editbone->parent = ((BPy_EditBone*)value)->parent;
			editbone->rad_head = ((BPy_EditBone*)value)->rad_head;
			editbone->rad_tail = ((BPy_EditBone*)value)->rad_tail;
			editbone->roll = ((BPy_EditBone*)value)->roll;
			editbone->segments = ((BPy_EditBone*)value)->segments;
			editbone->weight = ((BPy_EditBone*)value)->weight;
			editbone->xwidth = ((BPy_EditBone*)value)->xwidth;
			editbone->zwidth = ((BPy_EditBone*)value)->zwidth;
			VECCOPY(editbone->head, ((BPy_EditBone*)value)->head);
			VECCOPY(editbone->tail, ((BPy_EditBone*)value)->tail);
			
			// FIXME, should be exposed via python. this avoids creating bones with no layers.
			editbone->layer= 1;
			
			//set object pointer
			((BPy_EditBone*)value)->editbone = editbone;

			//fix the bone's head position if flags indicate that it is 'connected'
			if (editbone->flag & BONE_CONNECTED){
				if(!editbone->parent){
					((BPy_EditBone*)value)->editbone = NULL;
					MEM_freeN(editbone);
					goto AttributeError3;
				}else{
					VECCOPY(editbone->head, editbone->parent->tail);
				}
			}

			//set in editbonelist
			BLI_addtail(&self->editbones, editbone);

			//set the new editbone in the mapping
			if(PyDict_SetItemString(self->editbonesMap, key_str, value) == -1){
				((BPy_EditBone*)value)->editbone = NULL;
				BLI_freelinkN(&self->editbones, editbone);
				goto RuntimeError;
			}
		}else if(!value){
			//they are trying to delete the bone using 'del'
			if(PyDict_GetItem(self->editbonesMap, key) != NULL){
				/*first kill the datastruct then remove the item from the dict
				and wait for GC to pick it up.
				We have to delete the datastruct here because the tp_dealloc
				doesn't handle it*/
				editbone_for_deletion = (BPy_EditBone*)PyDict_GetItem(self->editbonesMap, key);
				/*this is ugly but you have to set the parent to NULL for else 
				editbones_to_armature will crash looking for this bone*/
				for (editbone = self->editbones.first; editbone; editbone = editbone->next){
					if (editbone->parent == editbone_for_deletion->editbone)
						editbone->parent = NULL;
					    /*any parent's were connected to this we must remove the flag
					    or else the 'root' ball doesn't get draw*/
					    if (editbone->flag & BONE_CONNECTED)
							editbone->flag &= ~BONE_CONNECTED;
				}
				BLI_freelinkN(&self->editbones, editbone_for_deletion->editbone);
				if(PyDict_DelItem(self->editbonesMap, key) == -1)
					goto RuntimeError;
			}else{
				goto KeyError;
			}
		}
		return 0;
	}else{
		goto AttributeError2;
	}

KeyError:
return EXPP_intError(PyExc_KeyError, "%s%s%s%s", 
	    sBoneDictError,  "The key: ", key_str, " is not present in this dictionary!");
RuntimeError:
	return EXPP_intError(PyExc_RuntimeError, "%s%s", 
		sBoneDictError,  "Unable to access dictionary!");
AttributeError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sBoneDictBadArgs,  "Expects EditboneType Object");
AttributeError2:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sBoneDictBadArgs,  "You must call makeEditable() first");
AttributeError3:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sBoneDictBadArgs,  "The 'connected' flag is set but the bone has no parent!");
}
//------------------TYPE_OBJECT DEFINITION--------------------------
//Mapping Protocol
static PyMappingMethods BonesDict_MapMethods = {
	(inquiry) BonesDict_len,					//mp_length
	(binaryfunc)BonesDict_GetItem,		//mp_subscript
	(objobjargproc)BonesDict_SetItem,	//mp_ass_subscript
};
//BonesDict TypeObject
PyTypeObject BonesDict_Type = {
	PyObject_HEAD_INIT(NULL)			//tp_head
	0,												//tp_internal
	"BonesDict",								//tp_name
	sizeof(BPy_BonesDict),					//tp_basicsize
	0,												//tp_itemsize
	(destructor)BonesDict_dealloc,		//tp_dealloc
	0,												//tp_print
	0,												//tp_getattr
	0,												//tp_setattr
	0,												//tp_compare
	(reprfunc) BonesDict_repr,				//tp_repr
	0,												//tp_as_number
	0,												//tp_as_sequence
	&BonesDict_MapMethods,				//tp_as_mapping
	0,												//tp_hash
	0,												//tp_call
	0,												//tp_str
	0,												//tp_getattro
	0,												//tp_setattro
	0,												//tp_as_buffer
	Py_TPFLAGS_DEFAULT,					//tp_flags
	BPy_BonesDict_doc,						//tp_doc
	0,												//tp_traverse
	0,												//tp_clear
	0,												//tp_richcompare
	0,												//tp_weaklistoffset
	0,												//tp_iter
	0,												//tp_iternext
	BPy_BonesDict_methods,				//tp_methods
	0,												//tp_members
	0,												//tp_getset
	0,												//tp_base
	0,												//tp_dict
	0,												//tp_descr_get
	0,												//tp_descr_set
	0,												//tp_dictoffset
	0, 				                                //tp_init
	0,												//tp_alloc
	0,												//tp_new
	0,												//tp_free
	0,												//tp_is_gc
	0,												//tp_bases
	0,												//tp_mro
	0,												//tp_cache
	0,												//tp_subclasses
	0,												//tp_weaklist
	0												//tp_del
};
//-----------------------PyBonesDict_FromPyArmature
static PyObject *PyBonesDict_FromPyArmature(BPy_Armature *py_armature)
{
	BPy_BonesDict *py_BonesDict = NULL;

	//create py object
	py_BonesDict = (BPy_BonesDict *)BonesDict_Type.tp_alloc(&BonesDict_Type, 0); 
	if (!py_BonesDict)
		goto RuntimeError;

	//create internal dictionaries
	py_BonesDict->bonesMap = PyDict_New();
	py_BonesDict->editbonesMap = PyDict_New();
	if (!py_BonesDict->bonesMap || !py_BonesDict->editbonesMap)
		goto RuntimeError;

	//set listbase pointer
	py_BonesDict->bones = &py_armature->armature->bonebase;

	//now that everything is setup - init the mappings
	if (!BonesDict_InitBones(py_BonesDict))
		goto RuntimeError;
	if (!BonesDict_InitEditBones(py_BonesDict))
		goto RuntimeError;

	//set editmode flag
	py_BonesDict->editmode_flag = 0; 

	return (PyObject*)py_BonesDict;

RuntimeError:
	return EXPP_objError(PyExc_RuntimeError, "%s%s", 
		sBoneDictError, "Failed to create class");
}

//######################### Armature_Type #############################
/*This type represents a thin wrapper around bArmature data types
* internal to blender. It contains the psuedo-dictionary BonesDict
* as an assistant in manipulating it's own bone collection*/
//#################################################################

//------------------METHOD IMPLEMENTATION------------------------------
//------------------------Armature.makeEditable()
static PyObject *Armature_makeEditable(BPy_Armature *self)
{
	if (self->armature->flag & ARM_EDITMODE)
		goto AttributeError;

	make_boneList(&self->Bones->editbones, self->Bones->bones, NULL);
	if (!BonesDict_InitEditBones(self->Bones))
		return NULL;
	self->Bones->editmode_flag = 1;
	return EXPP_incr_ret(Py_None);

AttributeError:
	return EXPP_objError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "The armature cannot be placed manually in editmode before you call makeEditable()!");
}
//------------------------Armature.update()
//This is a bit ugly because you need an object link to do this
static PyObject *Armature_update(BPy_Armature *self)
{
	Object *obj = NULL;

	for (obj = G.main->object.first; obj; obj = obj->id.next){
		if (obj->data == self->armature)
			break;
	}
	if (obj){
		editbones_to_armature (&self->Bones->editbones, obj);
		if (!BonesDict_InitBones(self->Bones))
			return NULL;
		self->Bones->editmode_flag = 0;
		BLI_freelistN(&self->Bones->editbones);
	}else{
		goto AttributeError;

	}
	return EXPP_incr_ret(Py_None);

AttributeError:
	return EXPP_objError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "The armature must be linked to an object before you can save changes!");
}
//------------------ATTRIBUTE IMPLEMENTATION---------------------------
//------------------------Armature.autoIK (getter)
static PyObject *Armature_getAutoIK(BPy_Armature *self, void *closure)
{
	if (self->armature->flag & ARM_AUTO_IK)
		return EXPP_incr_ret(Py_True);
	else
		return EXPP_incr_ret(Py_False);
}
//------------------------Armature.autoIK (setter)
static int Armature_setAutoIK(BPy_Armature *self, PyObject *value, void *closure)
{
	if(value){
		if(PyBool_Check(value)){
			if (value == Py_True){
				self->armature->flag |= ARM_AUTO_IK;
				return 0;
			}else if (value == Py_False){
				self->armature->flag &= ~ARM_AUTO_IK;
				return 0;
			}
		}
	}
	goto AttributeError;

AttributeError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "Expects True or False");
}
//------------------------Armature.layers (getter)
static PyObject *Armature_getLayers(BPy_Armature *self, void *closure)
{
	int layers, bit = 0, val = 0;
	PyObject *item = NULL, *laylist = PyList_New( 0 );

	if( !laylist )
		return EXPP_ReturnPyObjError( PyExc_MemoryError,
			"couldn't create pylist!" );

	layers = self->armature->layer;

	while( bit < 20 ) {
		val = 1 << bit;
		if( layers & val ) {
			item = Py_BuildValue( "i", bit + 1 );
			PyList_Append( laylist, item );
			Py_DECREF( item );
		}
		bit++;
	}
	return laylist;
}
//------------------------Armature.layer (setter)
static int Armature_setLayers(BPy_Armature *self, PyObject *value, void *closure)
{
	if(value){
		if(PyList_Check(value)){
			int layers = 0, len_list = 0;
			int val;
			PyObject *item = NULL;

			len_list = PyList_Size(value);

			if( len_list == 0 )
				return EXPP_ReturnIntError( PyExc_AttributeError,
				  "list can't be empty, at least one layer must be set" );

			while( len_list ) {
				--len_list;
				item = PyList_GetItem( value, len_list );
				if( !PyInt_Check( item ) )
					return EXPP_ReturnIntError( PyExc_AttributeError,
							"list must contain only integer numbers" );

				val = ( int ) PyInt_AsLong( item );
				if( val < 1 || val > 20 )
					return EXPP_ReturnIntError( PyExc_AttributeError,
						  "layer values must be in the range [1, 20]" );

				layers |= 1 << ( val - 1 );
			}

			/* update any bases pointing to our object */
			self->armature->layer = (short)layers;

			return 0;
		}
	}
	goto AttributeError;

AttributeError:
	return EXPP_ReturnIntError( PyExc_TypeError,
			"expected a list of integers" );
}
//------------------------Armature.mirrorEdit (getter)
static PyObject *Armature_getMirrorEdit(BPy_Armature *self, void *closure)
{
	if (self->armature->flag & ARM_MIRROR_EDIT)
		return EXPP_incr_ret(Py_True);
	else
		return EXPP_incr_ret(Py_False);
}
//------------------------Armature.mirrorEdit (setter)
static int Armature_setMirrorEdit(BPy_Armature *self, PyObject *value, void *closure)
{
	if(value){
		if(PyBool_Check(value)){
			if (value == Py_True){
				self->armature->flag |= ARM_MIRROR_EDIT;
				return 0;
			}else if (value == Py_False){
				self->armature->flag &= ~ARM_MIRROR_EDIT;
				return 0;
			}
		}
	}
	goto AttributeError;

AttributeError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "Expects True or False");
}
//------------------------Armature.drawType (getter)
static PyObject *Armature_getDrawType(BPy_Armature *self, void *closure)
{
	if (self->armature->drawtype == ARM_OCTA){
		return EXPP_GetModuleConstant("Blender.Armature", "OCTAHEDRON") ;
	}else if (self->armature->drawtype == ARM_LINE){
		return EXPP_GetModuleConstant("Blender.Armature", "STICK") ;
	}else if (self->armature->drawtype == ARM_B_BONE){
		return EXPP_GetModuleConstant("Blender.Armature", "BBONE") ;
	}else if (self->armature->drawtype == ARM_ENVELOPE){
		return EXPP_GetModuleConstant("Blender.Armature", "ENVELOPE") ;
	}else{
		goto RuntimeError;
	}

RuntimeError:
	return EXPP_objError(PyExc_RuntimeError, "%s%s%s", 
		sArmatureError, "drawType: ", "Internal failure!");
}
//------------------------Armature.drawType (setter)
static int Armature_setDrawType(BPy_Armature *self, PyObject *value, void *closure)
{
	PyObject *val = NULL, *name = NULL;
	long numeric_value;

	if(value){
		if(BPy_Constant_Check(value)){
			name = PyDict_GetItemString(((BPy_constant*)value)->dict, "name");
			if (!STREQ2(PyString_AsString(name), "OCTAHEDRON", "STICK") &&
				!STREQ2(PyString_AsString(name), "BBONE", "ENVELOPE"))
				goto ValueError;
			val = PyDict_GetItemString(((BPy_constant*)value)->dict, "value");
			if (PyInt_Check(val)){
				numeric_value = PyInt_AS_LONG(val);
				self->armature->drawtype = (int)numeric_value;
				return 0;
			}
		}
	}
	goto AttributeError;

AttributeError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "Expects module constant");

ValueError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "Argument must be the constant OCTAHEDRON, STICK, BBONE, or ENVELOPE");
}
//------------------------Armature.ghostStep (getter)
static PyObject *Armature_getStep(BPy_Armature *self, void *closure)
{
	return PyInt_FromLong((long)self->armature->ghostsize);
}
//------------------------Armature.ghostStep (setter)
static int Armature_setStep(BPy_Armature *self, PyObject *value, void *closure)
{
	long numerical_value;

	if(value){
		if(PyInt_Check(value)){
			numerical_value = PyInt_AS_LONG(value);
			if (numerical_value > 20.0f || numerical_value < 1.0f)
				goto ValueError;
			self->armature->ghostsize = (short)numerical_value;
			return 0;
		}
	}
	goto AttributeError;

AttributeError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "Expects Integer");

ValueError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "Argument must fall within 1-20");
}
//------------------------Armature.ghost (getter)
static PyObject *Armature_getGhost(BPy_Armature *self, void *closure)
{
	return PyInt_FromLong((long)self->armature->ghostep);
}
//------------------------Armature.ghost (setter)
static int Armature_setGhost(BPy_Armature *self, PyObject *value, void *closure)
{
	long numerical_value;

	if(value){
		if(PyInt_Check(value)){
			numerical_value = PyInt_AS_LONG(value);
			if (numerical_value > 30.0f || numerical_value < 0.0f)
				goto ValueError;
			self->armature->ghostep = (short)numerical_value;
			return 0;
		}
	}
	goto AttributeError;

AttributeError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "Expects Integer");

ValueError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "Argument must fall within 0-30");
}
//------------------------Armature.drawNames (getter)
static PyObject *Armature_getDrawNames(BPy_Armature *self, void *closure)
{
	if (self->armature->flag & ARM_DRAWNAMES)
		return EXPP_incr_ret(Py_True);
	else
		return EXPP_incr_ret(Py_False);
}
//------------------------Armature.drawNames (setter)
static int Armature_setDrawNames(BPy_Armature *self, PyObject *value, void *closure)
{
	if(value){
		if(PyBool_Check(value)){
			if (value == Py_True){
				self->armature->flag |= ARM_DRAWNAMES;
				return 0;
			}else if (value == Py_False){
				self->armature->flag &= ~ARM_DRAWNAMES;
				return 0;
			}
		}
	}
	goto AttributeError;

AttributeError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "Expects True or False");
}
//------------------------Armature.drawAxes (getter)
static PyObject *Armature_getDrawAxes(BPy_Armature *self, void *closure)
{
	if (self->armature->flag & ARM_DRAWAXES)
		return EXPP_incr_ret(Py_True);
	else
		return EXPP_incr_ret(Py_False);
}
//------------------------Armature.drawAxes (setter)
static int Armature_setDrawAxes(BPy_Armature *self, PyObject *value, void *closure)
{
	if(value){
		if(PyBool_Check(value)){
			if (value == Py_True){
				self->armature->flag |= ARM_DRAWAXES;
				return 0;
			}else if (value == Py_False){
				self->armature->flag &= ~ARM_DRAWAXES;
				return 0;
			}
		}
	}
	goto AttributeError;

AttributeError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "Expects True or False");
}
//------------------------Armature.delayDeform (getter)
static PyObject *Armature_getDelayDeform(BPy_Armature *self, void *closure)
{
	if (self->armature->flag & ARM_DELAYDEFORM)
		return EXPP_incr_ret(Py_True);
	else
		return EXPP_incr_ret(Py_False);
}
//------------------------Armature.delayDeform (setter)
static int Armature_setDelayDeform(BPy_Armature *self, PyObject *value, void *closure)
{
	if(value){
		if(PyBool_Check(value)){
			if (value == Py_True){
				self->armature->flag |= ARM_DELAYDEFORM;
				return 0;
			}else if (value == Py_False){
				self->armature->flag &= ~ARM_DELAYDEFORM;
				return 0;
			}
		}
	}
	goto AttributeError;

AttributeError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "Expects True or False");
}
//------------------------Armature.restPosition (getter)
static PyObject *Armature_getRestPosition(BPy_Armature *self, void *closure)
{
	if (self->armature->flag & ARM_RESTPOS)
		return EXPP_incr_ret(Py_True);
	else
		return EXPP_incr_ret(Py_False);
}
//------------------------Armature.restPosition (setter)
static int Armature_setRestPosition(BPy_Armature *self, PyObject *value, void *closure)
{
	if(value){
		if(PyBool_Check(value)){
			if (value == Py_True){
				self->armature->flag |= ARM_RESTPOS;
				return 0;
			}else if (value == Py_False){
				self->armature->flag &= ~ARM_RESTPOS;
				return 0;
			}
		}
	}
	goto AttributeError;

AttributeError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "Expects True or False");
}
//------------------------Armature.envelopes (getter)
static PyObject *Armature_getEnvelopes(BPy_Armature *self, void *closure)
{
	if (self->armature->deformflag & ARM_DEF_ENVELOPE)
		return EXPP_incr_ret(Py_True);
	else
		return EXPP_incr_ret(Py_False);
}
//------------------------Armature.envelopes (setter)
static int Armature_setEnvelopes(BPy_Armature *self, PyObject *value, void *closure)
{
	if(value){
		if(PyBool_Check(value)){
			if (value == Py_True){
				self->armature->deformflag |= ARM_DEF_ENVELOPE;
				return 0;
			}else if (value == Py_False){
				self->armature->deformflag &= ~ARM_DEF_ENVELOPE;
				return 0;
			}
		}
	}
	goto AttributeError;

AttributeError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "Expects True or False");
}
//------------------------Armature.vertexGroups (getter)
static PyObject *Armature_getVertexGroups(BPy_Armature *self, void *closure)
{
	if (self->armature->deformflag & ARM_DEF_VGROUP)
		return EXPP_incr_ret(Py_True);
	else
		return EXPP_incr_ret(Py_False);
}
//------------------------Armature.vertexGroups (setter)
static int Armature_setVertexGroups(BPy_Armature *self, PyObject *value, void *closure)
{
	if(value){
		if(PyBool_Check(value)){
			if (value == Py_True){
				self->armature->deformflag |= ARM_DEF_VGROUP;
				return 0;
			}else if (value == Py_False){
				self->armature->deformflag &= ~ARM_DEF_VGROUP;
				return 0;
			}
		}
	}
	goto AttributeError;

AttributeError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "Expects True or False");
}
//------------------------Armature.name (getter)
//Gets the name of the armature
static PyObject *Armature_getName(BPy_Armature *self, void *closure)
{
    return PyString_FromString(self->armature->id.name +2); //*new*
}
//------------------------Armature.name (setter)
//Sets the name of the armature
static int Armature_setName(BPy_Armature *self, PyObject *value, void *closure)
{
	char buffer[24];
	char *name = "";

	if(value){
		if(PyString_Check(value)){
			name = PyString_AsString(value);
			PyOS_snprintf(buffer, sizeof(buffer), "%s", name);
			rename_id(&self->armature->id, buffer);
			return 0; 
		}
	}
	goto AttributeError;

AttributeError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sArmatureBadArgs, "Expects string");
}
//------------------------Armature.bones (getter)
//Gets the name of the armature
static PyObject *Armature_getBoneDict(BPy_Armature *self, void *closure)
{
    return EXPP_incr_ret((PyObject*)self->Bones);
}
//------------------------Armature.bones (setter)
//Sets the name of the armature
/*TODO*/
/*Copy Bones through x = y*/
static int Armature_setBoneDict(BPy_Armature *self, PyObject *value, void *closure)
{
	goto AttributeError;

AttributeError:
	return EXPP_intError(PyExc_AttributeError, "%s%s", 
		sArmatureError, "You are not allowed to change the .Bones attribute");
}
//------------------TYPE_OBECT IMPLEMENTATION--------------------------
//------------------------tp_doc
//The __doc__ string for this object
static char BPy_Armature_doc[] = "This object wraps a Blender Armature object.";
//------------------------tp_methods
//This contains a list of all methods the object contains
static PyMethodDef BPy_Armature_methods[] = {
	{"makeEditable", (PyCFunction) Armature_makeEditable, METH_NOARGS, 
		"() - Unlocks the ability to modify armature bones"},
	{"update", (PyCFunction) Armature_update, METH_NOARGS, 
		"() - Rebuilds the armature based on changes to bones since the last call to makeEditable"},
	{NULL, NULL, 0, NULL}
};
//------------------------tp_getset
//This contains methods for attributes that require checking
static PyGetSetDef BPy_Armature_getset[] = {
	{"name", (getter)Armature_getName, (setter)Armature_setName, 
		"The armature's name", NULL},
	{"bones", (getter)Armature_getBoneDict, (setter)Armature_setBoneDict, 
		"The armature's Bone dictionary", NULL},
	{"vertexGroups", (getter)Armature_getVertexGroups, (setter)Armature_setVertexGroups, 
		"Enable/Disable vertex group defined deformation", NULL},
	{"envelopes", (getter)Armature_getEnvelopes, (setter)Armature_setEnvelopes, 
		"Enable/Disable bone envelope defined deformation", NULL},
	{"restPosition", (getter)Armature_getRestPosition, (setter)Armature_setRestPosition, 
		"Show armature rest position - disables posing", NULL},
	{"delayDeform", (getter)Armature_getDelayDeform, (setter)Armature_setDelayDeform, 
		"Don't deform children when manipulating bones in pose mode", NULL},
	{"drawAxes", (getter)Armature_getDrawAxes, (setter)Armature_setDrawAxes, 
		"Enable/Disable  drawing  the bone axes", NULL},
	{"drawNames", (getter)Armature_getDrawNames, (setter)Armature_setDrawNames, 
		"Enable/Disable  drawing the bone names", NULL},
	{"ghost", (getter)Armature_getGhost, (setter)Armature_setGhost, 
		"Draw a number of ghosts around the current frame for current Action", NULL},
	{"ghostStep", (getter)Armature_getStep, (setter)Armature_setStep, 
		"The number of frames between ghost instances", NULL},
	{"drawType", (getter)Armature_getDrawType, (setter)Armature_setDrawType, 
		"The type of drawing currently applied to the armature", NULL},
	{"mirrorEdit", (getter)Armature_getMirrorEdit, (setter)Armature_setMirrorEdit, 
		"Enable/Disable X-axis mirrored editing", NULL},
	{"autoIK", (getter)Armature_getAutoIK, (setter)Armature_setAutoIK, 
		"Adds temporal IK chains while grabbing bones", NULL},
	{"layers", (getter)Armature_getLayers, (setter)Armature_setLayers, 
		"List of layers for the armature", NULL},
	{NULL, NULL, NULL, NULL, NULL}
};
//------------------------tp_new
//This methods creates a new object (note it does not initialize it - only the building)
//This can be called through python by myObject.__new__() however, tp_init is not called
static PyObject *Armature_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
	BPy_Armature *py_armature = NULL;
	bArmature *bl_armature;

	bl_armature = add_armature();
	if(bl_armature) {
		bl_armature->id.us = 0; // return count to 0 - add_armature() inc'd it 

		py_armature = (BPy_Armature*)type->tp_alloc(type, 0); //*new*
		if (py_armature == NULL)
			goto RuntimeError;

		py_armature->armature = bl_armature;

		//create armature.bones
		py_armature->Bones = (BPy_BonesDict*)PyBonesDict_FromPyArmature(py_armature);
		if (!py_armature->Bones)
			goto RuntimeError;

	} else {
		goto RuntimeError;
	}
	return (PyObject*)py_armature; 

RuntimeError:
	return EXPP_objError(PyExc_RuntimeError, "%s%s%s", 
		sArmatureError, " __new__: ", "couldn't create Armature Data in Blender");
}
//------------------------tp_init
//This methods does initialization of the new object
//This method will get called in python by 'myObject(argument, keyword=value)'
//tp_new will be automatically called before this
static int Armature_init(BPy_Armature *self, PyObject *args, PyObject *kwds)
{
	char buf[21];
	char *name = "myArmature";
	static char *kwlist[] = {"name", NULL};

	if(!PyArg_ParseTupleAndKeywords(args, kwds, "|s", kwlist, &name)){
		goto AttributeError;
	}

	//rename the armature if a name is supplied
	if(!BLI_streq(name, "myArmature")){
		PyOS_snprintf(buf, sizeof(buf), "%s", name);
		rename_id(&self->armature->id, buf);
	}
	return 0;

AttributeError:
	return EXPP_intError(PyExc_AttributeError, "%s%s%s", 
		sArmatureBadArgs, " __init__: ", "Expects string(name)");
}
//------------------------tp_richcompare
//This method allows the object to use comparison operators
//TODO: We need some armature comparisons
static PyObject *Armature_richcmpr(BPy_Armature *self, PyObject *v, int op)
{
	return EXPP_incr_ret(Py_None);
}
//------------------------tp_repr
//This is the string representation of the object
static PyObject *Armature_repr(BPy_Armature *self)
{
	return PyString_FromFormat( "[Armature: \"%s\"]", self->armature->id.name + 2 ); //*new*
}
//------------------------tp_dealloc
//This tells how to 'tear-down' our object when ref count hits 0
///tp_dealloc
static void Armature_dealloc(BPy_Armature * self)
{
	Py_DECREF(self->Bones);
	Armature_Type.tp_free(self);
	return;
}
//------------------TYPE_OBECT DEFINITION--------------------------
PyTypeObject Armature_Type = {
	PyObject_HEAD_INIT(NULL)		//tp_head
	0,								//tp_internal
	"Armature",						//tp_name
	sizeof(BPy_Armature),			//tp_basicsize
	0,								//tp_itemsize
	(destructor)Armature_dealloc,	//tp_dealloc
	0,								//tp_print
	0,								//tp_getattr
	0,								//tp_setattr
	0,								//tp_compare
	(reprfunc) Armature_repr,		//tp_repr
	0,								//tp_as_number
	0,								//tp_as_sequence
	0,								//tp_as_mapping
	0,								//tp_hash
	0,								//tp_call
	0,								//tp_str
	0,								//tp_getattro
	0,								//tp_setattro
	0,								//tp_as_buffer
	Py_TPFLAGS_DEFAULT,				//tp_flags
	BPy_Armature_doc,				//tp_doc
	0,								//tp_traverse
	0,								//tp_clear
	(richcmpfunc)Armature_richcmpr,	//tp_richcompare
	0,								//tp_weaklistoffset
	0,								//tp_iter
	0,								//tp_iternext
	BPy_Armature_methods,			//tp_methods
	0,								//tp_members
	BPy_Armature_getset,			//tp_getset
	0,								//tp_base
	0,								//tp_dict
	0,								//tp_descr_get
	0,								//tp_descr_set
	0,								//tp_dictoffset
	(initproc)Armature_init,		//tp_init
	0,								//tp_alloc
	(newfunc)Armature_new,			//tp_new
	0,								//tp_free
	0,								//tp_is_gc
	0,								//tp_bases
	0,								//tp_mro
	0,								//tp_cache
	0,								//tp_subclasses
	0,								//tp_weaklist
	0								//tp_del
};

//-------------------MODULE METHODS IMPLEMENTATION------------------------
//----------------Blender.Armature.Get()
/* This function will return a Py_Armature when a single string is passed
* or else it will return a {key:value} dictionary when mutliple strings are passed
* or it will return a {key:value} dictionary of all armatures when nothing is passed*/
static PyObject *M_Armature_Get(PyObject * self, PyObject * args)
{
	PyObject *seq = NULL, *item = NULL, *dict = NULL, *py_armature = NULL;
	char *name = "", buffer[24];
	int size = 0, i;
	void *data;

	//GET ARGUMENTS - () ('s') ('s',..) (['s',..]) are exceptable
	size = PySequence_Length(args);
	if (size == 1) {
		seq = PySequence_GetItem(args, 0); //*new*
		if (!seq)
			goto RuntimeError;
		if(!PyString_Check(seq)){
			if (PySequence_Check(seq)) {
				size = PySequence_Length(seq);
			} else {
				Py_DECREF(seq);
				goto AttributeError;
			}
		}
	} else {
		seq = EXPP_incr_ret(args); //*take ownership*
	}
	//'seq' should be a list, empty tuple or string - check list for strings
	if(!PyString_Check(seq)){
		for(i = 0; i < size; i++){
			item = PySequence_GetItem(seq, i); //*new*
			if (!item) {
				Py_DECREF(seq);
				goto RuntimeError;
			}
			if(!PyString_Check(item)){
				EXPP_decr2(item, seq);
				goto AttributeError;
			}
			Py_DECREF(item);
		}
	}

	//GET ARMATURES
	if(size != 1){
		dict = PyDict_New(); //*new*
		if(!dict){
			Py_DECREF(seq);
			goto RuntimeError;
		}
		if(size == 0){	//GET ALL ARMATURES
			data = G.main->armature.first; //get the first data ID from the armature library
			while (data){
				py_armature = PyArmature_FromArmature(data); //*new*
				sprintf(buffer, "%s", ((bArmature*)data)->id.name +2);
				if(PyDict_SetItemString(dict, buffer, py_armature) == -1){ //add to dictionary
					EXPP_decr3(seq, dict, py_armature);
					goto RuntimeError;
				}
				Py_DECREF(py_armature);
				data = ((ID*)data)->next;
			}
			Py_DECREF(seq);
		}else{	//GET ARMATURE LIST
			for (i = 0; i < size; i++) {
				item = PySequence_GetItem(seq, i); //*new*
				name = PyString_AsString(item);
				Py_DECREF(item);
				data = find_id("AR", name); //get data from library
				if (data != NULL){
					py_armature = PyArmature_FromArmature(data); //*new*
					if(PyDict_SetItemString(dict, name, py_armature) == -1){ //add to dictionary
						EXPP_decr3(seq, dict, py_armature);
						goto RuntimeError;
					}
					Py_DECREF(py_armature);
				}else{
					if(PyDict_SetItemString(dict, name, Py_None) == -1){ //add to dictionary
						EXPP_decr2(seq, dict);
						goto RuntimeError;
					}
					Py_DECREF(Py_None);
				}
			}
			Py_DECREF(seq);
		}
		return dict;
	}else{	//GET SINGLE ARMATURE
		if(!PyString_Check(seq)){ //This handles the bizarre case where (['s']) is passed
			item = PySequence_GetItem(seq, 0); //*new*
			name = PyString_AsString(item);
			Py_DECREF(item);
		}else{
			name = PyString_AsString(seq);
		}
		Py_DECREF(seq);
		data = find_id("AR", name); //get data from library
		if (data != NULL){
			return PyArmature_FromArmature(data); //*new*
		}else{
			return EXPP_incr_ret(Py_None);
		}
	}

RuntimeError:
	return EXPP_objError(PyExc_RuntimeError, "%s%s%s", 
		sModuleError, "Get(): ", "Internal Error Ocurred");

AttributeError:
	return EXPP_objError(PyExc_AttributeError, "%s%s%s", 
		sModuleBadArgs, "Get(): ", "- Expects (optional) string sequence");
}

//-------------------MODULE METHODS DEFINITION-----------------------------

static char M_Armature_Get_doc[] = "(name) - return the armature with the name 'name', \
  returns None if not found.\n If 'name' is not specified, it returns a list of all \
  armatures in the\ncurrent scene.";

struct PyMethodDef M_Armature_methods[] = {
	{"Get", M_Armature_Get, METH_VARARGS, M_Armature_Get_doc},
	{NULL, NULL, 0, NULL}
};
//------------------VISIBLE PROTOTYPE IMPLEMENTATION-----------------------
//-----------------(internal)
//Converts a bArmature to a PyArmature
PyObject *PyArmature_FromArmature(struct bArmature *armature)
{
	BPy_Armature *py_armature = NULL;

	//create armature type
	py_armature = (BPy_Armature*)Armature_Type.tp_alloc(&Armature_Type, 0); //*new*
	if (!py_armature)
		goto RuntimeError;
	py_armature->armature = armature;

	//create armature.bones
	py_armature->Bones = (BPy_BonesDict*)PyBonesDict_FromPyArmature(py_armature);
	if (!py_armature->Bones)
		goto RuntimeError;

	return (PyObject *) py_armature; 

RuntimeError:
	return EXPP_objError(PyExc_RuntimeError, "%s%s%s", 
		sModuleError, "PyArmature_FromArmature: ", "Internal Error Ocurred");
}
//-----------------(internal)
//Converts a PyArmature to a bArmature
struct bArmature *PyArmature_AsArmature(BPy_Armature *py_armature)
{
	return (py_armature->armature);
}
//-------------------MODULE INITIALIZATION--------------------------------
PyObject *Armature_Init(void)
{
	PyObject *module, *dict;

	//Initializes TypeObject.ob_type
	if (PyType_Ready(&Armature_Type) < 0 ||	PyType_Ready(&BonesDict_Type) < 0 || 
		PyType_Ready(&EditBone_Type) < 0 ||	PyType_Ready(&Bone_Type) < 0) {
		return EXPP_incr_ret(Py_None);
	}

	//Register the module
	module = Py_InitModule3("Blender.Armature", M_Armature_methods, 
		"The Blender Armature module"); 

	//Add TYPEOBJECTS to the module
	PyModule_AddObject(module, "Armature", 
		EXPP_incr_ret((PyObject *)&Armature_Type)); //*steals*
	PyModule_AddObject(module, "Bone", 
		EXPP_incr_ret((PyObject *)&Bone_Type)); //*steals*
	PyModule_AddObject(module, "Editbone", 
		EXPP_incr_ret((PyObject *)&EditBone_Type)); //*steals*

	//Add CONSTANTS to the module
	PyModule_AddObject(module, "CONNECTED", 
		EXPP_incr_ret(PyConstant_NewInt("CONNECTED", BONE_CONNECTED)));
	PyModule_AddObject(module, "HINGE", 
		EXPP_incr_ret(PyConstant_NewInt("HINGE", BONE_HINGE)));
	PyModule_AddObject(module, "NO_DEFORM", 
		EXPP_incr_ret(PyConstant_NewInt("NO_DEFORM", BONE_NO_DEFORM)));
	PyModule_AddObject(module, "MULTIPLY", 
		EXPP_incr_ret(PyConstant_NewInt("MULTIPLY", BONE_MULT_VG_ENV)));
	PyModule_AddObject(module, "HIDDEN_EDIT", 
		EXPP_incr_ret(PyConstant_NewInt("HIDDEN_EDIT", BONE_HIDDEN_A)));
	PyModule_AddObject(module, "ROOT_SELECTED", 
		EXPP_incr_ret(PyConstant_NewInt("ROOT_SELECTED", BONE_ROOTSEL)));
	PyModule_AddObject(module, "BONE_SELECTED", 
		EXPP_incr_ret(PyConstant_NewInt("BONE_SELECTED", BONE_SELECTED)));
	PyModule_AddObject(module, "TIP_SELECTED", 
		EXPP_incr_ret(PyConstant_NewInt("TIP_SELECTED", BONE_TIPSEL)));

	PyModule_AddObject(module, "OCTAHEDRON", 
		EXPP_incr_ret(PyConstant_NewInt("OCTAHEDRON", ARM_OCTA)));
	PyModule_AddObject(module, "STICK", 
		EXPP_incr_ret(PyConstant_NewInt("STICK", ARM_LINE)));
	PyModule_AddObject(module, "BBONE", 
		EXPP_incr_ret(PyConstant_NewInt("BBONE", ARM_B_BONE)));
	PyModule_AddObject(module, "ENVELOPE", 
		EXPP_incr_ret(PyConstant_NewInt("ENVELOPE", ARM_ENVELOPE)));

	//Add SUBMODULES to the module
	dict = PyModule_GetDict( module ); //borrowed
	PyDict_SetItemString(dict, "NLA", NLA_Init()); //creates a *new* module

	return module;
}