Drawing a Line in InDesign CS5.5 using ExtendScript - extendscript

I would like to know how to draw a line on InDesign using Extended Script something like
pseudo code
for(x = 0; x < 5; x++){
drawLine(The X Value to startLine, The Y-Value to startLine, Length, Color);
}
Any help would be greatly appreciated.
Thank you

Try this script. https://github.com/fabiantheblind/extendscript/wiki/Graphic-Lines.
var data = {
"pw":100,
"ph":100,
"anchors":[
[ 0,50],
[ 10,60],
[ 20,40],
[ 30,60],
[ 40,40],
[ 50,60],
[ 60,40],
[ 70,60],
[ 80,40],
[ 90,60],
[100,50]
]
};
// We need a doc.
// Use pw and ph from data.
var doc = app.documents.add({
documentPreferences:{
pageHeight:data.ph,
pageWidth:data.pw
}
});
// The page is already there.
var page = doc.pages.item(0);
// Create a graphicLine.
var gl = page.graphicLines.add();
// Loop through the data.anchors.
for(var i in data.anchors){
var point = gl.paths[0].pathPoints[i];
/**
* a graphicLine always has 2 path points
* so we need to add points only from the third
* anchor from the data object
*/
if(i < 2){
point.anchor = data.anchors[i];
}else{
point = gl.paths[0].pathPoints.add();
point.anchor = data.anchors[i];
}
if((i != data.anchors.length - 1)&& i!=0)
point.rightDirection = data.anchors[i-1];
point.leftDirection = data.anchors[i];
}

Related

How get Lot/Serial number in Netsuite SuiteScript 2.0 for Inventory Adjustment Transaction?

I'm trying to get the serial numbers from a inventory adjustment in a user event script. The following code works very well for me when the amount to adjust is positive, but not when it is negative.
var invDet = transaction.getSublistSubrecord({sublistId:'inventory',
fieldId:'inventorydetail',
line:x});
for(var y = 0; y = invDet.getLineCount('inventoryassignment'); y++) {
var lotNumber = invDet.getSublistValue({sublistId:'inventoryassignment',
fieldId:'receiptinventorynumber',
line:y});
log.debug('lotNumber', lotNumber);
}
When adjust quantity is negative, receiptinvetorynumber is empty
I have tried using field id equal to 'issueinventorynumber' or 'binnunber' but the returned value is empty.
I found the following comment in a NetsuiteHub forum...
In 2.0 the getValue call returns the internal ID of the serial/lot number and the getText equivalent does not work. Depending on the exact logic you need to execute for the obtained numbers you might need to call a subsequent saved search to obtain the actual serial/lot numbers and not internal IDs (an 'inventorynumber' search will do the trick).
I tried this...
try{
var internalId = invdet.getSublistValue({sublistId:'inventoryassignment',fieldId:'internalid', line:y});
search.create({type:'inventorynumber', filters:[
['internalid', 'is', internalId]
], columns:['inventorynumber']}).run().each(function (result) {
binText = result.getValue('inventorynumber');
log.debug('binText', binText);
});
} catch(e) {
log.debug('Error', e.message);
throw e.message;
}
I am too inexperienced to make this work. I appreciate any help you can give me.
Thanks.
The challenge is that this area of the NetSuite API is not well documented. However, I pushed through it through trial and error and search hours.
var invDet = transaction.getSublistSubrecord({sublistId:'inventory',
fieldId:'inventorydetail',
line:x});
for(var y = 0; y = invDet.getLineCount('inventoryassignment'); y++) {
var Qty = invdet.getSublistValue({sublistId:'inventoryassignment',
fieldId:'quantity',
line:y});
var lotNumber = '';
if(Qty < 0)
{
var ivnNumId = nvdet.getSublistValue({sublistId:'inventoryassignment',
fieldId:'issueinventorynumber',
line:y});
if(ivnNumId !== '')
{
var invNum = record.load({type: 'inventorynumber',id:ivnNumId});
lotNumber = invNum.getValue({fieldId: 'inventorynumber'});
}
}
else
{
lotNumber = invdet.getSublistValue({sublistId:'inventoryassignment',
fieldId:'receiptinventorynumber',
line:y});
}
log.debug('lotNumber', lotNumber);
}
This information was very helpful in ss1.0
I hope it is useful to someone

Kendo grid how do i auto-size an excel export row height?

