Copy link to clipboard
Copied
Dear all,
Once again it seams that I "put the cart before the horse" to do the following:
- In the current document i have a text selection and want to re-apply the pgf format from the catalogue to the current pgf.
- Taking the properties from the catalogue and applying to the current pgf does nothing.
function ReApplyPgfFormat (oDoc, tRange) {
// oDoc current document
// tRange current text range
var currPgf = tRange.beg.obj;
var pgfFormat = currPgf.Name; // most likely Footnote, but not guaranteed
var pgfFmt = oDoc.GetNamedPgfFmt(pgfFormat);
var pgfProps = pgfFmt.GetProps(); // from catalogue
currPgf.SetProps(pgfProps); // re-apply
alert ("Reformatting done?"); // re-apply did not happen
}
I was searching in the documentation (fdk reference, object reference) back and forth - but did not get a clue.
This is the final solution to my problem which is not just re-apply the current ¶-format:
What I ned to do in my case is this:
Copy link to clipboard
Copied
Here is a function I use to apply a paragraph format to a paragraph.
function applyPgfFmt (pgf, name, doc) {
var pgfFmt = 0;
pgfFmt = doc.GetNamedPgfFmt(name);
if (pgfFmt.ObjectValid()) {
var props = pgfFmt.GetProps();
pgf.SetProps(props);
}
else {
pgf.Name = name;
}
}
In your case, you could call it like this:
var doc = app.ActiveDoc;
var pgf = doc.TextSelection.beg.obj;
applyPgfFmt (pgf, pgf.Name, doc);
-Rick
Copy link to clipboard
Copied
Thank You Rick,
However, I had to insert line 4. Without this the format is not really applied (in this case). Maybe the Textselection is in a special state from the find/replace process. Probably my initial idea (not communicated) would also have worked with this.
function ReApplyPgfFormat (oDoc, tRange) {
// oDoc current document
// tRange current text range
oDoc.TextSelection = tRange; // without this the re-apply don't work
var currPgf = tRange.beg.obj;
applyPgfFmt (currPgf, currPgf.Name, oDoc); // re-apply
}
Copy link to clipboard
Copied
Dear all,
I was to fast in accepting the solution... Further tests with other fm-documents revealed my misconception: The ¶-format is not re-applied - it just looks so:
function ReApplyPgfFormat (oDoc, tRange) {
oDoc.TextSelection = tRange;
var currPgf = oDoc.TextSelection.beg.obj;
Alert ("currPgf.name = " + currPgf.name); // => undefined
var pgfFmt = 0;
pgfFmt = oDoc.GetNamedPgfFmt(currPgf.name); // take properties from catalogue
if (pgfFmt.ObjectValid()) {
var props = pgfFmt.GetProps();
currPgf.SetProps(props);
} // do nothing, if not in catalogue
giLvlTrace -= 1;
} // --- end ReApplyPgfFormat
What can I do to get the current ¶ from the text range?
Copy link to clipboard
Copied
Hi Klaus,
the problem is definitely the undefined Pgf (line 4);
There are some points to look at:
- try currPgf.Name instead of currPgf.name
- how do you define your selection?
The variable oDoc looks like a global one. But you use it as an argument in your function. I don't know, if this can cause a problem (same with tRange).
Copy link to clipboard
Copied
Wow, Klaus, again capitalisation hit me!
«try currPgf.Name instead of currPgf.name»
This works as intended.
I have not yet found a clear list of syntax rules - and there are differences between JS and ES object and methods ...
Copy link to clipboard
Copied
This is the final solution to my problem which is not just re-apply the current ¶-format:
What I ned to do in my case is this:
function ReApplyFontAndSize (oDoc, tRange) {
oDoc.TextSelection = tRange; // current selection is only part of ¶
var currPgf = oDoc.TextSelection.beg.obj;
var pgfFmt = 0, propsPgf;
pgfFmt = oDoc.GetNamedPgfFmt(currPgf.Name); // get properties from catalogue
if (!pgfFmt.ObjectValid()) { // pgf fmt is not in catalogue
return;
}
propsPgf = AllocatePropVals(2); // for font-family and -size
propsCatlg = pgfFmt.GetProps(); // get properties from catalogue
j = GetPropIndex(propsCatlg, Constants.FP_FontFamily);
propsPgf[0] = propsCatlg;
j = GetPropIndex(propsCatlg, Constants.FP_FontSize);
propsPgf[1] = propsCatlg;
tRange.beg.obj = currPgf; // select the whole paragraph
tRange.beg.offset = 0;
tRange.end.obj = currPgf;
tRange.end.offset = Constants.FV_OBJ_END_OFFSET;
oDoc.TextSelection = tRange;
oDoc.SetTextProps (tRange, propsPgf); // apply font family and size
} // --- end ReApplyFontAndSize
This may be streamlined - but it does what it should.