I get the variables with Nisus Writer Pro macro as follow into clipboard 1 and clipboard 2
#counter für z.B. 30-35
Find and Replace ‘([[:digit:]]+)\-([[:digit:]]+)’, ‘\1\2’, ‘aEU’ #Bis-Nummer suchen
Begin Perl
I need to count them up to get the result 30.31.32.33.34.35 back into the text.
Unfortunately I don't know how to give the parameters 30 and 35 from the clipboard to pearl nor to count up with perl, because I never used perl before.
Thank you for your help
dakofi
Variable from clipboard to perl
Re: Variable from clipboard to perl
Your code does not put anything in clipboards and you don't need using Perl to do calculation of that kind. What you are trying to do is not very clear to me but am I right in assuming you want to convert all occurrences of number ranges such as "30-35" into "30.31.32.33.34.35" or something alike? If so, the following macro will do the job.dakofi wrote: Find and Replace ‘([[:digit:]]+)\-([[:digit:]]+)’, ‘\1\2’, ‘aEU’ #Bis-Nummer suchen
Begin Perl
Code: Select all
# Work on selection(s). If there is no selection, the whole document
# will be processed.
# Expand, for example, 1-3, 22-25, etc. to "1.2.3", "22.23.24.25", etc.
# You can customize the separator -- "." in the examples above -- by
# changing « . » in « $separator = '.' », the very first command of
# this macro.
$separator = '.'
Require Application Version '3.1'
$firstSel = TextSelection.active
if $firstSel == undefined
Exit 'No open document, exit...'
elsif ! $firstSel.length
Select All Document
end
$doc = Document.active
$numFound = Find All '[0-9]+\-[0-9]+', 'Es'
if ! $numFound
Exit 'Nothing found, exit...'
end
$selections = $doc.textSelections
foreach $sel in reversed $selections
$nums = $sel.subtext
$nums = $nums.split '-'
$i = $nums.firstValue
$j = $nums.lastValue
if $i < $j
$c = Array.new
while $i <= $j
$c.appendValue $i
$i += 1
end
$c = $c.join $separator
$c = Cast to String $c
$sel.text.replaceInRange $sel.range, $c
end
end
Re: Variable from clipboard to perl
Hi Kino
Thank you very much for solving my problem.
I guess that your macro is written in perl, isn't it?
Where can I learn more about the macro language?
regards
dakofi
Thank you very much for solving my problem.
I guess that your macro is written in perl, isn't it?
Where can I learn more about the macro language?
regards
dakofi
Re: Variable from clipboard to perl
No, no, there is no Perl code in it. Nisus Pro macro language having been enchanced a lot in NW Pro 1.1, we seldom need Perl.dakofi wrote:I guess that your macro is written in perl, isn't it?
Nisus Macro Reference.rtf you'll find in the "Read Me" folder of NW Pro dmg/zip may look somewhat difficult to understand. Unfortunately a tutorial is not available yet. I think the best way to learn it would be to write your macros by modifying macros written by others, using them as a kind of template. (My macro above is not a good example for it is a bit tricky.) Official macro repository is http://nisus.com/pro/macros/.Where can I learn more about the macro language?
Navigating in this forum, you'll be able to find other many macros posted here.
Re: Variable from clipboard to perl
Hi Kino
Thank you very much for your reply.
regards
dakofi
Thank you very much for your reply.
regards
dakofi