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

Get Max. Panel based on Table Height

Explorer ,
Apr 05, 2023 Apr 05, 2023

Copy link to clipboard

Copied

Hi,

I wanted to create a panel with 'n' number of columns based on the table columns. But as of now I have get only 13 columns. Please guide me to add columns as many as based on the table column length.

		var sCancel = { en: "Cancel"};
    if ( app.activeDocument ) {
	//app.doScript( autoSpalte, undefined, undefined, UndoModes.ENTIRE_SCRIPT, localize(sAutoColumn) );
var tables = app.activeDocument.stories.everyItem().tables.everyItem();
	for(myCounter = 0; myCounter < app.activeDocument.activeLayer.textFrames.length; myCounter++)
	{
        // alert("TextFrame : " + app.activeDocument.activeLayer.textFrames.item(myCounter).contents);
         myStory = app.activeDocument.activeLayer.textFrames.item(myCounter);
      myStory.fit(FitOptions.frameToContent); 
      //  alert(myStory.fit(FitOptions.frameToContent))
		if (myStory.constructor.name == "TextFrame")
		{  
		for( var j = 0; j< myStory.tables.length ; j++ ) 
		{
      myStory.fit(FitOptions.frameToContent); 
      
            var myColumnCount = myStory.tables[j].columns.length
					for( var i = 0; i< myStory.tables[j].columns.length ;i++ ) 
			{
           //     alert(myStory.tables[j].columns.length)
          // alert("Width" + myStory.textFramePreferences.textColumnFixedWidth)
          // alert("Left"+ myStory.tables[j].cells[i].leftInset)
           //alert("Right" + myStory.tables[j].cells[i].rightInset)
           if (myStory.constructor.name == "TextFrame")
		{  
		myFrameWidth = myStory.textFramePreferences.textColumnFixedWidth-myStory.tables[j].cells[i].leftInset-myStory.tables[j].cells[i].rightInset;
       }
	 else {
		// 210208 Edit: try to get column width instead of simply textframe width
		try {
         //   alert(myStory)
			myFrameWidth = myFrame.textFramePreferences.textColumnFixedWidth;
            
		} catch(e) {
			myFrameWidth = myStory.geometricBounds[3] - myStory.geometricBounds[1];
		}
     
	}

                  }
    
	}
}
}
    }
    var nuColumnWidths = new Array();
	var nuColumnWidthFields = new Array();
	var nuColumnWidthFieldLabels = new Array();
	var nuColumnWidthCalc = new Array();
	
    var w = new Window("dialog", "Column Fitting");
	w.orientation = "row";
	w.alignChildren = "fill";
	w.alignment = "fill";
	var fields = w.add("group");
	fields.orientation = "row";
	fields.alignChildren = "fill";
	fields.alignment = "fill";
    for (var n = 0; n < myColumnCount; n++) {
		nuColumnWidths[n]= tables.columns[n].width;
		var aPanel = fields.add("panel");
		aPanel.orientation = "column";
		aPanel.alignChildren="top";
		aPanel.ix = n;
		aPanel.text =  n.toString(); 

        nuColumnWidths[n] = '';
         	nuColumnWidthFields[n] = aPanel.add("edittext", undefined, nuColumnWidths[n]);
            nuColumnWidthFields[n].characters = 2;
		nuColumnWidthFields[n].onChange = function() {
			var ix = this.parent.ix;
 			nuColumnWidths[ix] = Number(nuColumnWidthFields[ix].text.replace(/,/g, "."));
         // alert(nuColumnWidths[ix] )
			nuColumnWidthCalc[ix].value = false;
			calcAuto();
		}
	
		nuColumnWidthCalc[n] = aPanel.add("statictext", undefined, "");
		nuColumnWidthCalc[n].value = false;
		nuColumnWidthCalc[n].onClick = function() {
			calcAuto();
           
		}
	}
	//calcAuto();
		w.buttons = w.add("group");
	w.buttons.orientation = "column";
	w.buttons.alignChildren = "left";
	w.defaultElement = w.buttons.add("button", undefined, "OK");
//~ 		w.defaultElement.onClick = okClick;
	w.cancelElement = w.buttons.add( "button", undefined, localize(sCancel) );
	w.cancelElement.onClick = function() {
		this.window.close();
		exit();
	}
	
	w.center();
	var bClickedOK = w.show();

 

TOPICS
How to , Scripting

Views

81

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 ,
Apr 11, 2023 Apr 11, 2023

Copy link to clipboard

Copied

LATEST

Please improve your code and explain clearly what you are trying to do in a better way. Some pointers that are causing confusion reading the code are

  • You save textframe object inside a variable named myStory
  • You have lots of commented code littering around. Share only the portion that is relevant to the issue
  • You have unnecessary code, you check if my Story is a textframe and then within the if body you again check if it's a textframe, is this needed?

For explaining the issue you are facing, describe what your code currently does and what you expect it to do instead. Some screenshots, sample document etc would be of great assistance

-Manan

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