Index: scribus/plugins/scriptplugin/cmdobj.h
===================================================================
--- scribus/plugins/scriptplugin/cmdobj.h	(Revision 22369)
+++ scribus/plugins/scriptplugin/cmdobj.h	(Arbeitskopie)
@@ -283,23 +283,46 @@
 PyObject *scribus_getcharstylenames(PyObject * /*self*/);
 
 
+/* Jonas Bechtel, 2018-02-04 */
 /*! docstring */
+PyDoc_STRVAR(scribus_renameobject__doc__,
+QT_TR_NOOP("renameObject([\"newname\", <\"oldname\">]) -> string\n\
+\n\
+Renames the object \"oldname\" (or the selected object) to \"oldname\".\n\
+"));
+PyObject *scribus_renameobject(PyObject * /* self */, PyObject *args);
+
+
+
+/* Jonas Bechtel, 2018-02-03 */
+/*! docstring */
 PyDoc_STRVAR(scribus_duplicateobject__doc__,
-QT_TR_NOOP("duplicateObject([\"name\"]) -> string\n\
+QT_TR_NOOP("duplicateObject([<\"newname\", <\"name\">>]) -> string\n\
 \n\
-creates a Duplicate of the selected Object (or Selection Group).\n\
+Creates a duplicate of the selected or named single object.\n\
+The duplicate will have the name \"newname\", if provided.\n\
 "));
+PyObject *scribus_duplicateobject(PyObject * /* self */, PyObject *args);
+
+
+/*! docstring */
+PyDoc_STRVAR(scribus_duplicateobject_legacy__doc__,
+QT_TR_NOOP("duplicateObject_legacy([\"name\"]) -> None\n\
+\n\
+creates a duplicate of the selected or named object (or selection group).\n\
+[Remark: you will find that object in your system's clipboard then].\n\
+"));
 /**
  Christian Hausknecht, 2006-07-12
  duplicate an object
 */
-PyObject *scribus_duplicateobject(PyObject * /* self */, PyObject *args);
+PyObject *scribus_duplicateobject_legacy(PyObject * /* self */, PyObject *args);
 
 /*! docstring */
 PyDoc_STRVAR(scribus_copyobject__doc__,
 QT_TR_NOOP("copyObject([\"name\"]) -> string\n\
 \n\
-copies the selected Object (or Selection Group).\n\
+copies the selected object (or selection group).\n\
 "));
 /**
  Gregory Pittman, 2012-01-12
Index: scribus/plugins/scriptplugin/cmdobj.cpp
===================================================================
--- scribus/plugins/scriptplugin/cmdobj.cpp	(Revision 22369)
+++ scribus/plugins/scriptplugin/cmdobj.cpp	(Arbeitskopie)
@@ -16,7 +16,9 @@
 #include "selection.h"
 #include "util_math.h"
 
+#include "scriptercore.h"
 
+
 PyObject *scribus_newrect(PyObject* /* self */, PyObject* args)
 {
 	double x, y, w, h;
@@ -43,7 +45,7 @@
 		if (!ItemExists(objName))
 			ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName);
 	}
-	return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8());
+	return Legacy_PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8());
 }
 
 
@@ -69,7 +71,7 @@
 		if (!ItemExists(objName))
 			ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName);
 	}
-	return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8());
+	return Legacy_PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8());
 }
 
 
@@ -94,7 +96,7 @@
 		if (!ItemExists(objName))
 			ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName);
 	}
-	return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8());
+	return Legacy_PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8());
 }
 
 
@@ -119,7 +121,7 @@
 		if (!ItemExists(objName))
 			ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName);
 	}
-	return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8());
+	return Legacy_PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8());
 }
 
 PyObject *scribus_newtable(PyObject* /* self */, PyObject* args)
@@ -155,7 +157,7 @@
 		if (!ItemExists(objName))
 			ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName);
 	}
-	return PyString_FromString(table->itemName().toUtf8());
+	return Legacy_PyString_FromString(table->itemName().toUtf8());
 }
 
 PyObject *scribus_newline(PyObject* /* self */, PyObject* args)
@@ -215,7 +217,7 @@
 		if (!ItemExists(objName))
 			ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName);
 	}