I have a custom excel output class that I'm using to parse the grid, and in some cases replace the data in the grid with template data. In this particular instance, the data i want to output is multi-line. I have it working to that point but the exported sheet is one line high so you can't see lines two thru-seven in the field.
desired result:
actual result:
Here's a relevant section of my code. It's the parsing loop that applies the templates and strips html, but adds line breaks first.
if (me.ColumnTemplates && $.isArray(me.ColumnTemplates)) {
for (let c = 0; c < me.ColumnTemplates.length; c++) {
let ct = me.ColumnTemplates[c];
if (ct.template(dr).includes("</br>")) {
sheet.rows[r + 1].cells[ct.cellIndex - 1].wrap = true;
}
me.elem.innerHTML = ct.template(dr).replace(/<\/br>/g, "\n");
sheet.rows[r + 1].cells[ct.cellIndex - 1].value = me.elem.textContent || me.elem.innerText || "";
}
}
any help would be appreciated. I would like to either have a setting that makes this "just work" or have a way to compute the needed height and set it manually. Either is fine.
I'm not aware of a way to auto-size it, but you can set row height it via sheets.rows.height:
<script>
var workbook = new kendo.ooxml.Workbook({
sheets: [{
rows: [{
cells: [{ value: "this row is 100px high" }],
height: 100
}, {
cells: [{ value: "this row is 200px high" }],
height: 200
}]
}]
});
</script>
example found here
Updating your code to utilize each in the template html you can do something like the following:
if (me.ColumnTemplates && $.isArray(me.ColumnTemplates)) {
for (let c = 0; c < me.ColumnTemplates.length; c++) {
let ct = me.ColumnTemplates[c];
if (ct.template(dr).includes("</br>")) {
sheet.rows[r + 1].cells[ct.cellIndex - 1].wrap = true;
sheet.rows[r + 1].height = (ct.template(dr).match(/<\/br>/g) || []).length * 20 + 20; //20 was default row height.
}
me.elem.innerHTML = ct.template(dr).replace(/<\/br>/g, "\n");
sheet.rows[r + 1].cells[ct.cellIndex - 1].value = me.elem.textContent || me.elem.innerText || "";
}
}
Set column width to auto
Solution 1
When kendo grid bound to data source in JavaScript/jQuery
excelExport: function(e) {
var columns = e.workbook.sheets[0].columns;
columns.forEach(function(column){
// also delete the width if it is set
delete column.width;
column.autoWidth = true;
});
}
more details
Solution 2
When kendo grid is taking data source from action controller not bound to data source in jQuery then add event to call a JavaScript function on excel export
function exportToExcelSheetColumnWidthChange(e) {
var columns = e.workbook.sheets[0].columns;
columns.forEach(function (column) {
delete column.width;
column.autoWidth = true;
});
};
Add event to the kendo grid control
.Events(e => e.ExcelExport("exportToExcelSheetColumnWidthChange"))

Parse string (node js ) .Find array of numbers into string

\n54766392632990,178.32.243.13,wfsdsfsdfs23432,\n54766393632990,178.32.243.13,
Above u can see example of string which I want to parse.. I want to get array if numbers which exist between (\n....,178.32.243.13) .. In this example it will be smth like :
[54766392632990,54766393632990] - how to make it
Please run this script it full file your requirement
var ss = "\n54766392632990,178.32.243.13,wfsdsfsdfs23432,\n54766393632990,178.32.243.13,"
var ddd = ss.split(",")
console.log(ddd)
var dfd = []
ddd.forEach(function(res){
if(res.startsWith("\n"))
{
dfd.push(res.replace("\n",""))
}
})
console.log(dfd)
Result [ '54766392632990', '54766393632990' ]
"\n54766392632990,178.32.243.13,wfsdsfsdfs23432,\n54766393632990,178.32.243.13,"
.split("\n")
.filter((n)=> n!== "")
.map(n=> parseInt(n.split(",")[0]))
You can do something like this to parse this string
let s = "\n54766392632990,178.32.243.13,wfsdsfsdfs23432,\n54766393632990,178.32.243.13,"
s = s.split("\n");
let array = [];
for(let i=0;i<s.length;i++) {
let v = s[i].split(",178.32.243.13,");
for(let j=0;j<v.length;j++) {
if(!isNaN(parseInt(v[j]))) {
array.push(v[j]);
}
}
}
console.log(array);

Jscript to check defined array

