Copy link to clipboard
Copied
Why do I get the error "TextFrame is undefined" when for instance a shape selected?
var doc = app.activeDocument;
var textRef = doc.selection[0]; // assume text frame is selected
alert(textRef.typename);
if (!(textRef instanceof TextFrame)) {
return;
}
TextFrame est considéré comme une variable dans votre script.
// JavaScript Document
var doc = app.activeDocument;
var objRef = doc.selection[0]; // assume text frame is selected
if (objRef.typename == "TextFrame") {
alert("Text found");
}
else alert(objRef.typename);
Copy link to clipboard
Copied
TextFrame est considéré comme une variable dans votre script.
// JavaScript Document
var doc = app.activeDocument;
var objRef = doc.selection[0]; // assume text frame is selected
if (objRef.typename == "TextFrame") {
alert("Text found");
}
else alert(objRef.typename);
Copy link to clipboard
Copied
var doc = app.activeDocument;
var textRef = doc.selection[0]; // assume text frame is selected
if (textRef.constructor == TextFrame) {
alert("It is a textframe");
}
Copy link to clipboard
Copied
Hi @Charu Rajput, when I refer to `TextFrame` in the example you give, I get the same error as @andyf65867865, but only if I launch the script from Illustrator—if I launch it from VSCode debugger it works fine. My sample code is:
(function () {
var textRef = app.activeDocument.selection[0];
if (textRef.constructor === TextFrame)
alert('yes');
else
alert('no');
})();
So this code gives error if run from Illustrator, but not from VSCode debugger. Is your experience different? I am on MacOS 15.0 (AI 28.7.1).
Anyway, the idiom I use these days is almost always
if (textRef.constructor.name === 'TextFrame')
I prefer this to `typename` because I can use it with non-DOM objects, eg. Array. (Only Illustrator's objects have a `typename`.)
- Mark
Copy link to clipboard
Copied
the same question was asked here
Find more inspiration, events, and resources on the new Adobe Community
Explore Now