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

Script for converting text to shape

New Here ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

We are 3 guys working in AE and I want to set up an independent machine for rendering.

The only drawback is missing fonts breaking the renders.

 

What I want to achieve is that when any of us wants to render on remote machine:

1. Run a script that convert all text layers to shapes

2. Use watch folders

 

Part 2 is ok, but I´ve gotten stuck on the script. 

I use the AE Beta.

 

Script search through all comps in project in search for text layers to convert.

Inside a comp it executes:

1. deselect any layer

2. find a text layer that is not locked or hidden

3. create shape of text

4. deselect all layers

5. find next text layer and repeat

 

Script:

 

// Loop through all compositions in the project
for (var i = 1; i <= app.project.numItems; i++) {
  var currentItem = app.project.item(i);
  
  // Check if the item is a composition
  if (currentItem instanceof CompItem) {
    var textLayerFound = false;
    
    // Loop through all layers in the composition
    for (var j = 1; j <= currentItem.layers.length; j++) {
      var currentLayer = currentItem.layers[j];
      
      // Deselect all layers
      for (var k = 1; k <= currentItem.layers.length; k++) {
        currentItem.layers[k].selected = false;
      }
      
      // Check if the layer is a visible, unlocked text layer
      if (currentLayer instanceof TextLayer && currentLayer.enabled && !currentLayer.locked && !textLayerFound) {
        app.beginUndoGroup("Convert Text to Shape");
        
        // Select the text layer
        currentLayer.selected = true;
        
        // Execute the code to duplicate and convert the layer
        app.executeCommand(3781); // Convert to Shape
        
        app.endUndoGroup();
        
        textLayerFound = true;
      }
    }
  }
}

 

 

So far it´s converting first text layer, but only in the comp that´s active. If the active comp got more thn one text layer, only the first is converted.

 

All help appreciated!

TOPICS
Scripting

Views

1.1K

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

Enthusiast , Aug 10, 2023 Aug 10, 2023

I'm not sure what you were trying to do with textLayerFound, but of course once you have found one you specifically lock it out from converting any more layers by checking !textLayerFound. You can use .openInViewer() to open a comp, which you will need to do as any executeCommand just mimics a manual user interaction so requires everything to be arranged just like it would be if done manually.

 

I've also made it so it instead tests if any text layer has been converted in order to start a single u

...

Votes

Translate

Translate
Enthusiast ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

I'm not sure what you were trying to do with textLayerFound, but of course once you have found one you specifically lock it out from converting any more layers by checking !textLayerFound. You can use .openInViewer() to open a comp, which you will need to do as any executeCommand just mimics a manual user interaction so requires everything to be arranged just like it would be if done manually.

 

I've also made it so it instead tests if any text layer has been converted in order to start a single undo group then know at the end if that happened and it needs to close the group. And I moved the variable declarations to the start just to avoid you repeatedly declaring j and k on subsequent loops.

var i, j, k;

var startedUndo = false;

// Loop through all compositions in the project
for (i = 1; i <= app.project.numItems; i++) {
	var currentItem = app.project.item(i);
	
	// Check if the item is a composition
	if (currentItem instanceof CompItem) {

	  currentItem.openInViewer();
	  
	  // Loop through all layers in the composition
	  for (j = 1; j <= currentItem.layers.length; j++) {
		
		var currentLayer = currentItem.layers[j];
		
		// Deselect all layers
		for (k = 1; k <= currentItem.layers.length; k++) {
		  currentItem.layers[k].selected = false;
		}
		
		// Check if the layer is a visible, unlocked text layer
		if (currentLayer instanceof TextLayer && currentLayer.enabled && !currentLayer.locked) {

		if (!startedUndo) {
			app.beginUndoGroup("Convert Text to Shape");
			startedUndo = true;
		}
		  
		  // Select the text layer
		  currentLayer.selected = true;
		  
		  // Execute the code to duplicate and convert the layer
		  app.executeCommand(3781); // Convert to Shape

		}
	  }
	}
  }
  if (startedUndo) app.endUndoGroup();

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
New Here ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

Thanks so much Paul!!!

Your version made the script do EXACTLY as I wanted 🙂

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
Adobe Employee ,
Aug 12, 2023 Aug 12, 2023

Copy link to clipboard

Copied

The recently released property now in Beta app.fonts.missingOrSubstitutedFonts may be helpful to at least know that a font is missing.

 

Douglas Waterfall

After Effects Engineering

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
Enthusiast ,
Aug 12, 2023 Aug 12, 2023

Copy link to clipboard

Copied

app.fonts? That's amazing! You've added my entire feature request from a month ago?

Is there some other way I might have found out about that rather than simply your chance post here?

Very excited as I have plans for this!

Paul

 

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
Adobe Employee ,
Aug 12, 2023 Aug 12, 2023

Copy link to clipboard

Copied

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
Enthusiast ,
Aug 12, 2023 Aug 12, 2023

Copy link to clipboard

Copied

LATEST

It seems I wasn't subscribed to those particular forums!?! Fixed that. Thanks.

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