Index: TXM/trunk/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/CQPUtils.groovy
===================================================================
--- TXM/trunk/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/CQPUtils.groovy	(revision 3321)
+++ TXM/trunk/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/CQPUtils.groovy	(revision 3322)
@@ -2,10 +2,20 @@
 // Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
 // @author sheiden
 
-package org.txm.macro.cqp
+package org.txm.macro.urs.exploit
 
 import org.txm.searchengine.cqp.corpus.*
+import org.txm.rcp.views.corpora.*
 
+def refreshCorpusViewExpand(monitor, corpus) {
+	monitor.syncExec(new Runnable() {
+		public void run() {
+			CorporaView.refresh()
+			CorporaView.expand(corpus)
+		}
+	})
+}
+
 def getCorpusByName(name) {
 	def cl = CorpusManager.getCorpusManager().getCorpora()
 	def rc = cl.find {
Index: TXM/trunk/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/Units2SubCorpusMacro.groovy
===================================================================
--- TXM/trunk/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/Units2SubCorpusMacro.groovy	(revision 0)
+++ TXM/trunk/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/Units2SubCorpusMacro.groovy	(revision 3322)
@@ -0,0 +1,91 @@
+package org.txm.macro.urs.exploit
+
+// Copyright © 2021 ENS de Lyon, CNRS, University of Franche-Comté
+// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
+// @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.*
+//import org.txm.macro.cqp.CQPUtils
+import org.txm.annotation.urs.URSCorpora
+import org.txm.macro.urs.AnalecUtils
+
+// BEGINNING OF PARAMETERS
+
+// Declare each parameter here
+// (available widget types: Query, File, Folder, String, Text, Boolean, Integer, Float and Date)
+
+@Field @Option(name="subcorpus_name", usage="name of the subcorpus result", widget="String", required=true, def="subcorpus1")
+def subcorpus_name
+
+@Field @Option(name="unit_ursql", usage="TYPE@PROP=VALUE", widget="String", required=false, def="MENTION")
+String unit_ursql
+
+@Field @Option(name="debug", usage="Show debug information", widget="StringArray", metaVar="OFF	ON	ALL	REALLY ALL", required=false, def="OFF")
+debug
+
+// Open the parameters input dialog box
+if (!ParametersDialog.open(this)) return false
+
+if (debug == "OFF") debug = 0; else if (debug == "ON") debug = 1; else if (debug == "ALL") debug = 2 else if (debug == "REALLY ALL") debug = 3
+
+def CQI = CQPSearchEngine.getCqiClient()
+
+def scriptName = this.class.getSimpleName()
+
+def utils = new CQPUtils()
+
+corpora = utils.getCorpora(this)
+
+if ((corpora == null) || corpora.size() > 1) {
+	println "** $scriptName: please select a corpus in the Corpus view or provide a corpus name. Aborting."
+	return false
+}
+
+corpus = corpora[0].getMainCorpus()
+corpusName = corpus.getName()
+
+if (!URSCorpora.isAnnotationStructureReady(corpus)) {
+	println "** URS Annotation Structure of "+corpusName+" is not ready. Aborting."
+	return
+}
+
+def analecCorpus = URSCorpora.getCorpus(corpus)
+	
+def selectedUnits = AnalecUtils.selectUnitsInSchema(debug, analecCorpus, corpus, null, 0, 1000000, unit_ursql, 0, null, false, 0)
+
+nUnits = selectedUnits.size()
+query = ""
+
+if (nUnits == 0) {
+	println "No units selected, no subcorpus created."
+	return
+} else {
+	println nUnits+" units selected."
+	positionsList = selectedUnits.collect {
+		[it.getDeb(), it.getFin()]
+	}
+	query = utils.positions2cql(utils.positionsList2positions(positionsList, 20, false))
+}
+
+String resultCqpId = CqpObject.subcorpusNamePrefix + CQPCorpus.getNextSubcorpusCounter()
+String queryString = "$resultCqpId=$query;"
+
+CQI.query(queryString)
+
+def subcorpus = corpora[0].createSubcorpus(new CQLQuery("$query;"), subcorpus_name)
+
+if (binding.variables["monitor"]) {
+	utils.refreshCorpusViewExpand(monitor, subcorpus.getParent())
+}
+
+return true
+
+
Index: TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/cqp/CQPUtils.groovy
===================================================================
--- TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/cqp/CQPUtils.groovy	(revision 3321)
+++ TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/cqp/CQPUtils.groovy	(revision 3322)
@@ -5,7 +5,17 @@
 package org.txm.macro.cqp
 
 import org.txm.searchengine.cqp.corpus.*
+import org.txm.rcp.views.corpora.*
 
+def refreshCorpusViewExpand(monitor, corpus) {
+	monitor.syncExec(new Runnable() {
+		public void run() {
+			CorporaView.refresh()
+			CorporaView.expand(corpus)
+		}
+	})
+}
+
 def getCorpusByName(name) {
 	def cl = CorpusManager.getCorpusManager().getCorpora()
 	def rc = cl.find {
