• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

Remove one condition from paragraph

Contributor ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

Given a paragraph with conditions {a, b, c, d} applied to some words and the condition {e} applied to the entire paragraph: is there a command to remove the condition {e} without removing those applied to words?

TOPICS
Scripting

Views

250

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , May 03, 2024 May 03, 2024

@Eugene Tyson , @Nick Passmore , @Laubender , @tobias.wantzen 

Thank you guys!

Even if none of these script is perfect, they put me in the right direction:

 

tell application id "InDn"
	
	set theConditions to name of conditions of active document
	set condToClear to condition "relectureWord" of active document
	
	repeat with aCondition in theConditions
		if (every text style range of selection whose name of applied conditions contains aCondition) ≠ {} then
			set theFound to object reference of (eve
...

Votes

Translate

Translate
Community Expert ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

I don't follow your train of thought here - are you talking about conditional text?
I don't understand

Can you give a broader context with an example?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

zeRafio_0-1714566535958.png

In the example above you can see that some words have (each one) a different condition applied on it. [conditions = contitional text]

Plus, the entire paragraph has an other condition applied (the sinusoidal underline).

I want to remove the sinusoidal condition from the paragraph (the condition named "relectureWord") while keeping the 5 other applied to words.

(Not sure I'm much more understanable!)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

Hi @zeRafio:

 

Select the entire paragraph and uncheck relectureWord in the Conditional Text panel. 

 

~Barb

 

2024-05-01_17-54-16 (1).gif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

My appologies. I forgot to mention that I was asking for a scripting solution in applescript or extendscript. The post is tagged but it's not obvious, I can see.

In both languages, there's a command to 'apply' a condition, another to 'delete' a condition at the document level, but there's not to 'remove' an applied condition among others.

So I'm inquirering for a method to do by script what you're suggesting using the interface.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

It's not clear what you're asking - you mean something like this?
I have no idea if this works or not - probably not - but you can let us know

Without a sample file with context it's impossible to troubleshoot the script. 

// Iterate through each paragraph in the document
for (var i = 0; i < app.activeDocument.stories.length; i++) {
    var story = app.activeDocument.stories[i];
    var paragraphs = story.paragraphs;
    
    for (var j = 0; j < paragraphs.length; j++) {
        var paragraph = paragraphs[j];
        
        // Check if the paragraph has the condition applied
        if (paragraph.appliedConditions.itemByName("relectureWord").isValid) {
            // Remove the condition
            paragraph.appliedConditions.itemByName("relectureWord").remove();
        }
    }
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

I think it may be the case that you cannot remove one condition among many but have to re-apply the conditions minus the one you want to remove. The dictionary is a bit opaque. This is a brute force example in AppleScript that does this character by character. It seems to work but it would not be quick on a large body of text. You have to select all the text first.

 

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

-- Select all the text to be processed
tell application id "InDn"
	tell document 1
		set c to (condition "relectureWord")
		set x to (a reference to (item 1 of the selection))
		repeat with i from 1 to count of characters of x
			try
				set AC to (get applied conditions of character i of x)
				set NC to {}
				repeat with f from 1 to count of items of AC
					if item f of AC is not c then
						set NC to NC & (item f of AC)
					end if
				end repeat
				set applied conditions of character i of x to NC
			end try
		end repeat
	end tell
end tell

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

Hi @zeRafio ,

well, if you remove a condition you will remove it from the document.

Not only from the text where you applied it:

app.documents[0].conditions.itemByName( "relectureWord" ).remove();

 

FWIW: If you remove condition "relectureWord" from the document the condition is also removed from the text in that document. But I assume you need to do that on a case-by-case basis, so you need more code.

 

Two ideas:

[1] You could move text out to a new document, remove the condition there and move the text back in to the original document.

 

Note, in the code below that is working on selected text, I used parent instead of parentStory for variable sourceStory, because I'd like to make the code also work on selected text in a table cell. For text in a table cell, parent returns all the text of the cell; parentStory returns the story where the table is.

 

// Name of the condition we want to remove from selected text
// and NOT from the document!

var nameOfCondition = "relectureWord";

// Text selected:
var formattedText = app.selection[0];
var sourceStory = formattedText.parent;

var ind = app.selection[0].insertionPoints[0].index;

var tempDoc = app.documents.add();
var temptextFrame = tempDoc.textFrames.add();

formattedText.move( LocationOptions.AT_BEGINNING , temptextFrame.parentStory );

tempDoc.conditions.itemByName( nameOfCondition ).remove();
temptextFrame.parentStory.texts[0].move( LocationOptions.AT_BEGINNING , sourceStory.insertionPoints[ind] );

tempDoc.close( SaveOptions.NO );

 

[2] Or you could work with text style ranges instead of characters and apply an appropriate array of conditions to a given text style range. All applied conditions minus the one you'd like to remove from the text.

Note, that a text style range could easily extend a selection of characters.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

Hi @zeRafio ,

also look into this thread from 2011 where this is discussed at length:

 

Returning a conditional text value.
Trevor:, Aug 02, 2011
https://community.adobe.com/t5/indesign-discussions/returning-a-conditional-text-value/td-p/3637111

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

Based on Uwe's suggestion to look at text style ranges, here's a much quicker AppleScript version.

 

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

-- Select all the text to be processed
tell application id "InDn"
	tell document 1
		set c to (condition "relectureWord")
		set x to (a reference to (item 1 of the selection))
		set TSRs to (every text style range of x)
		repeat with i from 1 to (count of items of TSRs)
			set NextRange to (a reference to (text style range i of x))
			set AC to (get applied conditions of NextRange)
			set NC to {}
			repeat with f from 1 to count of items of AC
				if item f of AC is not c then
					set NC to NC & (item f of AC)
				end if
			end repeat
			set applied conditions of NextRange to NC
		end repeat
	end tell
end tell

  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

LATEST

@Eugene Tyson , @Nick Passmore , @Laubender , @tobias.wantzen 

Thank you guys!

Even if none of these script is perfect, they put me in the right direction:

 

tell application id "InDn"
	
	set theConditions to name of conditions of active document
	set condToClear to condition "relectureWord" of active document
	
	repeat with aCondition in theConditions
		if (every text style range of selection whose name of applied conditions contains aCondition) ≠ {} then
			set theFound to object reference of (every text style range of selection whose name of applied conditions contains aCondition)
			repeat with aFound in theFound
				set condApplied to applied conditions of aFound
				set condToKeep to {}
				repeat with aCond in condApplied
					if contents of aCond ≠ condToClear then set end of condToKeep to contents of aCond
				end repeat
				apply conditions aFound using condToKeep with remove existing
			end repeat
		end if
	end repeat
end tell

 

This snippet is part of a script that loops through selected paragraphs. Be careful if you use it "as is": the text style ranges will not necessarily stop at the end of the selection...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines