Can't set the value of textItem.contents - extendscript

I am trying to write a script that will update the value of a text layer in Photoshop.
I have a layer stored in a variable myLayer which I log out so I know it is an ArtLayer with a type of LayerKind.TEXT and has a textItem object associated that has a string value in place. All as I would expect.
The documentation says that textItem.contents is read-write so I thought myLayer.textItem.contents = "Hello World" should update the value but when I try this I get General Photoshop Error occurred. This functionality might not be available in this version of Photoshop.
Can anyone advise on what I'm missing?
I am using Photoshop CC 2014 and the CC 2014 Javascript Reference
Thankyou in advance for you help :)

Its hard to see whats going wrong when there is no code example. This works for me.
Tested in PS CC 2014 Mac OSX
// needs a Photoshop document with only one textlayer
var d = app.activeDocument;
var l = d.artLayers[0];
if(l.hasOwnProperty ("textItem")){
$.writeln("yes");
l.textItem.contents = "Hello World";
}

This works in CS2: (Assuming the active layer (mylayer) is a text layer)
var srcDoc = app.activeDocument;
var myLayer= srcDoc.activeLayer;
var text = myLayer.textItem.contents;
myLayer.textItem.contents = "Hello World";

Related

Rich Text Box *Formatting

Language: C#
My Question...
Q. Is there a SIMPLE way to change the format of strings in the rich text box, similar the way you handle it with HTML.
For example:
richTextBox1.text = "[i]Hello[/i] [Bold]world![/Bold]";
output: Hello World!
I am also wondering if there is colour?
With kind regards and thank in advance for your feedback.
Rich Text Format is a language in and of itself. However, you don't need to learn it to use it.
However, there are other ways this can be accomplished that might be more practical, like so:
RichTextBox1.Text = "Hello World"
' Select Hello and Bold It
RichTextBox1.Find("Hello")
Dim fntBold As New Font(RichTextBox1.Font, FontStyle.Bold)
RichTextBox1.SelectionFont = fntBold
' Select World and Set to Italics
RichTextBox1.Find("World")
Dim fntItalic As New Font(RichTextBox1.Font, FontStyle.Italic)
RichTextBox1.SelectionFont = fntItalic
Afterwards, if you are curious, you can look at RichTextBox.Rtf property (it's a string) to see what it looks like. This is what I saw after I did it:
{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}\viewkind4\uc1\pard\lang1033\b\f0\fs17 Hello\b0 \i World\i0\par}
In fact, if you then take that text, open Notepad, copy the Rtf property's text, save as an RTF file. Close down Notepad and open the RTF in Word, you'll see this same same text with the same look and feel.
Hi and thank's so much #Ctznkane525, thanks for putting me on the right track, I did convert it to C# and this is the outcome:
using System.Drawing.Text;
rtb_Main.Text = "Hello World";
rtb_Main.Find("Hello");
Font fntBold = new Font(FontFamily.GenericSansSerif, 14.0F, FontStyle.Bold);
rtb_Main.SelectionFont = fntBold;
rtb_Main.Find("World");
Font fntItalic = new Font(FontFamily.GenericSansSerif, 14.0F, FontStyle.Italic);
rtb_Main.SelectionFont = fntItalic;

Filling a buffer with emptiness

How can I fill a buffer with emptiness?
This was working on v0.10.*:
var b = new Buffer(8192);
b.fill("");
But it just crashes without any error on v0.11.11.
I have this code:
var b = new Buffer(8192);
b.fill("");
console.log(1);
When I run it, 1 doesn't appear in output. What alternatives are to fill a buffer with emptiness?
Originally I suggested new Buffer(Array(32)), but we determined b.fill(0) was a workable solution.

Python 3.x Tkinter, Entry field issue?

Pastebin - My Full Code
I have an issue with my program that effects my entry fields.
With my password entry it works great, the input is stored to a StringVar and can be used to test whether it has been entered correctly.
When users enter an email address or new password in the admin settings page it doesn't work, the text variable is always null.
If you could help that would be much appreciated as this is going towards an important qualification.
Problematic Areas:
Change Function
#Function that changes the system email address
def ChangeEmail(page):
global field_ChangeEmail
newEmail = field_ChangeEmail.get()
field_ChangeEmail.set('')
print(newEmail)
settingsDB = sqlite3.connect('Settings.db')
action = ("UPDATE ADMIN_SETTINGS set SYSTEM_EMAIL = '" + newEmail + "' where ID=1")
settingsDB.execute(action)
settingsDB.commit()
settingsDB.close()
Entry Field
global field_ChangeEmail
entry_ChangeEmail = tk.Entry(page, textvariable = field_ChangeEmail, justify = CENTER, fg = settings_EntryFontColour, font = settings_EntryFont)
widthRatio = settings_AS_Column03Width
heightRatio = settings_AS_RowHeight
relativeX = settings_AS_Column03RelX
relativeY = settings_AS_Row01RelY - 0.0009
entry_ChangeEmail.place(width=screenWidth*widthRatio, height=screenHeight*heightRatio, relx=relativeX, rely=relativeY, x=-((screenWidth*widthRatio)*0.5), y=-((screenHeight*heightRatio)*0.5))
There is nothing wrong with the code you posted, though your use of place and variables for sizing is very, very odd. I strongly encourage you to learn about pack or grid, it will make your GUI much, much easier to get right, and to maintain it over time. Place should never be used except when neither of the other two will work.
That being said, when I run the above code, and add a little extra to make it work, it works fine. ChangeEmail prints out the value that is in the entry widget, then clears the entry widget by setting the variable to an empty string. I assume that's what it's supposed to do.
If the text variable is getting set to null (None?), that is happening in some other part of your code.

Populate iTextSharp pdf with database values

I have this code below and trying to populate my pdf with values from the database.
PdfPCell points = new PdfPCell(new Phrase("and is therefore entitled to ", arialCertify));
points.Colspan = 2;
points.Border = 0;
points.PaddingTop = 40f;
points.HorizontalAlignment = 1;//0=Left, 1=Centre, 2=Right
// code below needs attention
var cID = "ALFKI";
var xw = Customers.First(p => p.CustomerID ==cID);
table.AddCell(xw.CompanyName.ToString());
I can not figure out where I am going wrong. When I remove the code under 'code below needs attention' it works but I need the database values.
I am using webmatrix with ItextSharp. If to answer you need further code please let me know.
PdfPCell cell=new PdfPCell(new Phrase(xw.CompanyName.ToString()));
cell.setColspan(numColumns);
table.addCell(cell);
document.add(table);

Adding content control throws an exception dynamically

I am fairly new to Word Addin development. Fortunately I was able to do almost everything but stuck at some simple issue I belive.
I want to insert plain text controls dynamically at the selected range. For this I am using the following:
currentDocument = application.ActiveDocument;
foreach(var field in myFieldsList)
{
Microsoft.Office.Interop.Word.Range rng = currentDocument.ActiveWindow.Selection.Range;
object oRng = rng;
var contentControlPlain = application.ActiveDocument.ContentControls.Add(Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlText, ref oRng);
contentControlPlain.Tag = formField.FormFieldId.ToString();
contentControlPlain.SetPlaceholderText(null, null, " <" + formField.FormFieldName + "> ");
contentControlPlain.LockContentControl = (formField.TypeName.Trim() == "Blank");
}
Code seems to be working fine but when I try to insert the second field it complains saying:
This method or property is not available because the current selection partially covers a plain text content control.
I understand that addin is trying to insert next content control into the previously inserted plain text control. But I tried giving some other range and could not fix it.
Any help is greatly appreciated.
Thanks.
After adding every content control use
Application.Selection.Start = lastControl.Range.End+1

Resources