-	return PyString_FromString(it->itemName().toUtf8());
+	return Legacy_PyString_FromString(it->itemName().toUtf8());
 }
 
 
@@ -292,7 +294,7 @@
 		if (!ItemExists(objName))
 			ScCore->primaryMainWindow()->doc->Items->at(ic)->setItemName(objName);
 	}
-	return PyString_FromString(it->itemName().toUtf8());
+	return Legacy_PyString_FromString(it->itemName().toUtf8());
 }
 
 
@@ -374,7 +376,7 @@
 		if (!ItemExists(objName))
 			ScCore->primaryMainWindow()->doc->Items->at(ic)->setItemName(objName);
 	}
-	return PyString_FromString(it->itemName().toUtf8());
+	return Legacy_PyString_FromString(it->itemName().toUtf8());
 }
 
 PyObject *scribus_bezierline(PyObject* /* self */, PyObject* args)
@@ -465,7 +467,7 @@
 		if (!ItemExists(objName))
 			ScCore->primaryMainWindow()->doc->Items->at(ic)->setItemName(objName);
 	}
-	return PyString_FromString(it->itemName().toUtf8());
+	return Legacy_PyString_FromString(it->itemName().toUtf8());
 }
 
 
@@ -506,7 +508,7 @@
 		if (!ItemExists(objName))
 			i->setItemName(objName);
 	}
-	return PyString_FromString(i->itemName().toUtf8());
+	return Legacy_PyString_FromString(i->itemName().toUtf8());
 }
 
 
@@ -527,6 +529,9 @@
 	ScCore->primaryMainWindow()->doc->itemSelection_DeleteItem();
 //	Py_INCREF(Py_None);
 //	return Py_None;
+	
+	emit scripterCore->checkpoint(10);
+	
 	Py_RETURN_NONE;
 }
 
