def addMeshInstance(self, meshTemplateName, meshInstanceName):
        """
        Creates and adds a new meshInstance to this geometryInstance.
        Raises an AcdOptiException_geomInstance_nameError
        if the meshInstanceName is already in use or the meshTemplate does not exist.
        """

        print "AcdOptiGeometryInstance::addMeshInstance(meshTemplateName=\""\
             + meshTemplateName + "\" , meshInstanceName=\"" + meshInstanceName + "\" )"
        
        #Check that the mesh instance name is not already in use:
        if meshInstanceName in self.meshInsts:
            raise AcdOptiException_geomInstance_nameError("Mesh instance name already in use")
        
        folder = os.path.join(self.folder,self.meshInstanceFolderName,meshInstanceName)
    
        try:
            AcdOptiMeshInstance.createNew(folder, self.instName, meshTemplateName)
        except AcdOptiException_meshInstance_createFail:
            raise AcdOptiException_geomInstance_nameError("Mesh instance name \"" + meshInstanceName + "\" already in use")
        
        meshInstance = AcdOptiMeshInstance(folder, self, self.template.project.meshTemplateCollection)
        
        self.meshInsts[meshInstanceName] = meshInstance

        print "AcdOptiGeometryInstance::addMeshInstance():Mesh instances currently loaded:" + str(self.meshInsts)
 def cloneMeshInstance(self, oldObject, newName):
     """
     Clone a mesh object into a new name and attach it to the current geometryInstance
     """
     print "AcdOptiGeometryInstance::cloneMeshInstance()"
     assert not newName in self.meshInsts
     
     newMesh = AcdOptiMeshInstance.createNew_clone(os.path.join(self.folder, self.meshInstanceFolderName, newName), oldObject, self)
     self.meshInsts[newName] = newMesh
     self.write()
    def createNew_clone(folder, cloneFrom):
        """
        Creates a new geomInstance in a not previously existing folder,
        which has identical settings as an already existing geometryInstance.
        The newly created geomInstance is then returned.
        
        This is a deep copy, meshInstances etc. are also cloned.
        """
        #Create the new geomInstance
        AcdOptiGeometryInstance.createNew(folder)
        newInstance = AcdOptiGeometryInstance(folder, cloneFrom.template)

        #Copy information        
        for key in cloneFrom.templateOverrides_getKeys():
            newInstance.templateOverrides_insert(key, cloneFrom.templateOverrides_get(key))
        
        for (meshName, mesh) in cloneFrom.meshInsts.iteritems():
            newMesh = AcdOptiMeshInstance.createNew_clone(os.path.join(folder,"meshInstances",meshName), mesh, newInstance)
            newInstance.meshInsts[meshName] = newMesh
        
        newInstance.write()
        return newInstance