<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Art Of Creation - Dynamics AX Blog &#187; Editorscripts</title>
	<atom:link href="http://www.artofcreation.be/tag/editorscripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.artofcreation.be</link>
	<description>The everyday life of a Dynamics AX developer</description>
	<lastBuildDate>Thu, 02 Feb 2012 12:20:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Editorscripts: create parm method from class declaration</title>
		<link>http://www.artofcreation.be/2009/08/27/editorscripts-create-parm-method-from-class-declaration/</link>
		<comments>http://www.artofcreation.be/2009/08/27/editorscripts-create-parm-method-from-class-declaration/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 11:55:22 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Editorscripts]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=188</guid>
		<description><![CDATA[I&#8217;ve always found it annoying that when you want to create a parm method using the editorscripts, you have to fill in two fields on a dialog (variable name and type). Most of the time, you&#8217;ve already declared the variable in the class declaration of your class, so it would be nice if you could [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always found it annoying that when you want to create a parm method using the editorscripts, you have to fill in two fields on a dialog (variable name and type). Most of the time, you&#8217;ve already declared the variable in the class declaration of your class, so it would be nice if you could just right click on that and create a parm method from there.</p>
<p>Below is a (quick and dirty) editorscript that allows you to do that.</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> template_method_parmfromCD<span style="color: #000000;">&#40;</span>Editor editor<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">int</span> endLine &nbsp; <span style="color: #00007f;">=</span> editor.<span style="color: #000000;">selectionEndLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">str</span> line;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">str</span> firstCol;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">str</span> secondCol;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">int</span> linecount;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">str</span> source;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">container</span> cont;<br />
&nbsp; &nbsp; XppSource xppSource;<br />
&nbsp; &nbsp; TreeNode tn;<br />
&nbsp; &nbsp; TreeNode childNode;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">boolean</span> contains<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">str</span> s<span style="color: #00007f;">,</span> <span style="color: #0000ff;">str</span> findStr<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">strscan</span><span style="color: #000000;">&#40;</span>s<span style="color: #00007f;">,</span> findStr<span style="color: #00007f;">,</span> <span style="color: #000000;">1</span><span style="color: #00007f;">,</span> <span style="color: #0000ff;">strlen</span><span style="color: #000000;">&#40;</span>s<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #00007f;">&gt;</span> <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">str</span> replace<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">str</span> s<span style="color: #00007f;">,</span> <span style="color: #0000ff;">str</span> findStr<span style="color: #00007f;">,</span> <span style="color: #0000ff;">str</span> replStr<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">int</span> pos <span style="color: #00007f;">=</span> <span style="color: #0000ff;">strscan</span><span style="color: #000000;">&#40;</span>s<span style="color: #00007f;">,</span> findStr<span style="color: #00007f;">,</span> <span style="color: #000000;">1</span><span style="color: #00007f;">,</span> <span style="color: #0000ff;">strlen</span><span style="color: #000000;">&#40;</span>s<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">while</span><span style="color: #000000;">&#40;</span>pos <span style="color: #00007f;">&gt;</span> <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s <span style="color: #00007f;">=</span> <span style="color: #0000ff;">strdel</span><span style="color: #000000;">&#40;</span>s<span style="color: #00007f;">,</span> pos<span style="color: #00007f;">,</span> <span style="color: #0000ff;">strlen</span><span style="color: #000000;">&#40;</span>findStr<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s <span style="color: #00007f;">=</span> <span style="color: #0000ff;">strins</span><span style="color: #000000;">&#40;</span>s<span style="color: #00007f;">,</span> replStr<span style="color: #00007f;">,</span> pos<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pos <span style="color: #00007f;">=</span> <span style="color: #0000ff;">strscan</span><span style="color: #000000;">&#40;</span>s<span style="color: #00007f;">,</span> findStr<span style="color: #00007f;">,</span> pos <span style="color: #00007f;">+</span> <span style="color: #0000ff;">strlen</span><span style="color: #000000;">&#40;</span>replStr<span style="color: #000000;">&#41;</span><span style="color: #00007f;">,</span> <span style="color: #0000ff;">strlen</span><span style="color: #000000;">&#40;</span>s<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">return</span> s;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; editor.<span style="color: #000000;">firstSelectedLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">while</span> <span style="color: #000000;">&#40;</span>editor.<span style="color: #000000;">moreLines</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #00007f;">&amp;&amp;</span> endline <span style="color: #00007f;">&gt;</span> editor.<span style="color: #000000;">lineNo</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; line <span style="color: #00007f;">=</span> <span style="color: #0000ff;">strltrim</span><span style="color: #000000;">&#40;</span>editor.<span style="color: #000000;">getLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">while</span><span style="color: #000000;">&#40;</span>contains<span style="color: #000000;">&#40;</span>line<span style="color: #00007f;">,</span> <span style="color: #ff0000;">&quot; &nbsp;&quot;</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line <span style="color: #00007f;">=</span> replace<span style="color: #000000;">&#40;</span>line<span style="color: #00007f;">,</span> <span style="color: #ff0000;">&quot; &nbsp;&quot;</span><span style="color: #00007f;">,</span> <span style="color: #ff0000;">&quot; &quot;</span> <span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; cont <span style="color: #00007f;">=</span> str2con<span style="color: #000000;">&#40;</span>line<span style="color: #00007f;">,</span> <span style="color: #ff0000;">&quot; &quot;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; firstCol <span style="color: #00007f;">=</span> <span style="color: #0000ff;">conpeek</span><span style="color: #000000;">&#40;</span>cont<span style="color: #00007f;">,</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; secondCol <span style="color: #00007f;">=</span> <span style="color: #0000ff;">conpeek</span><span style="color: #000000;">&#40;</span>cont<span style="color: #00007f;">,</span> <span style="color: #000000;">2</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; secondCol <span style="color: #00007f;">=</span> <span style="color: #0000ff;">strrem</span><span style="color: #000000;">&#40;</span>secondCol<span style="color: #00007f;">,</span> <span style="color: #ff0000;">&quot;;=&quot;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; editor.<span style="color: #000000;">nextSelectedLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; tn <span style="color: #00007f;">=</span> EditorScripts<span style="color: #00007f;">::</span><span style="color: #000000;">getApplObjectNode</span><span style="color: #000000;">&#40;</span>editor<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #000000;">&#40;</span>firstCol <span style="color: #00007f;">!=</span> <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #00007f;">&amp;&amp;</span> secondCol <span style="color: #00007f;">!=</span> <span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #000000;">&#40;</span><span style="color: #00007f;">!</span>tn.<span style="color: #000000;">AOTfindChild</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">strfmt</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;parm%1&quot;</span><span style="color: #00007f;">,</span> <span style="color: #0000ff;">strupr</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">substr</span><span style="color: #000000;">&#40;</span>secondCol<span style="color: #00007f;">,</span><span style="color: #000000;">1</span><span style="color: #00007f;">,</span><span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #00007f;">+</span><span style="color: #0000ff;">substr</span><span style="color: #000000;">&#40;</span>secondCol<span style="color: #00007f;">,</span><span style="color: #000000;">2</span><span style="color: #00007f;">,</span><span style="color: #0000ff;">strlen</span><span style="color: #000000;">&#40;</span>secondCol<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #000000;">&#40;</span>tn.<span style="color: #000000;">AOTfindChild</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;Methods&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tn <span style="color: #00007f;">=</span> tn.<span style="color: #000000;">AOTfindChild</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;Methods&quot;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; childNode <span style="color: #00007f;">=</span> tn.<span style="color: #000000;">AOTadd</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">strfmt</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;parm%1&quot;</span><span style="color: #00007f;">,</span> <span style="color: #0000ff;">strupr</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">substr</span><span style="color: #000000;">&#40;</span>secondCol<span style="color: #00007f;">,</span><span style="color: #000000;">1</span><span style="color: #00007f;">,</span><span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #00007f;">+</span><span style="color: #0000ff;">substr</span><span style="color: #000000;">&#40;</span>secondCol<span style="color: #00007f;">,</span><span style="color: #000000;">2</span><span style="color: #00007f;">,</span><span style="color: #0000ff;">strlen</span><span style="color: #000000;">&#40;</span>secondCol<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xppSource <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> XppSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source <span style="color: #00007f;">=</span> xppSource.<span style="color: #000000;">parmMethod</span><span style="color: #000000;">&#40;</span>firstcol<span style="color: #00007f;">,</span>secondCol<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; childNode.<span style="color: #000000;">AOTsetSource</span><span style="color: #000000;">&#40;</span>source<span style="color: #00007f;">,</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tn.<span style="color: #000000;">AOTsave</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">strfmt</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;Parm method %1 already exists&quot;</span><span style="color: #00007f;">,</span> <span style="color: #0000ff;">strfmt</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;parm%1&quot;</span><span style="color: #00007f;">,</span> <span style="color: #0000ff;">strupr</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">substr</span><span style="color: #000000;">&#40;</span>secondCol<span style="color: #00007f;">,</span><span style="color: #000000;">1</span><span style="color: #00007f;">,</span><span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #00007f;">+</span><span style="color: #0000ff;">substr</span><span style="color: #000000;">&#40;</span>secondCol<span style="color: #00007f;">,</span><span style="color: #000000;">2</span><span style="color: #00007f;">,</span><span style="color: #0000ff;">strlen</span><span style="color: #000000;">&#40;</span>secondCol<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Some code from Greg Pierce’s awesome <a href="http://greg.agiletortoise.com/2007/01/12/dynamix-ax-axapta-string-class/">String class</a> was used for the inner methods.<br />
I tested it on classes, form and reports, and it works very well.</p>
<p>To install this editorscript, copy the code above in a new method of the class EditorScripts.<br />
To use it, in the classDeclaration, simply select one or more declarations, then right click and choose Scripts &#8211; template &#8211; method &#8211; parmfromCD.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2009/08/27/editorscripts-create-parm-method-from-class-declaration/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

