Page 1 of 1

Can dynamic list numbers be transformed into ordinary text?

Posted: 2010-09-23 04:51:20
by js
Can dynamic list numbers be transformed into ordinary text? Or had one better use a macro to put running numbers in front of each paragraphs? In fact I seem to remember that earlier versions of Nisus did come with such a macro.

Re: Can dynamic list numbers be transformed into ordinary text?

Posted: 2010-09-23 08:48:33
by martin
js wrote:Can dynamic list numbers be transformed into ordinary text?
There's no built-in command for this, but the following macro transforms all list items/bullets in your document to fixed/ordinary text:

Code: Select all

Select Document End
While Select Previous List Item
	$selection = TextSelection.active
	$bullet = $selection.substring
	Write Selection $bullet
End
You could also get the following idea working:
Or had one better use a macro to put running numbers in front of each paragraphs?
But perhaps your first idea is more convenient?

Re: Can dynamic list numbers be transformed into ordinary text?

Posted: 2010-09-23 12:29:12
by js
I find that by putting "Lists:Number list" (so that the macro works directly from a Selection of paragraphs), this is extremely fast and convenient. Thank you.

Re: Can dynamic list numbers be transformed into ordinary text?

Posted: 2010-09-23 13:16:32
by greenmorpher
Can we clarify this? I tried the macro and got page full of numbers both when I ran it on unsdelected text and when I ran it on selected text! It was duplicating the second level -- numbers, not the text of the head.

Cheers, Geoff

Geoffrey Heard
Publisher, Editor, Business Writer
The Worsley Press

FREE Bonus book offer. Get "How to make great ads for (sm)all business" FREE when you buy "Type & Layout: Are you communicating or just making pretty shapes?" or "How to Start and Produce a Magazine or Newsletter". Amazon or www.worsleypress.com

Re: Can dynamic list numbers be transformed into ordinary text?

Posted: 2010-09-24 06:34:46
by Kino
Geoff, I reproduced the problem by running the macro on your Outline.dot.
http://nisus.com/forum/viewtopic.php?p=16788#p16788
What magic did you use? -;) I don’t understand why your template makes misbehave Martin’s macro. Anyway, if you need such a macro right now, try this one.

Code: Select all

$doc = Document.active
if $doc == undefined
	exit
end

$sels = $refs = Array.new
foreach $text in $doc.allTexts
	$i = 0
	while $i < $text.length
		$attr = $text.displayAttributesAtIndex $i
		$range = $text.rangeOfDisplayAttributesAtIndex $i
		if Defined $attr.listStyle
			$sel = TextSelection.new $text, $range
			$sels.appendValue $sel
		end
		$i = $range.bound
	end
end

if ! $sels.count
	exit 'No list found, exiting...'
end

foreach $sel in $sels
	$founds = $sel.subtext.findAll '^[^\t]+(?=\t)', 'E'
	foreach $found in $founds
		$range = $found.range
		$range.location += $sel.location
		$ref = TextSelection.new $sel.text, $range
		$refs.appendValue $ref
	end
end

foreach $ref in reversed $refs
	$ref.text.replaceInRange $ref.range, $ref.substring
end
This one relies on tabs following numbers/bullets for there seems to be no other way to get List Items, regardless of the activeness of the document. I’d like to have something equivalent to Note object commands for Lists.

Edit: I forgot to write this: When I was writing the macro above, I was believing that you had touched the document while Martin’s macro was running. So, I wrote it so that it works properly even if the target document has become inactive. But the problem seems to be elsewhere.

Edit: This one may be faster. Select Previous List Item does not seem to be the culprit. Perhaps is Write Selection too slow or does it make misbehave Select Previous List Item?

Code: Select all

$doc = Document.active
$sels = Array.new
Select Document End
while Select Previous List Item
	$sel = TextSelection.active
	$sels.appendValue $sel
end
foreach $sel in $sels
	$sel.text.replaceInRange $sel.range, $sel.substring
end
Edit: This another one seems to work properly on Outline.dot too.

Code: Select all

Select Document End
while Select Previous List Item
	$sel = TextSelection.active
	$sel.text.replaceInRange $sel.range, $sel.substring
end
Edit: Perhaps does Write Selection fail to replace an existent attribute with a new one in some situations?

Re: Can dynamic list numbers be transformed into ordinary text?

Posted: 2010-09-24 11:32:58
by martin
The problem with using the macro on Geoff's template is that his list items are enforced via a paragraph style. When the macro replaces those list items with plain string list numbers, it does not clear NWP's desire to enforce the paragraph style, and thus the list style as well.

The solution is for the macro to tell NWP that the list style should be explicitly turned off for the paragraph (ie, override the paragraph style):

Code: Select all

Select Document End
While Select Previous List Item
	$selection = TextSelection.active
	$bullet = $selection.substring
	Menu 'Lists:Use None'
	Write Selection $bullet
End

Re: Can dynamic list numbers be transformed into ordinary text?

Posted: 2010-09-27 02:36:47
by greenmorpher
thanx Kino & Martin

Cheers, Geoff

Alternative script using Copy & Paste

Posted: 2010-10-19 21:21:02
by Bob Stern
The following script also seems to work. Like Geoff, I have a list style associated with the paragraph style. However, for some reason, pasting plain text seems to change the list style to None without the "Menu 'Lists:Use None' command in Martin's script. Is Martin's last script a more reliable approach than my Copy/Paste?

Code: Select all

# Move to end of document
Select Document End

# Convert all list numbers (list bullets) to plain text.
# Go backwards so numbering doesn't change as we progress.
While Select Previous List Item
	Copy Text Only
	Paste Text Only
End