// Detatch Text from Path
// Nathaniel Vaughn KELSO
// 2007.July.10 
// at Hyattsville, MD
// Version 0.4
// DESC: Takes a path type and extracts the text and turns into point type
// TODO: Extend to work with text on a line (PATHTEXT)

// Inspired by version 0.2
// (c) vd [vd(kot)online.com.ua]


if(documents.length > 0) {
	doc = activeDocument;
	mySelection = activeDocument.selection;

	// If there are enough to process
	if (mySelection instanceof Array)

	// For each of the selected items
	for(i=0; i<mySelection.length; i++)
	// That are textFrames
	if (mySelection[i].typename == "TextFrame" && mySelection[i].kind == TextType.PATHTEXT) {
		obj = mySelection[i];
		objTop = obj.top;
		objLeft = obj.left;

		// Make the new point type object and locate it
		copy1 = obj.parent.textFrames.add();
		copy1.left = objLeft;
		copy1.top = objTop;

		// And keep it selected for after the script runs
		copy1.selected = true;

		// Run thru the lines
		// TODO: What about text that is not visible on the line?!
		for(j=0;j<obj.lines.length;j++) {
			frame = obj.lines[j];
			// If there is more than one line add a char return
			// TODO: Does this mess with formating to be Paragraph?
			if(j>0) copy1.paragraphs.add("");
			frame.duplicate(copy1);
		}
		
		var myPathPoints = obj.textPath.pathPoints.length;
//		copy1.contents += myPathPoints;
//		copy1 = obj.parent.textFrames.add();
//		var dupPathRef = obj.textPath.duplicate();
//		obj.remove();
		obj.textRange.remove();
	}
}