NISUS Archives

May 2011

NISUS@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Philip Spaelti <[log in to unmask]>
Reply To:
Date:
Wed, 1 Jun 2011 00:07:20 +0900
Content-Type:
text/plain
Parts/Attachments:
text/plain (44 lines)
Hello Žorvaršur,

what you you want to do is actually surprisingly simple. Replace the $startNumber = Prompt… line with the following:

$doc = Document.active
$howManyRows = $doc.tableSelection.rowRange.length

Now *if* you start the macro with a selection covering a few table rows, then your macro will insert numbers, starting from your desired input.

Note that I said *if*. The macro at that point will not have any security whatsoever, and I am not going to try to predict what may all go wrong. Generally what you would want to do is to first check if anything is selected, and take appropriate precautions if things are not right. If you look at the macros Kino writes you will see some very good models of how that should be done. As is stands now your macro is of the "Quick and Dirty" variety. Personally I often write things that way myself. But "User Beware!"

best
philip

PS: You can turn the above into something more secure if you write it like this

$doc = Document.active
if $tblSel = $doc.tableSelection
	$howManyRows = $tblSel.rowRange.length
else
	exit “No table selected”
end

In that case you would probably want to put this first in the macro, before the first dialog.


On 31. May 2011, at 17:41 , Žorvaršur Davķšsson wrote:

> I would like to highlight the cells by dragging the mouse over them in the beginning and let NWP determine where the first cell is and how many cells were highlighted, but I don’t know how to do that yet. Perhaps somebody can do that.
> 
> 
> BEGINNING OF MACRO
> 
> $startNumber = Prompt Input 'Enter a number to start with…'
> # This is the cell where you start and refers to the number you want to begin with. 
> 
> 
> $howManyRows = Prompt Input 'How many rows should be involved?' 
> # Much better would be to highlight the part by dragging the mouse over the cells and let NWP determine the number. I don't know how to do that yet.
> 

Philip Spaelti
[log in to unmask]

ATOM RSS1 RSS2