Reply to topic  [ 5 posts ] 
Variable from clipboard to perl 
Author Message

Joined: 2003-02-07 07:48:35
Posts: 17
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


2008-08-27 01:27:03
Profile

Joined: 2008-05-17 04:02:32
Posts: 400
dakofi wrote:
Find and Replace ‘([[:digit:]]+)\-([[:digit:]]+)’, ‘\1\2’, ‘aEU’ #Bis-Nummer suchen
Begin 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.
Code:
 # 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


2008-08-27 05:30:18
Profile

Joined: 2003-02-07 07:48:35
Posts: 17
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


2008-08-28 00:11:24
Profile

Joined: 2008-05-17 04:02:32
Posts: 400
dakofi wrote:
I guess that your macro is written in perl, isn't it?

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.
Quote:
Where can I learn more about the macro language?

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/.
Navigating in this forum, you'll be able to find other many macros posted here.


2008-08-28 03:07:23
Profile

Joined: 2003-02-07 07:48:35
Posts: 17
Hi Kino

Thank you very much for your reply.

regards

dakofi


2008-08-28 04:24:07
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software