Weird behaviour copying a field into another stack
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Weird behaviour copying a field into another stack
Hi again,
I am trying to copy a field into another stack when a button is clicked.
I need the content of the field, with the formatted text to be copied.
I am using this code:
on mouseUp
copy field "Text2" to card "Hilite" of stack "print layout"
end mouseUp
It only works sometimes, and I cannot figure out what's going on.
Any ideas?
Marta
I am trying to copy a field into another stack when a button is clicked.
I need the content of the field, with the formatted text to be copied.
I am using this code:
on mouseUp
copy field "Text2" to card "Hilite" of stack "print layout"
end mouseUp
It only works sometimes, and I cannot figure out what's going on.
Any ideas?
Marta
Marta,
your script copies a whole field, not just the content of the field effectively adding a field to the destination card.
try:to just copy the content of a field with the formatting preserved.
regards
Bernd
your script copies a whole field, not just the content of the field effectively adding a field to the destination card.
try:
Code: Select all
set the htmlText of field 1 of card 1 of stack "myOtherStack" to the htmlText of field 1 of this card
regards
Bernd
Thanks bernd,
That helped a little bit. However, I am still having problems with that field.
The field is originally in a card in the main stack. After the end users have hilited the text, I want to copy the field to another card in another stack (that is working right now)
Now, I want to change some of the properties of the text. This is my code:
on preOpenCard
set the lock of field "Text2" to false
set the textFont of field "Text2" to "Times New Roman"
--set the textSize of field "Text2" to 12
set the textHeight of field "Text2" to 23
set the width of field "Text2" to 1000
set the height of field "Text2" to 550
set the loc of field "Text2" to 622, 433
if the formattedHeight of field "Text2" > the height of field "Text2" then
set the vScrollbar of field "Text2" to true -- so show a scrollbar
else
set the vScrollbar of field "Text2" to false -- get rid of the scrollbar
end if
end preOpenCard
I think it should work, but for example the textFont never changes, and the other atributes only change sometimes.
Any idea? Am I missing something?
Marta
That helped a little bit. However, I am still having problems with that field.
The field is originally in a card in the main stack. After the end users have hilited the text, I want to copy the field to another card in another stack (that is working right now)
Now, I want to change some of the properties of the text. This is my code:
on preOpenCard
set the lock of field "Text2" to false
set the textFont of field "Text2" to "Times New Roman"
--set the textSize of field "Text2" to 12
set the textHeight of field "Text2" to 23
set the width of field "Text2" to 1000
set the height of field "Text2" to 550
set the loc of field "Text2" to 622, 433
if the formattedHeight of field "Text2" > the height of field "Text2" then
set the vScrollbar of field "Text2" to true -- so show a scrollbar
else
set the vScrollbar of field "Text2" to false -- get rid of the scrollbar
end if
end preOpenCard
I think it should work, but for example the textFont never changes, and the other atributes only change sometimes.
Any idea? Am I missing something?
Marta
Marta,
your script works if and when there is not prior formatting regarding textFont in the field. If you want to change the textFont afterwards then try this:I put it into a button to test it. You should be able to put it back into your preopencard handler.
The bottom line is that if you want to change text attributes on text that have been formatted before then work on a selection of the text, even if it is the whole text like in this case.
regards
Bernd
PS the line "set the lock of field "Text2" to false" did not give you an error although the lock of a field does not exist, it would be the locktext. No error because in this case Rev creates a custom property called lock and puts false into it. Probably not what you wanted. You can look at this property in the property inspector under custom properties. This can be a source of confusion. Rev creates your custom property if you use the property syntax (set the NameOfCustomProperty to value). In this case lock did not exist as a reserved word so Rev happily complied.
your script works if and when there is not prior formatting regarding textFont in the field. If you want to change the textFont afterwards then try this:
Code: Select all
on mouseUp
set the lockText of field "Text2" to false -- if you want this/ not needed, can be locked
--set the lock of field "Text2" to false -- this property does not exist
lock screen -- not necessary in a preopencard handler
put the traversalOn of field "Text2" into OldTraversal -- we restore the traversalOn after changing the textFont
set the traversalOn of field "Text2" to true -- has to be on to make a selection by script
select text of field "Text2"
set the textFont of the selectedText to "Courier"
select empty
set the traversalOn of field "Text2" to OldTraversal -- restore traversalOn to old state
--set the textFont of field "Text2" to "Times New Roman"
set the textSize of field "Text2" to 12
set the textHeight of field "Text2" to 23
set the width of field "Text2" to 1000
set the height of field "Text2" to 550
set the loc of field "Text2" to 622, 433
if the formattedHeight of field "Text2" > the height of field "Text2" then
set the vScrollbar of field "Text2" to true -- so show a scrollbar
else
set the vScrollbar of field "Text2" to false -- get rid of the scrollbar
end if
end mouseUp
The bottom line is that if you want to change text attributes on text that have been formatted before then work on a selection of the text, even if it is the whole text like in this case.
regards
Bernd
PS the line "set the lock of field "Text2" to false" did not give you an error although the lock of a field does not exist, it would be the locktext. No error because in this case Rev creates a custom property called lock and puts false into it. Probably not what you wanted. You can look at this property in the property inspector under custom properties. This can be a source of confusion. Rev creates your custom property if you use the property syntax (set the NameOfCustomProperty to value). In this case lock did not exist as a reserved word so Rev happily complied.
Re: Weird behaviour copying a field into another stack
Just some things that may be of use to folks who read this thread. I have found working with text properties a little confusing at times, because it is easy to forget whether, say, the textFont you are seeing in the field is one you have set yourself for that chunk of text, or inherited from the field itself, or further up the “inheritance chain”. The section in the Rev user manual about “Inheritance” explains this well, especially the role of the key word “effective”.
You can apply text properties, for example textFont, directly to chunks of text in a field:... or all the chars in the field:
... or remove settings:
... in which case, the textFont you will see will be that set for the field itself, or if none is set for the field, the textFont inherited from further up the “chain”. It can be useful to try these lines out on a field, and watch how the htmlText of the field changes, e.g.
... to see the effect in the message box.
Another thing to notice is that if the fixedLineHeight of the field is false, setting the textHeight has no effect, because the height of each line is determined by the size of the text on the line. If the fixedLineHeight is true, you can set the textHeight. Notice that when you set the textSize, Rev automatically adjusts the textHeight to suit (see the dictionary for details). The thing to remember is that if you set the textHeight, then the textSize, the textHeight you will see will be that automatically calculated to suit the textSize. Your textHeight setting is overridden by the textSize/textHeight combination. The script examples earlier in this thread quite correctly get the order right- set the textSize, then set the textHeight. It’s worth knowing the importance of the order.
[I had to delete and re-post this, as it seemed to get truncated when forum was upgraded]
You can apply text properties, for example textFont, directly to chunks of text in a field:
Code: Select all
set the textFont of char 1 to 20 of card field “MyText” to arial
Code: Select all
set the textFont of char 1 to (the length of card field “MyText”) of card field “MyText” to arial
Code: Select all
set the textFont of char 1 to (the length of card field “MyText”) of card field “MyText” to empty
Code: Select all
set the textFont of char 1 to 20 of card field “MyText” to arial
put the htmlText of card field “MyText”
Another thing to notice is that if the fixedLineHeight of the field is false, setting the textHeight has no effect, because the height of each line is determined by the size of the text on the line. If the fixedLineHeight is true, you can set the textHeight. Notice that when you set the textSize, Rev automatically adjusts the textHeight to suit (see the dictionary for details). The thing to remember is that if you set the textHeight, then the textSize, the textHeight you will see will be that automatically calculated to suit the textSize. Your textHeight setting is overridden by the textSize/textHeight combination. The script examples earlier in this thread quite correctly get the order right- set the textSize, then set the textHeight. It’s worth knowing the importance of the order.
[I had to delete and re-post this, as it seemed to get truncated when forum was upgraded]