My code gathers all categories from a CSV file, sorts and grabs top 10 categories and the top 10 result are displayed on a chart. The code works fine if the gategory found is 10, but if it is less than 10 no chart is displayed..basically code dies.
I am a newbie when it comes to coding and the code was passed on to me by someone else who is not available. What I would like to add is an if cases that checks:
Gather all category, sort
Set category to 1 to 10
if category is null, stop. Chart has no value
if category=1 ===> Display found value
if category=2 ===> Display found value
if category=3 ===> Display found value
if category=3 ===> Display found value
So on, so on..untill it reaches to 10
//collect top 10 cat from array
catArray.sort(sort_by("count", false, function (a) {
return parseInt(a)
}));
var categorytop10 = new Array(catArray[0]["tier3"], catArray[1]["tier3"], catArray[2]["tier3"], catArray[3]["tier3"], catArray[4]["tier3"], catArray[5]["tier3"], catArray[6]["tier3"], catArray[7]["tier3"], catArray[8]["tier3"], catArray[9]["tier3"]);
var categorytop10Count = new Array(catArray[0]["count"], catArray[1]["count"], catArray[2]["count"], catArray[3]["count"], catArray[4]["count"], catArray[5]["count"], catArray[6]["count"], catArray[7]["count"], catArray[8]["count"], catArray[9]["count"]);
Any help is appreciated. Thanks
Based on the limited info provided, here is what I can suggest.
//collect top 10 cat from array
catArray.sort(sort_by("count", false, function (a) {
return parseInt(a)
}));
var categorytop10 = new Array();
var categorytop10Count = new Array();
for (var i = 0; i < 10 && i < catArray.length; ++i)
{
categorytop10.push( catArray[i]["tier3"] );
categorytop10Count.push( catArray[i]["count"] );
}
EDIT: You can also try this
//collect top 10 cat from array
catArray.sort(sort_by("count", false, function (a) {
return parseInt(a)
}));
var categorytop10 = new Array();
var categorytop10Count = new Array();
for (var i = 0; i < 10; ++i)
{
if (i < catArray.length)
{
categorytop10.push( catArray[i]["tier3"] );
categorytop10Count.push( catArray[i]["count"] );
}
else {
categorytop10.push( "?" );
categorytop10Count.push( "0" );
}
}

Titanium: Error trying to play a sound when tapping a row in a table?

I'm making a rather simple app that displays a table where each row contains an English word and the corresponding Polish word. When a row is pressed it should play a sound clip of the word expressed. However, I cannot make it work, even though I've tried to troubleshoot it with all that Google has to offer. Would appreciate if someone could point out the flaw...
var win = Titanium.UI.currentWindow;
var data =[];
var CustomData = [
{ file:'001', english:'Do you?', polish:'Czy masz?', fav:false },
{ file:'002', english:'How long?', polish:'Jak d?ugo?', fav:false },
{ file:'003', english:'Is it?', polish:'Czy?', fav:false },
];
var section = Ti.UI.createTableViewSection();
data.push(section);
for (var i=0; i<CustomData.length; i++) {
var row = Ti.UI.createTableViewRow({layout : 'vertical', height:'auto'});
var item = Ti.UI.createLabel({
color:'#000',
text:CustomData[i].english,
font:{fontSize:12, fontWeight:'bold'},
top:3,
left:10,
right:30,
height:'auto'
});
row.add(item);
var cost = Ti.UI.createLabel({
color:'#444',
text:CustomData[i].polish,
font:{fontSize:12},
top:0,
left:15,
right:30,
bottom:5,
height:'auto'
});
row.add(cost);
row.filter = CustomData[i].english;
section.add(row);
};
var tableview = Titanium.UI.createTableView({
data:data, search:search, searchHidden:false, filterAttribute: 'filter' });
win.add(tableview);
tableview.addEventListener('click', function(e)
{
var sound = Titanium.Media.createSound();
sound.url = '../sound/' + e.rowData.file + '.mp3';
sound.play();
if (e.rowData.test)
{
var win = Titanium.UI.createWindow({
url:e.rowData.test,
title:e.rowData.title
});
Titanium.UI.currentTab.open(win,{animated:true});
}
});
Just a shot in the dark, but are you sure you can set the URL after the sound object is created? Have you tried:
Titanium.Media.createSound({url:'../sound/' + e.rowData.file + '.mp3'});
Aside from that, are you sure the relative URL is evaluated from where you think? Maybe try it with an absolute URL just to be sure.

Resources