Indesign render script need to target TextFrames within Rectangle objects - node.js

I am working on InDesign rendering script (.jsx) for rendering template (.indd) using InDesign Server (Version: 17.2). In my InDesign templates, there are Rectangle ([object Rectangle]) items, that further includes some TextFrames (more than one). When I try to access those TextFrames using [object Rectangle].allpageItems, it gives and empty array. How can I access those TextFrames from the [object Rectangle]? Further, can I get/find the InDesign element/item (TextFrame) using xmlTag name? If yes, then please provide the example by which we can find the item.

I suppose it should be something like this:
var doc = app.activeDocument;
var rectangle = doc.rectangles[0]; // get a first rectangle
var text_frame = rectangle.textFrames[0]; // get a textFrame inside of the rectangle
text_frame.select(); // select the text frame

Related

How do I carry over identical texture mapping when exporting to DAE?

I am able to open a 3DS file in MeshLab and when I export to Collada DAE format the textures are visible but they are not being projected onto the mesh in the same way as the preview in MeshLab. For example, the front/back faces of a cube would have the proper texture (suppose it's a polka dot) but the top and bottom have a striped look. How can I apply a single texture and have it appear as intended on all faces, like the imported model before I convert it?
This problem is a result of the end software being used to view the DAE file. It's not a problem with MeshLab.
For example, if loading the file into Away3D be sure to handle the texture materials using the TextureMaterial class instead of the simpler SinglePassMaterialBase such as what you might find in their example code. Here is what I use now, and it displays texture properly:
var material:TextureMaterial = cast(asset, TextureMaterial);
material.ambientColor = 0xffffff;
material.lightPicker = _lightPicker;
material.shadowMethod = new FilteredShadowMapMethod(_light);
material.lightPicker = _lightPicker;
material.gloss = 30;
material.specular = 1;
material.ambient = 1;
material.repeat = true;

Easily convert between Fabric JS IText and Textbox?

Is there a way to easily convert a Fabric JS IText into a TextBox (new in 1.6.0) and vice versa, without having to laboriously read and set every single property of them, i.e. some quick way of mapping between them?
Thanks.
you can easily do
var text = oldItext.text;
var textobj = oldItext.toObject();
delete textobj.text;
delete textobj.type;
var clonedtextobj = JSON.parse(JSON.stringify(textobj));
var textbox = new fabric.Textbox(text, clonedtextobj);
a note about use of json:
normal toObject method in Fabricjs does not take care of deep cloning. so the new textbox you create would share the same style object with the old itext. That is not necessarly bad untill you create 2 copies from 1.
if you are not using styles, a faster way is:
var text = oldItext.text;
var textobj = oldItext.toObject();
delete textobj.type;
var textbox = new fabric.Textbox(text, textobj);

Snapsvg - get height and width of text element

I am altering the elements contents using
svgTextLines[name].node.innerHTML = line.val();
svgTextLines[name].node.textContent = line.val();
and trying to get the height and width of the element after the content has changed but I cant seem to find any property in the elemement.node object that gets updated. As the element has not transformed I can understand why but is there a way I can get this information?
Regards
I'm using SnapSVG and I had the same problem.
You can use getBoundingClientRect to get an object with this parameter.
var s = Snap("#svg");
Snap.load("mascot.svg", function (f) {
s.append(f);
var rect = s.searchAll("g")[0];
var dimens = rect.node.getBoundingClientRect();
console.log(dimens.width)
});

Insert 3D text to the front face of a cube GameObject

I want to add a text to a cube, which has a 3D text as a child. I am trying to write/show the text to the front face (or very close) of the cube.
I am using the below javascript to write on the 3D text:
#pragma strict
var countdown : int = 200;
function Update()
{
GetComponent(TextMesh).text = countdown.ToString();
}
EDIT: My difficulty is to make the text appear in the front side/face of the cube, like it is written on it.
My last failed try was to use the below lines:
var tm = gameObject.AddComponent(TextMesh);
tm.text = countdown.ToString();
Any ideas?
If the TextMesh object is a child of the cube, then what you'd want to use is:
transform.Find("TextMeshObjectName").GetComponent(TextMesh).text = countdown.ToString();
where TextMeshObjectName is the name of your TextMesh object. I'm also assuming the script is running from within the cube. There are of course other ways to find children as well, so if you like, take a look at this link here

Aspose.Words...calculating widt of text in pixels

I have an MVC3 C# .Net web app. I am using Aspose.Words to create an MS Word document. I have a requirement to not include tables in the document. However, on several lines of the document the alignment of the text is mis-aligned depending on the width of the text.
For example:
This looks good
Proposal Name: My Proposal Date:04/24/2012
This does not
Proposal Name: My Prop Date:04/24/2012
It should be
Proposal Name: My Prop Date:04/24/2012
Based on the width of the first bit of text, I need to calculate the width in pixels (I think) and insert a TAB if necessary.
Any ideas how to do this?
you can use Graphics.MeasureString function which gives you the width of your string in pixels based on your font. for more info go Here
Cheers,
Ehsan
The following code example returns the bounding rectangle of the current entity relative to the page top left corner.
Document doc = new Document(MyDir + "in.docx");
LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
var renderObject = layoutCollector.GetEntity(para);
layoutEnumerator.Current = renderObject;
RectangleF location = layoutEnumerator.Rectangle;
Console.WriteLine(location);
}
src: https://www.aspose.com/community/forums/thread/541215/replace-run-text-with-string-of-spaces-of-same-pixel-length.aspx

Resources