M.Hasanin
Enthusiast
M.Hasanin
Enthusiast
Activity
Feb 07, 2025
12:39 PM
great solutions!, also you can try the following script (Apply Language to Document v1.2.8): https://hasaninscripts.com/l/bzcgc
... View more
Dec 29, 2024
12:03 PM
Hi @dublove try this : DoConvert();
function DoConvert(){
var myTable = app.selection[0]; // Get the selected top cells
var myRows = myTable.rows; // Get all table rows in selection
// Loop through each row in the table
for (var i = 0; i < myRows.length; i++) {
// Check if the row is a body row and convert it to a header row
if (myRows[i].rowType === RowTypes.BODY_ROW) {
myRows[i].rowType = RowTypes.HEADER_ROW;
}
}
alert("Body rows converted to header rows successfully.");
}
... View more
Feb 03, 2024
06:30 AM
@Robert at ID-Tasker Thanks a lot, i fix it now
... View more
Feb 03, 2024
05:46 AM
@Robert at ID-Tasker Hi Robert, no it just short name, my full name is Mohammed Hasanin, but i write it in shorten form M.Hasanin
... View more
Feb 03, 2024
03:33 AM
Hi @Suburban L&G as i understand from you, you cant apply the previos script to your project, actually, to apply correctly the object styles , the old script assume that the exact content are inside the text frame and also object style name is exactly as content so if the textframe content is "RED" , also object style name must be "RED" but in the following new version of the script you can Apply the Object Style from the array if the script found any (Index of) content in the same array, this will much easier if the text frame loaded with many text : //Apply Object Style to TextFrame Based on Content v2.0
//Created By M.Hasanin
app.doScript(ApplyOSTextFrames, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Apply Object Style Based on Content");
function ApplyOSTextFrames() {
var myDoc = app.documents[0];
var myFrames = myDoc.textFrames.everyItem().getElements();
for (var n = 0; n < myFrames.length; n++) {
var frameContent = myFrames[n].contents.toLowerCase(); // Convert the content to lowercase for case-insensitive matching
// Define the color keywords and their corresponding object style names
var colorStyles = {
"red": "RED",
"blue": "Blue",
"green": "GREEN"
// Add more color keywords and object style names as needed
};
// Iterate through the color keywords and check if the frame content contains any of them
for (var colorKeyword in colorStyles) {
if (frameContent.indexOf(colorKeyword) !== -1) {
var objectStyleName = colorStyles[colorKeyword];
// Check if the object style exists in the document
if (myDoc.objectStyles.itemByName(objectStyleName).isValid) {
myFrames[n].applyObjectStyle(myDoc.objectStyles.itemByName(objectStyleName));
}
}
}
}
} so you have to add any keywords that are might to be contained in the text frames like (red, blue, green) as example then you can deterimine the Object Style Name, so as example if the text frame contains the statement "in the red" it will apply RED object style to the textframe and so on, so i think this version might solve your problem.
... View more
Aug 23, 2023
09:50 PM
Hi @Peter Kahrel thank you, your updated script very good for one hit reversing, but using character direction is not the right choice, it reverse the characters wrongly, if you use : words[i].contents = words[i].contents.split('').reverse().join(''); it will work but will swap the locations of word, so simple table will be table simple, etc also in arabic
... View more
Aug 23, 2023
09:29 PM
@m1b Hi mark, Thank you, actually the broken characters caused because of the InDesign Plugin PDF2ID also Alternative Plugin MARKZWARE Cause Same Problem, so the editor will need to fix it manually after reversing the text.
... View more
Aug 20, 2023
06:09 PM
Hi @Robert at ID-Tasker Actually, this is very good Question, now try the following simple script : words = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().texts.everyItem().words.everyItem().getElements();
for (var i = words.length-1; i >= 0; i--) {
words[i].contents = words[i].contents.split('').reverse().join('');
} the previous will work with latin/English but not with Arabic, it shouid simply do what the complicated script done!, but unlucky this is not true!, look at the wrong results here (Before/After): The Results is not correct , the words in wrong direction (المهام جدول) it must be (جدول المهام) also (تجربة هذه) must be (هذه تجربة) to be in the correct direction! now look for the results for my complicated script!, that will correctly make the right direct for the letters (Before/After) : Try it your Self , here is link to download test project : https://mega.nz/file/Kjh0FLCK#ehO8wDxKH9wD38EViit-RtJq4ku4sT08DFl48YNzs5M actually i spent a lot of hours try to figure out how to solve this, maybe there are another way i didnt try it!
... View more
Aug 20, 2023
02:10 PM
Hi @r28071715i111 , here is a version for reversing text in tables cells: //Reverse Characters in All Document Tables
app.doScript(CatchMyError, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Reverse Characters in Doc Tables");
// Error Catcher for Function
function CatchMyError() {
try {
DoReverseAllTables();
} catch (myError) {
alert(myError, "ERROR!");
exit();
}
}
function DoReverseAllTables() {
//Get All Tables Table Style Apply
var myDoc = app.activeDocument;
var tables = myDoc.stories.everyItem().tables.everyItem().getElements();
// Iterate through each table in the document
for (var tableIndex = 0; tableIndex < tables.length; tableIndex++) {
var table = tables[tableIndex];
// Iterate through each cell in the table
for (var rowIndex = 0; rowIndex < table.rows.length; rowIndex++) {
var row = table.rows[rowIndex];
for (var cellIndex = 0; cellIndex < row.cells.length; cellIndex++) {
var cell = row.cells[cellIndex];
var textFrames = cell.texts; // Get the text frames in the cell
// Iterate through each text frame in the cell
for (var textFrameIndex = 0; textFrameIndex < textFrames.length; textFrameIndex++) {
var textFrame = textFrames[textFrameIndex];
var text = textFrame.contents;
// Reverse the character direction
var reversedText = reverseCharacterDirectionTables(text);
// Set the reversed text back to the text frame
textFrame.contents = reversedText;
}
}
}
}
//wait a maximum of 10 second for the active process.
app.activeDocument.activeProcess.waitForProcess(10);
alert("Character direction reversed in all tables!","Finished");
}
function reverseCharacterDirectionTables(text) {
var reversedText = "";
for (var i = text.length - 1; i >= 0; i--) {
reversedText += text.charAt(i);
}
return reversedText;
}
... View more
Aug 14, 2023
02:06 AM
@Manan Joshi Thanks , i forget to examine it correctly , thank you for the correction
... View more
Aug 13, 2023
10:54 PM
Hi! This is updated one : //Relink Unlinked TextFrames in Pages
var myDoc = app.activeDocument;
for (var i = 0; i < myDoc.pages.length - 1; i++) {
var currentPage = myDoc.pages[i];
var nextPage = myDoc.pages[i + 1];
var currentTextFrame = currentPage.textFrames[0];
var nextTextFrame = nextPage.textFrames[0];
currentTextFrame.nextTextFrame = nextTextFrame;
}
... View more
Jul 23, 2023
10:49 PM
@r28071715i111 You are welcome
... View more
Jul 23, 2023
04:17 PM
1 Upvote
Hi @m1b , your script is excellent also, thank you, very briliant idea from its base, cheers
... View more
Jul 23, 2023
04:00 PM
1 Upvote
hi @r28071715i111 , here is another version as you asked me in private message that will scale and rotate in same time : /**
* Apply Scale and Rotation to graphics script labels
* eg. if label is "r:30 s:10", then the graphic will be rotated to 30 degree and scaled to 10%
* @Originally authored by m1b for rotation version
* Updated Mixed Rotation and Scale Version By M.Hasanin
* @discussion https://community.adobe.com/t5/indesign-discussions/script-to-rotate-selected-image-inside-frame-data-merge/m-p/13955151
*/
function main() {
var doc = app.activeDocument,
tm = app.transformationMatrices.add({ counterclockwiseRotationAngle: 0 }),
images = doc.allGraphics,
matcher = /^r:(-?\d+\.?\d*)\s+s:(-?\d+\.?\d*)/i, // match both values in one regex (Rotation and Scale with Space)
label,
value1,
value2;
for (var i = 0; i < images.length; i++) {
label = images[i].label || images[i].parent.label;
if (!label)
continue;
var matches = label.match(matcher);
if (!matches || matches.length < 3) // check for both values
continue;
value1 = Number(matches[1]); // set value1 to the first match Rotate
value2 = Number(matches[2]); // set value2 to the second match Scale Percentage
images[i].transform( //Roatation
CoordinateSpaces.pasteboardCoordinates,
AnchorPoint.centerAnchor,
tm.rotateMatrix(-images[i].absoluteRotationAngle + value1),
);
images[i].horizontalScale = images[i].verticalScale = value2; //Scale Percentage
}
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Scale and Rotate Graphics');
... View more
Jul 23, 2023
03:58 PM
2 Upvotes
Hi @r28071715i111 , here is a version that will scale in percentage : /**
* Apply Scale to graphics with a "Scale" script label.
* eg. if label is "s:10", then the graphic will be scaled to 10%
* @Originally authored by m1b for roation version
* Updated Scale Version By M.Hasanin
* @discussion https://community.adobe.com/t5/indesign-discussions/script-to-rotate-selected-image-inside-frame-data-merge/m-p/13955151
*/
function main() {
var doc = app.activeDocument,
images = doc.allGraphics,
matcher = /^s:(-?\d+\.?\d*)/i,
label,
value;
for (var i = 0; i < images.length; i++) {
label = images[i].label || images[i].parent.label;
if (!label)
continue;
value = label.match(matcher);
if (!value
|| value.length < 2
|| isNaN(value = Number(value[1]))
)
continue;
images[i].horizontalScale = images[i].verticalScale = value;
}
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Scale Graphics Percent');
... View more
Jun 24, 2023
02:00 AM
2 Upvotes
Hi @ali u , the following version works smoothly, using characters[0] stop executing the script, the following tested in InDesign 2023 : //Set Diacritic Offsets Palette
#targetengine "session"
var myPalette = new Window("palette", "Move Diacritics", undefined, {closeButton: true});
var button1 = myPalette.add("button", undefined, "Left");
button1.onClick = function() {
app.activeDocument.selection[0].xOffsetDiacritic += 10
}
var button2 = myPalette.add("button", undefined, "Right");
button2.onClick = function() {
app.activeDocument.selection[0].xOffsetDiacritic -= 10
}
var button3 = myPalette.add("button", undefined, "Up");
button3.onClick = function() {
app.activeDocument.selection[0].yOffsetDiacritic += 10
}
var button4 = myPalette.add("button", undefined, "Down");
button4.onClick = function() {
app.activeDocument.selection[0].yOffsetDiacritic -= 10
}
myPalette.show();
... View more
Apr 17, 2023
02:09 PM
Thanks @Willi Adelberger , yes im cc subscriber and i will test your solution, thanks alot
... View more
Apr 17, 2023
01:38 AM
Hi @Willi Adelberger , Thanks for replying, actually i only have InDesign ME Version 18.2.1 (latest) and the publisher give me the project files to transilate but all the new textframes are in arabic and hyphenation options is off, i can work and export but everytime i open the project this message appear!
... View more
Apr 17, 2023
01:26 AM
Hi Experts! Im working in InDesign German Project need to be transilated to Arabic, when opening the original German InDesign Files this Error Show even after transilation done in InDesign ME Version : and after the transilation it still apear every time i open the arabic project done in InDesign ME Version, are there any way to stop seeing this everytime i opened my project? and thanks in advance
... View more
Apr 10, 2023
09:28 AM
@Peter Kahrel Thanks a lot, it works!
... View more
Apr 09, 2023
02:55 PM
hi experts, im using this script to get rid of arabic diacritics using grep function like this : grepSearchLL("[\\x{064B}-\\x{065F}\\x{06D2}-\\x{06ED}]", ""); but when i try similar command but using replace function it not working : myText.replace(/[\u064B-\u065F\u06D2-\u06ED]/g, ''); so please how to fix that using replace function?, and thanks in advance
... View more
Mar 21, 2023
01:45 PM
@roman__ you are welcome
... View more
Mar 17, 2023
01:04 PM
1 Upvote
@roman__ if you want to apply table styles to all tables you can try this : //Apply to Table Style to All Document Tables
var myDoc = app.activeDocument;
var tstyle = myDoc.tableStyles.itemByName("MyTableStyle");
var DocTables = app.documents[0].stories.everyItem().tables.everyItem().getElements()
for (var i = 0; i < DocTables.length; i++){
DocTables[i].appliedTableStyle = tstyle
} just Change "MyTableStyle" to your Table Style Name. if you want to target Anchored Tables Only use : //Apply to Table Style to Anchored Tables Only
var myDoc = app.activeDocument;
var tstyle = myDoc.tableStyles.itemByName("MyTableStyle");
var DocTables = app.documents[0].stories.everyItem().tables.everyItem().getElements()
for (var i = 0; i < DocTables.length; i++){
if (DocTables[i].parent.parent.constructor.name == "Character") {
DocTables[i].appliedTableStyle = tstyle
}
} for table Widths, you can try another Script, download from here : Control All Tables Columns Width Control All Tables Columns Width Script
... View more
Mar 08, 2023
05:10 AM
جرب استعمال سكريبت بيتر كارل من هنا https://creativepro.com/files/kahrel/indesign/footnotes_columns.html هنا شرح مبسط لها يجب استعمال كافة الاسكربتات الثلاثة المتوفرة في المجلد , انت يوجد عندك ثلاثة سكريبتات واحد اسمه Convert للتحويل والثاني اسمه add لللإضافة والاخير Update للتحديث, السكريبت الاول Convert يقوم فعليا بتحويل كلا من الاشارات المرجعية والحواشي المرقمة الى نص - فالاشارة ذات الرقم تأخذ ستايل حرفي ملون يمكنك تعديله ولكن لا تغير اسماء الستايلات حتى لا يختل عمل السكريبت وتحت الحاشية كما ترى يمكنك تركها مقسمه, بالنسبة لنظام الترقيم الموجود في الحواشي فهو في ستايل الفقرة على هيئة أرقام List حيث تلاحظ انك لو ازلت احد الحواشي بالارقام فيقوم انديزاين بتحديث ما قبلها او بعدها تلقائيا ولكن هذا لا يحدث في الاشارة المرجعية وهنا نأتي للوظيفة Update حيث الفكرة هي كالتالي : أولا : ستقوم باضافة كافة الحواشي في الملف الخاص بك بالكامل ثانيا : ستقوم بتشغيل السكريبت Convert الذي سيقوم بتحويل كل الاشارات المرجعية الى أرقام مرتبطة بستايل حرفي من السكريبت والحواشي المرقمة الى نصوص متسلسلة بنظام ترقيم. ثالثا : ستقوم يدويا باخفاء الحواشي التي ليس لها رقم اشارة مرجعية في الصفحة الحالية ثم تتوجه الى الصفحة التالية فتختار الاطار النصي أولا ثم لتكملة اظهار الحواشي تضغط على السكريبت add فيقوم انديزاين اوتوماتيكيا باضافة اطار نص لتكملة الحواشي وهكذا لنهاية المستند, تظهر الحواشي في الصفحة الحالية وتخفي ما هو ليس له اشارة مرجعية والسكريبت add عن اختيارك لاطار النص في الصفحة المكملة سيقوم تلقائيا باستكمال اظهار الحواشي ولو عدلت رأيك وقررت مسح اشارة مرجعية من الاطار النصي فيستلزم ذلك مسحها من اطار النص في الحواشي وبالتالي هنا يأتي دور السكريبت الثالث update حيث بعد مسح الاشارة ونصها سيقوم السكريبت بتعديل الترقيم بشكل آلي في الاشارات المرجعية. هو سهل الاستخدام لكن ربما اقوم بعمل فيديو ليفيد الجميع وارجو ان يكون الشرح هنا مبسطا الان كما ترى ارقام الحواشي يمكنك ضبطها كما تشاء وعمل المحاذاة اللازمة
... View more
Mar 05, 2023
10:22 PM
Hi @wckdtall , here the script to loop document to override all parent pages items (tested in 2023) : //Override All Document
OverrideDoc();
function OverrideDoc() {
var mA = app.menuActions.itemByName("$ID/Override All Parent Page Items");
var doc = app.documents[0];
var allDocSpreads = doc.spreads.everyItem().getElements(); //Here is Pages Range
var allDocSpreadsLength = allDocSpreads.length;
for( var n=0; n<allDocSpreadsLength; n++ ) //Loop inSide Pages Range
{
doc.layoutWindows[0].activeSpread = allDocSpreads[n]; //you can delete this, just to show process
if( mA.isValid && mA.enabled ){ mA.invoke() };
};
} note that you can use any of these and will get the same results : var mA = app.menuActions.itemByName("$ID/Override All Master Page Items"); or var mA = app.menuActions.itemByName("$ID/Override All Parent Page Items");
... View more
Mar 05, 2023
03:22 PM
Thanks alot friends! , i spent some time to squeez my mind and i figured it out, here is the loading solution, it works! load.onClick = function () {
//Remove old list items
myList.removeAll()
var filePathMinusExtension = app.activeDocument.fullName.fsName.substr(0, app.activeDocument.fullName.fsName.lastIndexOf("."));
var ReadFile = File(filePathMinusExtension + "_GREP_Queries.txt");
if (ReadFile.exists) {
try {
ReadFile.open("r");
//
var i = 0;
while (ln = ReadFile.readln()) {
var arr = ln.split(',');
with (myList.add ("item", arr[i]+"\n")){
subItems[0].text = arr[1+i]+"\n";
}
}
//Close the file
ReadFile.close();
alert("Done, the GREP Queries Loaded");
return true;
}
catch (errOpen) {
alert("Error. The GREP Queries file could not be opened!");
return false;
}
}
else{
alert("The GREP Queries file could not be found!");
return false;
}
}
... View more
Mar 05, 2023
02:01 PM
Hi All Now i discovered a solution to remove the items from the list box from trail from error, and it works! for removing item and subitem : //delete selected item
del.onClick = function () {
//Remove Items
myList.remove(myList.selection.text);
myList.remove(myList.selection.subItems[0].text);
}
... View more
Mar 04, 2023
03:23 PM
Thanks @Loic.Aigon for your reply, here is a screen shot to clarify concept, see here (the yellow buttons) are attached with the funciton (onClick) those Buttons linked to funcitons (Delete Grep Query) not working also (Load Grep Queries) not working also so this function not working (Delete GREP Query) : //delete selected item
del.onClick = function () {
// remember which line is selected
var sel = myList.selection[0].index;
for (var i = myList.selection.length-1; i > -1; i--)
myList.remove(myList.selection[i]);
// select a line after deleting one or more items
if (sel > myList.items.length-1)
myList.selection = myList.length-1;
else
myList.selection = sel;
} also this function not working (Load GREP Query) : //Load List Items and Show them
load.onClick = function () {
//Remove old list items
myList.removeAll()
var filePathMinusExtension = app.activeDocument.fullName.fsName.substr(0, app.activeDocument.fullName.fsName.lastIndexOf("."));
var ReadFile = File(filePathMinusExtension + "_GREP_Queries.txt");
if (ReadFile.exists) {
try {
ReadFile.open("r");
while (ln = ReadFile.readln()) {
myList.add("item", ln);
}
//Close the file
ReadFile.close();
alert("Done, the GREP Queries Loaded");
return true;
}
catch (errOpen) {
alert("Error. The GREP Queries file could not be opened!");
return false;
}
}
else{
alert("The GREP Queries file could not be found!");
return false;
}
} these functions need to be modified to work with multi columns listbox, i hope this clear and thanks again for help
... View more
Mar 04, 2023
08:33 AM
Hi Experts its just very tiny tool for saving GREP Queries, previously @Manan Joshi helped me in creating it , now i add a title using multi columns lisbox in script UI so every grep query to be saved with its own title!, i try to change tha code , i succeeded only in modifying inserting and saving function but i stucked in the Load and Delete functions, i still learning javascript so i get stucked from time to time! , i apperciate any help to make those functions works and thanks in advance : var w = new Window ("dialog");
var myList = w.add ("listbox", undefined, " ",
{numberOfColumns: 2, showHeaders: true, columnTitles: ["GREP Name", "GREP Formula"]});
//MyListSize
myList.maximumSize.height = 1000;
myList.maximumSize.width = 1000;
myList.minimumSize.width = 1000;
//GREP Name
var StaticaName = w.add("statictext", undefined,"GREP Name");
StaticaName.alignment = "Left";
var myname = w.add ("edittext");
myname.active = true;
myname.characters = 100;
//GREP Formula
var StaticaGREP = w.add("statictext", undefined,"GREP Formula");
var input = w.add ("edittext");
StaticaGREP.alignment = "Left";
input.active = false;
input.characters = 100;
//-----------------------------------------------------------------------------------//
//Buttons Group 1
//-----------------------------------------------------------------------------------//
var gqmButtonGroup1 = w.add ('group {orientation: "row"}');
gqmButtonGroup1.alignChildren = "fill";
//GQMButtonGroup1.alignment = "stack";
//------------------------------------------------------------------------------------//
var inserttxt = gqmButtonGroup1.add ("button", undefined, " Insert GREP Query", {name: "Insert"});
var del = gqmButtonGroup1.add ("button", undefined, " Delete GREP Query", {name: "Delete"});
var gqmButtonGroup2 = w.add ('group {orientation: "row"}');
gqmButtonGroup2.alignChildren = "fill";
//GQMButtonGroup2.alignment = "stack";
var load = gqmButtonGroup2.add ("button", undefined, " Load GREP Queries", {name: "Load"});
var savelist = gqmButtonGroup2.add ("button", undefined, " Save GREP Queries", {name: "Save"});
//insert item Button
inserttxt.onClick = function () {
insert_item (myList, myname.text);
//insert_item (myList, input.text);
input.text = "";
input.text = "";
input.active = true;
}
//delete selected item
del.onClick = function () {
// remember which line is selected
var sel = myList.selection[0].index;
for (var i = myList.selection.length-1; i > -1; i--)
myList.remove(myList.selection[i]);
// select a line after deleting one or more items
if (sel > myList.items.length-1)
myList.selection = myList.items.length-1;
else
myList.selection = sel;
}
function insert_item (list_obj, new_item) {
if (list_obj.find (new_item) == null) {
var stop = list_obj.items.length;
//w.add(myList);
var i = 0;
while (i < stop && new_item > list_obj.items[i].text)
i++;
with (list_obj.add ("item", new_item, i)){
subItems[0].text = input.text;
}
}
}
//Saving the List in the Same path of Indesign file (must before Show Command)
savelist.onClick = function () {
//Define path and file name
var filePathMinusExtension = app.activeDocument.fullName.fsName.substr(0, app.activeDocument.fullName.fsName.lastIndexOf("."));
var writeFile = File(filePathMinusExtension + "_GREP_Queries.txt");
writeFile.encoding = 'UTF-8';
writeFile.open('w');
var content = ""
for(var i = 0; i < myList.items.length; i++)
content += myList.items[i].toString() +","+ myList.items[i].subItems[0].toString() + "\r"
writeFile.write(content);
writeFile.close();
alert("Done, File Saved in Same InDesign Document Location", "Alert!");
}
//Load List Items and Show them
load.onClick = function () {
//Remove old list items
myList.removeAll()
var filePathMinusExtension = app.activeDocument.fullName.fsName.substr(0, app.activeDocument.fullName.fsName.lastIndexOf("."));
var ReadFile = File(filePathMinusExtension + "_GREP_Queries.txt");
if (ReadFile.exists) {
try {
ReadFile.open("r");
while (ln = ReadFile.readln()) {
myList.add("item", ln);
}
//Close the file
ReadFile.close();
alert("Done, the GREP Queries Loaded");
return true;
}
catch (errOpen) {
alert("Error. The GREP Queries file could not be opened!");
return false;
}
}
else{
alert("The GREP Queries file could not be found!");
return false;
}
}
w.show ();
... View more
Mar 02, 2023
07:07 AM
Hi @AK09M yes you can do this automatically from Find/Change or from Docuement Footnotes Options : جعل الحاشية السفلية ذات اسطر لها محاذاة واحدة Make Footnotes paragraphs lines aligned (Indent to here) by GREP Find : (^~F) Change : $1~>~i Paragraph Style : Footnote Text Note : I used en space just before indent to here! Or from (Document Footnote Options) ^>^i استعمل الحل المناسب لك
... View more