Index: tmp/org.txm.analec.rcp/src/org/txm/macro/urs/democrat/BuildSectionsMacro.groovy
===================================================================
--- tmp/org.txm.analec.rcp/src/org/txm/macro/urs/democrat/BuildSectionsMacro.groovy	(revision 0)
+++ tmp/org.txm.analec.rcp/src/org/txm/macro/urs/democrat/BuildSectionsMacro.groovy	(revision 2148)
@@ -0,0 +1,68 @@
+package org.txm.macro.urs.democrat
+
+import org.txm.searchengine.cqp.corpus.*
+import org.txm.rcpapplication.views.*
+import org.txm.searchengine.cqp.corpus.query.*
+import org.txm.Toolbox
+
+def scriptName = this.class.getSimpleName()
+def utils = new org.txm.macro.urs.exploit.CQPUtils()
+
+// Création des 4 sous-corpus de chapitres
+
+[1, 2, 3, 4].each { chapitre ->
+	res = gse.run(SubCorpusMacro, ["args":[ "corpus":"DIDEROTESSAIS", "name":"Chapitre "+chapitre, "query":"[_.div_n1=\""+chapitre+"\"] expand to div1" ],
+                                "selection":selection,
+                                "selections":selections,
+                                "corpusViewSelection":corpusViewSelection,
+                                "corpusViewSelections":corpusViewSelections,
+                                "monitor":monitor])
+	if (!res) println "** problem calling SubCorpusMacro."
+}
+
+
+// Définition des paragraphes dans les 4 chapitres
+
+def para = [
+[1, 14, 17, 22],
+[2, 29, 44, 46],
+[3, 53, 63, 66],
+[4, 74, 75, 79]
+]
+
+// get the CQP corpus
+if (!(corpusViewSelection instanceof CQPCorpus)) {
+	println "Corpus view selection is no a corpus: $corpusViewSelection"
+	return false;
+}
+def corpus = corpusViewSelection
+if (corpus.getName() != "DIDEROTESSAIS") {
+	println "Warning: this macro was made to work for the DIDEROTESSAIS corpus"
+}
+	
+para.each { chapitre ->
+
+	println chapitre
+
+	def subcorpus = corpus.getSubcorpusByName("Chapitre "+chapitre[0])
+
+	println "chap = "+subcorpus
+
+	[1, 2, 3].each { num ->
+
+		def p = chapitre[num]
+
+		println "p = "+p
+
+		name = "p "+p
+		query = '[_.p_n=\"'+p+'\"] expand to p'
+
+		res = gse.run(SubCorpusMacro, ["args":[ "name":name, "query":query ],
+                                "corpusViewSelections":[subcorpus],
+								"corpusViewSelection":subcorpus,
+                                "monitor":monitor])
+		
+
+	} // [1, 2, 3].each
+
+} // para.each
Index: tmp/org.txm.analec.rcp/src/org/txm/macro/urs/democrat/SubCorpusMacro.groovy
===================================================================
--- tmp/org.txm.analec.rcp/src/org/txm/macro/urs/democrat/SubCorpusMacro.groovy	(revision 0)
+++ tmp/org.txm.analec.rcp/src/org/txm/macro/urs/democrat/SubCorpusMacro.groovy	(revision 2148)
@@ -0,0 +1,74 @@
+package org.txm.macro.urs.democrat;
+
+	// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté
+	// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
+	// @author mdecorde
+	// @author sheiden
+	
+	
+	import org.kohsuke.args4j.*
+	import groovy.transform.Field
+	import org.txm.rcpapplication.swt.widget.parameters.*
+	import org.txm.searchengine.cqp.*
+	import org.txm.searchengine.cqp.corpus.*
+	import org.txm.searchengine.cqp.corpus.query.*
+	import org.txm.*
+	import org.txm.rcpapplication.views.*
+	
+	// BEGINNING OF PARAMETERS
+	
+	// Declare each parameter here
+	// (available widget types: Query, File, Folder, String, Text, Boolean, Integer, Float and Date)
+	
+	@Field @Option(name="name", usage="name of the subcorpus result", widget="String", required=true, def="subcorpus1")
+	def name
+	
+	@Field @Option(name="query", usage="query to build subcorpus", widget="String", required=true, def="n:[] :: n = 0 expand to 10")
+	def query
+	/*
+	
+	n:[] [] [] [] [] [] [] [] [] [] :: n = 0
+	n:[] :: n = 0 expand to 10
+	
+	*/
+	
+	// Open the parameters input dialog box
+	if (!ParametersDialog.open(this)) return false
+	
+	def CQI = CQPSearchEngine.getCqiClient()
+	
+	def scriptName = this.class.getSimpleName()
+	
+	def utils = new org.txm.macro.urs.exploit.CQPUtils()
+	
+	def corpora = utils.getCorpora(this)
+	
+	if ((corpora == null) || corpora.size() == 0) {
+		println "** $scriptName: please select a corpus in the Corpus view or provide a corpus name. Aborting."
+		return false
+	}
+	
+	/*
+	CorpusManager.getCorpusManager().getCorpora().each {
+		if (it.getSubcorpusByName(name)) {
+			println "** Subcorpus: sub-corpus name already used. Please use another sub-corpus name. Aborting."
+			return false
+		}
+		// it.getSubcorpora().each { sub -> println it.getName()+" subcorpora: "+sub.getName() }
+	}
+	*/
+	
+	String resultCqpId = CqpObject.subcorpusNamePrefix + CQPCorpus.getNextSubcorpusCounter()
+	String queryString = "$resultCqpId=$query;"
+	
+	CQI.query(queryString)
+	
+	def subcorpus = corpora[0].createSubcorpus(new CQLQuery("$query;"), name)
+	
+	if (binding.variables["monitor"]) {
+		utils.refreshCorpusViewExpand(monitor, subcorpus.getParent())
+	}
+	
+	return true
+
+
Index: tmp/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/CQPUtils.groovy
===================================================================
--- tmp/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/CQPUtils.groovy	(revision 2147)
+++ tmp/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/CQPUtils.groovy	(revision 2148)
@@ -5,9 +5,10 @@
 package org.txm.macro.urs.exploit
 
 import org.txm.searchengine.cqp.corpus.*
+import org.txm.rcp.views.corpora.*
 
 def getCorpusByName(name) {
-	def cl = CorpusManager.getCorpusManager().getCorpora()
+	def cl = CorpusManager.getCorpusManager().getCorpora().values()
 	def rc = cl.find {
 		it.getID() == name
 	}
@@ -26,6 +27,15 @@
 	return rsc
 }
 
+def refreshCorpusViewExpand(monitor, corpus) {
+	monitor.syncExec(new Runnable() {
+		public void run() {
+			CorporaView.refresh()
+			CorporaView.expand(corpus)
+		}
+	})
+}
+
 def getCorpora(def script) {
 
 	def scriptName = this.class.getSimpleName()
