Jump to content

Setting Text Defaults from a Plug-In


Recommended Posts

Hi All,

I have a point object Plug-In (Event Enabled) that is simply a piece of text that is edited in a dialog by a cursor double click. This is my first dabble into event enabled scripting, so I am quite happy that for the most part, the object is working as intended. I have one problem though.

I need the placed text object to have specific text settings such as Font, Size, Style, and Alignment. To accomplish this I am first collecting the text defaults, then changing the defaults before the object creation, then changing the text settings back to the original defaults after the object creation. I am doing all this in the Reset Event case of the script.

It works correctly as far as creating the object with the correct text settings, but there seems to be a problem with re-setting the defaults back to their original values when done. Specifically, the default Style and Alignment are not returning to their original settings after the object is placed in the drawing. This is not a problem when double clicking on an existing object in the drawing and editing, it is only a problem on placing a new object in the drawing, which seems odd as I thought the same Reset Event occurs whether the object is placed or edited.

I have tracked the issue down to the gathering of the default Style and Alignment, not the re-setting. I set up a message to return the default values being collected during the Reset Event, and when the object is placed, the message returns the Style and Alignment settings that are not set until after I collect them. But when the object is double clicked and edited the message shows that the correct default values are collected.

Here is a snippit of my Reset Event:

CASE theEvent OF
	{Gets default font settings and fill pattern}
	fontstr := GetPrefString(100);
	txtsize := GetDefaultTextSize;
	txtstyle := GetPrefInt(58); {these two text items do not correctly return default values when     }
	txtjust := GetPrefInt(82);  {object is placed, but return TextFace and TextJust that are set below}

	dfltfill := FFillPat;

	Message(fontstr,' ' ,txtsize,' ' ,txtstyle,' ' ,txtjust);

	{Sets default font settings and fill pattern for object creation}


	{Draws object}
	shtnum := PSHEET;

	{Resets font settings and fill pattern back to original default values}



One additional piece of information is that the default font and size do correctly return, and therefore are correctly reset, although they are also changed in the object along with the style and justification.

I find the text functions in VectorScript confusing enough, but this one has me stumped. Does anyone have

any ideas what is going on here?

Link to comment

Hi Peter,

I don't know what's going on with this, but a PIO that fails to work as expected on first insertion, and then works fine after that sounds familiar. My knee-jerk reaction would be to try a ResetObject and see what happens.

I do have a question that probably has nothing to do with the problem. I'm curious why you're not using Push and PopAttrs. Is there a setting that isn't captured by PushAttrs?

Link to comment

Thanks Charles,

I substituted in the PushAttrs and PopAttrs, and the script works fine now. I guess I had my brain so wrapped around understanding the event enabling that I over complicated the easy part of the script. This also shortens my code by 8 lines.

Also, I guess I have never used push and pop for text, I have just used it for pen and fill attributes.

I would still be interested in knowing why the other way was failing. I do not think Reset object would have done it as the object was drawing correctly. It was the document defaults that were failing.

Maybe it had something to do with the compiler mode, or haven't I read something about plug-in objects regenerating twice? The script was clearly getting attributes that were not being set until after I got them, so the code must have been read twice by the compiler. This is an area in which I could certainly use more knowledge.

Thanks again,


Link to comment
This is an area in which I could certainly use more knowledge.

Me too! Object re-generation and what happens when is also mysterious. How can an object that doesn't exist yet pick up a preference that it hasn't set?

It seems that some scripts run in a time-warp...

And yeah, the reset idea doesn't make much sense, but you never know.

In any case I'm glad you got it working.

I just noticed your signature, and I remember a post recently where someone ran into trouble with event-enabling of some sort in 12 that was resolved in a later version. Might have something to do with it. Seems to me that what you were doing should have worked. If you have trouble in the future I'd be happy to test in 09 if that might help.

Link to comment

I am surprised that not many use the $debug directive to troubleshoot the code. If used, it will show you how many times it runs the reset event.

In using this feature, I discovered that if you create an object and later delete it in the code, it will make the reset event run twice. You really do not notice this if the code is a few lines long but if you are changing thousand of objects at the same time, the difference may be significant.


In addition to using Push & PopAttrs, you can also create the objects with the default settings and then change the object attributes with calls like SetTextFont which uses the handle of the new text (LNewObj) as a parameter. This way you do not have to mess with the default settings at all.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...