InvalidGetError: Get not possible, invalid or unknown error trying to get Field.rect
Copy link to clipboard
Copied
Good morning all.
I am building a smart multi-purpose form. One of its features is to allow the user to enter a vertical section at a specific location on a vessel drawing. Once the location is selected, a vertical line is displayed together with a set of data fields where the user is supposed to enter water depths. In order to do this, I use the rect data from specific fields as base and then I add the appropriate figures to create a new set of fields at the selected location. Here is the full code (runs when you click a button on the page. This page is a template)
//var FieldGND="P"+this.pageNum+".GND.";
var FieldGND="S.";
// the following are the numbers for min and max frame numbers
var FRmax=226;
var FRmin=-5;
// the following are actual frame numbers marking changes in frame spacing
var fr1=FRmin;
var fr2=13;
var fr3=36;
var fr4=206;
var fr5=FRmax;
// the following are x-coordinates in points for frame locations marking changes in frame spacing
var pos1=93.03;
var pos2=122.03;
var pos3=169.71;
var pos4=525.39;
var pos5=556.39
var FRnum=parseInt(app.response({cQuestion:"Enter frame number (" + FRmin + " to " + FRmax + ")",cTitle:"Insert position by frame number",cDefault:"0"}));
if(FRnum>FRmax || FRnum<FRmin){
app.alert("Frame number out of range. Must be between " + FRmin + " and " + FRmax);
}else{
var FRxpos=0.0;
// use linear regression
if(FRnum<=fr2){
FRxpos = pos1+(FRnum-fr1)*(pos2-pos1)/(fr2-fr1);
}else if(FRnum<=fr3){
FRxpos = pos2+(FRnum-fr2)*(pos3-pos2)/(fr3-fr2);
}else if(FRnum<=fr4){
FRxpos = pos3+(FRnum-fr3)*(pos4-pos3)/(fr4-fr3);
}else if(FRnum<=fr5){
FRxpos = pos4+(FRnum-fr4)*(pos5-pos4)/(fr5-fr4);
}
//app.alert("1");
var txt0rect=[FRxpos-0.5,536.88,FRxpos+0.5,650.84];
var txt1rect=this.getField("ACT.F.004").rect; //this line fails
var txt2rect=this.getField("ACT.F.017").rect;
var txt3rect=this.getField("ACT.S.009").rect;
var txt4rect=this.getField("ACT.S.016").rect;
var txtFPOS=this.getField("ACT.FR1.0").rect;
//app.alert("2");
txt1rect[0]=FRxpos-7.25;txt1rect[2]=FRxpos+7.25;
txt2rect[0]=FRxpos-7.25;txt2rect[2]=FRxpos+7.25;
txt3rect[0]=FRxpos-7.25;txt3rect[2]=FRxpos+7.25;
txt4rect[0]=FRxpos-7.25;txt4rect[2]=FRxpos+7.25;
txtFPOS[0]=FRxpos-1.5;
txtFPOS[2]=FRxpos-7.5-1.5;
//app.alert("3");
var txtrot=90;
var txtsize=7;
//app.alert(FieldGND+"frame."+FRnum+".BHD");
var bhd=this.addField("frame."+FRnum+".BHD","text",this.pageNum,txt0rect);
//bhd.borderStyle=border.d;
bhd.strokeColor=color.red;
bhd.readonly=true;
var f1=this.addField("frame."+FRnum+".FBp","text",this.pageNum,txt1rect);
f1.rotation=90;
f1.textColor=color.blue;
f1.strokeColor=color.red;
f1.textSize=txtsize;
f1.alignment="center";
var f2=this.addField("frame."+FRnum+".FBs","text",this.pageNum,txt2rect);
f2.rotation=90;
f2.textColor=color.blue;
f2.strokeColor=color.red;
f2.textSize=txtsize;
f2.alignment="center";
var f3=this.addField("frame."+FRnum+".SNDp","text",this.pageNum,txt3rect);
f3.rotation=90;
f3.textSize=txtsize;
f3.strokeColor=color.red;
f3.alignment="center";
var f4=this.addField("frame."+FRnum+".SNDs","text",this.pageNum,txt4rect);
f4.rotation=90;
f4.textSize=txtsize;
f4.strokeColor=color.red;
f4.alignment="center";
var f=this.addField("frame."+FRnum+".FPOS","text",this.pageNum,txtFPOS);
f.rotation=90;
f.alignment="center";
f.value="FR"+FRnum;
f.textColor=color.red;
f.fillColor=color.white;
f.strokeColor=color.red;
f.textSize=5;
f.readonly=true;
}
and this is the line where the code fails...
var txt1rect=this.getField("ACT.F.004").rect;
and I'm sure the rest will fail as well.
Now this was working perfectly while the fields were created on a regular page. However when this page was turned into a template (which is spawned when required) the code stopped working and fails at the line above with the following error:
InvalidGetError: Get not possible, invalid or unknown. Field.rect:44:Field Button01:Mouse Up
The page is spawned from an option button on another page, using this.getTemplate("GND").spawn(this.numPages-1,false,false);
Funny thing is, out of curiosity I extracted the page to another file and everything works like a charm. Is this some kind of bug/limitation of templates or am I missing something?
Thank you all in advance for your help.
Using Windows 10, Acrobat DC Pro (2015 release)
Copy link to clipboard
Copied
Make sure there's actually a field with that name ("ACT.F.004")...
Copy link to clipboard
Copied
There is indeed...
Copy link to clipboard
Copied
Can you share the file with us?
Copy link to clipboard
Copied
SOLVED!
It appears that if a template is spawned with bRename set to false the rect parameter of the fields on the template cannot be retrieved, while setting bRename to true takes care of this.
You only need to make sure that you reference the page number correctly.
It took some tests but finally I figured it out...
Also (although probably irrelevant) if templates are spawned with bRename=false their fields' page property is an array if spawned more than once. If false, their fields' page property is always a number...
Copy link to clipboard
Copied
This is true for any field that has multiple widgets, not just those from spawned templates.
You can still access those widgets directly and get their rect property, though.
You just need to adjust the field name, like this:
this.getField("ACT.F.004.0") // returns first widget in the group
this.getField("ACT.F.004.1") // returns second widget in the group, etc.
Copy link to clipboard
Copied
Thank you very much try67, however it still puzzles me why the rect property cannot be retrieved from fields in templates spawned with bRename=false...
Copy link to clipboard
Copied
It can be. I explained how above.

