Jump to content
Developer Wiki and Function Reference Links ×

PIO checking for duplicated field values


J. Miller

Recommended Posts

I have a PIO that needs to have a unique field value in order to work with another PIO. Is there a way to open the preference dialog of the PIO each time the PIO is placed into the File and check to be sure the value of a field does not already exist. If it does I'd like to call a strdialog to change the name? Where would this call be placed to work properly?

Thanks in Advance

Jeff Miller

Link to comment

Jeff,

I'm not clear why you want to open the preference dialog. You can have the PIO check for duplicate IDs on regen. You can also do the check using IsNewCustomObject in the PIO code. This only runs, however, when placing the object through its corresponding tool, so you would also have to check for uniqueness if you place the PIO as part of another script. I would imagine, though that you would always want to check to make sure the field is unique, not just on insertion.

Presenting a dialog is generally not recommended -- think what would happen if 100 objects regen at the same time and start presenting dialogs. Normally the way to handle this is to create some sort of error text as part of the object which would direct the user to Object Info. Instead of a dialog, can you have the object create it's own UID? Either increment some sort of ID value or just append a number to the value until it is unique?

HTH,

Josh

Link to comment

Thanks Josh.

I am going to experiment with setting the Name of the object. It seems VW will check for unique names upon creation on its own.

I haven't tried it yet, but maybe this will solve my issue.

I guess I could also check all the other existing PIO's for duplicates, but like you mentioned a dialog would pop up to correct the problem would happen on each reset. I wonder if there is a way just check at initialization of the object. The "VSO" calls (same ones that allow a button to be placed on a PIO Object Info) available are a bit vague in description. I can't seem to find a list of what all the numbers actually do.

SetObjPropVS(??, TRUE) as a sample

Jeff

Link to comment

Yes, names are unique. If you need to use UIDs for linking, the name field is a good place for it. Not only can you check for uniqueness, but you can use GetObject to get a handle by name.

If you are just looking for a good test of uniqueness, use count. Ie, if, count(record.field.value)=0 then unique.

The initialization event is for the plug-in itself, not for each instance of the plug-in. It happens once per session -- either when a file with the plug-in gets opened or when the first plugin is placed. You really want the uniqueness check to jpen as part of the reset event.

Would you mind elaborating on what the field does?

-Josh

Link to comment

Actually, be wary of using handle as a UID. Handles are assigned at the start of script execution, and are valid for that run only. They are not saved with the object, so while they may be unique while your script executes, they will not be consistant from run to run.

If you want an "off the shelf" UID generator, try the CreateUUID function.

-Josh

Link to comment

But even if you write it to a record it is not guaranteed to be unique. If you put it in the Name field, when you duplicate the object the name is cleared so you don't have a duplicate. If you just store it in a record, when you duplicate the object the UID is duplicated also, not what you want.

You can handle this if you always do the duplication by script or if it is a PIO and you make it smart enough.

We (Vectorscripter) need a way to have record ID that is guaranteed to be unique. This could be another "Name" type field that clears when duplicated, or a new field type for record formats or something entirely different does not matter. We just need a way to use UIDs that a use copying and pasting things around in a drawing can't mess up.

Link to comment

Thanks for he tips...

Here is a brief description of what this plug-in is doing.

The field 'name' of this plug in (center) will be placed into another plug-in (point) available thru a pop up list. This will allow the other plug in (point) to find it and get its "X", "Y" location based on the user selection of the name. If the plug-in (center) is not in the file than the other plug-in (point) will use the current files center. The offset difference will be used for some dimensioning and reports of (point) based on the position of plug-in (center). Originally i was only going to use one (center), but wanted to make the plug-in a little more robust by allowing multiple (centers). If two (centers) are named the same then erroneous results happen (point usually fined the newest (center)first). I know not to have to (centers) with the same name, but don't want to rely on the user to know that. Trapping user errors always complicates things.... doesn't it??

Sorry it takes a few days for a response, but it's usually weekend warrior coding for me

Jeff

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.

Guest
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...