@@ -760,7 +765,7 @@
 	styleList = PyList_New(0);
 	for (int i=0; i < ScCore->primaryMainWindow()->doc->paragraphStyles().count(); ++i)
 	{
-		if (PyList_Append(styleList, PyString_FromString(ScCore->primaryMainWindow()->doc->paragraphStyles()[i].name().toUtf8())))
+		if (PyList_Append(styleList, Legacy_PyString_FromString(ScCore->primaryMainWindow()->doc->paragraphStyles()[i].name().toUtf8())))
 		{
 			// An exception will have already been set by PyList_Append apparently.
 			return NULL;
@@ -777,7 +782,7 @@
 	charStyleList = PyList_New(0);
 	for (int i=0; i < ScCore->primaryMainWindow()->doc->charStyles().count(); ++i)
 	{
-		if (PyList_Append(charStyleList, PyString_FromString(ScCore->primaryMainWindow()->doc->charStyles()[i].name().toUtf8())))
+		if (PyList_Append(charStyleList, Legacy_PyString_FromString(ScCore->primaryMainWindow()->doc->charStyles()[i].name().toUtf8())))
 		{
 			// An exception will have already been set by PyList_Append apparently.
 			return NULL;
@@ -786,16 +791,82 @@
 	return charStyleList;
 }
 
+PyObject *scribus_renameobject(PyObject * /* self */, PyObject *args)
+{
+	char* origname = const_cast<char*>("");
+	char* newname = const_cast<char*>("");
+	if (!PyArg_ParseTuple(args, "es|es", "utf-8", &newname, "utf-8", &origname)) {
+		Py_RETURN_NONE;
+	}
+	if(!checkHaveDocument()) {
+		Py_RETURN_NONE;
+	}
+	
+	PageItem *src = GetUniqueItem(QString::fromUtf8(origname));
+	if (src == NULL) {
+		qDebug() << QString("Cannot get item \"%1\".").arg(origname);
+		Py_RETURN_NONE;
+	}
+	
+	src->setItemName(newname);
+	if (src->itemName() != newname)
+	{
+		PyErr_SetString(
+			NameExistsError,
+			QObject::tr("An object with the requested name already exists.",
+			            "python error").toUtf8().constData());
+		src->setItemName(origname);
+		qDebug() << QString("Wanted back to \"%1\", got \"%2\".").arg(origname, src->itemName());
+		Py_RETURN_NONE;
+	}
+	
+	emit scripterCore->checkpoint(5);
+	
+	return Legacy_PyString_FromString(src->itemName().toUtf8());
+}
+
 PyObject *scribus_duplicateobject(PyObject * /* self */, PyObject *args)
 {
 	char* name = const_cast<char*>("");
+	char* newname = const_cast<char*>("");
+	if (!PyArg_ParseTuple(args, "|eses", "utf-8", &newname, "utf-8", &name)) {
+		Py_RETURN_NONE;
+	}
+	if(!checkHaveDocument()) {
+		Py_RETURN_NONE;
+	}
+	// We require a name given and duplicate only one object at one time.
+	PageItem *src = GetUniqueItem(QString::fromUtf8(name));
+	if (src == NULL) {
+		qDebug() << "Cannot duplicate NULL.";
+		Py_RETURN_NONE;
+	}
+	
+	QString qnewname = QString::fromUtf8(newname);
+	
+	// do the duplicate
+	PageItem *dst = ScCore->primaryMainWindow()->slotDuplicateSingle(src, &qnewname);
+	
+	if (dst == NULL) {
+		emit scripterCore->checkpoint(4);
+		Py_RETURN_NONE;
+	}
+	
+	emit scripterCore->checkpoint(12);
+	
+	return Legacy_PyString_FromString(dst->itemName().toUtf8());
+}
+
+PyObject *scribus_duplicateobject_legacy(PyObject * /* self */, PyObject *args)
+{
+	char* name = const_cast<char*>("");
 	if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) {
-		return NULL;
+		Py_RETURN_NONE;
 	}
 	if(!checkHaveDocument()) {
-		return NULL;
+		Py_RETURN_NONE;
 	}
-	// Is there a special name given? Yes -> add this to selection
+	// Is there a special name given? Yes -> make a selection of it
 	PageItem *i = GetUniqueItem(QString::fromUtf8(name));
 	if (i != NULL) {
 		ScCore->primaryMainWindow()->doc->m_Selection->clear();
@@ -802,12 +873,15 @@
 		ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
 	}
 	else
-		return NULL;
+		Py_RETURN_NONE;
 	// do the duplicate
 	ScCore->primaryMainWindow()->slotEditCopy();
 	ScCore->primaryMainWindow()->slotEditPaste();
 //	Py_INCREF(Py_None);
 //	return Py_None;
+	
+	emit scripterCore->checkpoint(20);
+	
 	Py_RETURN_NONE;
 }
 
@@ -855,8 +929,8 @@
 /*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings
 with header files structure untouched (docstrings are kept near declarations)
 PV */
-void cmdobjdocwarnings()
+inline void cmdobjdocwarnings()
 {
 	QStringList s;
-	s << scribus_newrect__doc__ <<scribus_newellipse__doc__ << scribus_newimage__doc__ << scribus_newtext__doc__ << scribus_newtable__doc__ << scribus_newline__doc__ <<scribus_polyline__doc__ << scribus_polygon__doc__ << scribus_bezierline__doc__ <<scribus_pathtext__doc__ <<scribus_deleteobj__doc__ <<scribus_textflow__doc__ <<scribus_objectexists__doc__ <<scribus_setstyle__doc__ <<scribus_getstylenames__doc__ <<scribus_getcharstylenames__doc__ <<scribus_duplicateobject__doc__ <<scribus_copyobject__doc__ <<scribus_pasteobject__doc__;
+	s << scribus_newrect__doc__ <<scribus_newellipse__doc__ << scribus_newimage__doc__ << scribus_newtext__doc__ << scribus_newtable__doc__ << scribus_newline__doc__ <<scribus_polyline__doc__ << scribus_polygon__doc__ << scribus_bezierline__doc__ <<scribus_pathtext__doc__ <<scribus_deleteobj__doc__ <<scribus_textflow__doc__ <<scribus_objectexists__doc__ <<scribus_setstyle__doc__ <<scribus_setcharstyle__doc__ <<scribus_getstylenames__doc__ <<scribus_getcharstylenames__doc__ <<scribus_renameobject__doc__ <<scribus_duplicateobject__doc__ <<scribus_duplicateobject__doc__ <<scribus_duplicateobject_legacy__doc__ <<scribus_copyobject__doc__ <<scribus_pasteobject__doc__;
 }
