SamIWas

Update PIO with duplication

10 posts in this topic

Posted (edited)

Expanding functionality of some of my tools a bit further.  I need each object created by the tool to have a unique identifier so that data can be imported and exported between Filemaker.  I have created an ID field in one of my tools in which I create this unique ID upon creation of each object.   This works perfectly currently.  However, any time I duplicate an object, the ID field will not regenerate until I change another field, which kind of negates the purpose.  I've been trying to use the workarounds shown in the IsNewCustomObject page of the Language Guide, but I can't seem to get them to work either until I specifically modify a field in the OIP.

 

Has anyone figured out a secret to a PIO updating upon duplication?   The Lighting Device tool does it, so it must be possible.

 

And, while we're at it:  I know how to make a field in the OIP not editable.  But, how can I make the object name also not editable?  Can't seem to find the right procedure.

Edited by SamIWas
0

Share this post


Link to post
Share on other sites

I manage duplication using the kObjectCreated (13) event. In there I force it to -1. Next my object reset codes loads the ID and replaces it whenever it's -1.

On default, your object should reset after the above event is called.

 

Disabling the unique name field can be done by setting an object property (35) in the object init event. Example from the SDK

    extProps->SetObjectProperty(objectID, kObjXPropDataNameDisabled, false);

 
0

Share this post


Link to post
Share on other sites

Unless you are using the SDK, the only absolutely reliable way to have a field cleared when you duplicate an object is to use the NAME field shown in the OIP. That has it's own problems in that it is user accessible, but it is the only place in VW where you can trust the the data will be unique.

0

Share this post


Link to post
Share on other sites

Posted (edited)

Whoa. That all sounds way above my head!  But I'll look it up...don't know anything about the SDK or kObj type stuff. 

 

That's a shame. Was hoping for something more elegant than having to assign them upon export. 

Edited by SamIWas
0

Share this post


Link to post
Share on other sites

I have advocated for years that there should be a PIO field type of Clear on Creation or something similar. Even just a single field the programmer could use and trust that the field would either be cleared or reset to a know value upon creation/duplication would be very helpful.

 

I am pretty sure the VWInc has had to jump through hoops on several of there objects to overcome this problem. Hopefully some of that will eventually flow out to user accessible ways of doing this.

0

Share this post


Link to post
Share on other sites

Pat, you don't necessarily need the SDK to detect new objects, and most of the foibles of dealing with UID's are also present in the SDK.

 

Going back to @Hippocode's comment, you can get better detection of new objects using state events, rather than with IsNewCustomObject(), which only works with objects inserted with their tool.  I believe there are a few other posts on how to set up an object to accept states, if you need it.  The state you're looking for is kObjectCreated, which equals 13.  (The constant name becomes relevant if you're working with the SDK, but for VS you need to define the constant yourself).  

 

This should catch all new instances of the object except for when it's inserted via a script.  Make sure you test manual insertion, paste, duplicate, and option-drag.  They all trigger a slightly different sequence of events.

 

-Josh

0

Share this post


Link to post
Share on other sites

I believe this could be simplified just by testing for duplicate ID. If there is more than 1 of the same ID then assign a new one to the created object. The only one regenerating would be the duplicated one because it is a new object.

 

I have not tried this on a copy and paste operation because in my work flow, I create a new object instead but checking for duplicates should work for any new object.  In my object, which is a pipe, If the ID field is empty, it will look for the next available ID and assign it to the newly created pipe. In your case, I would test on every regeneration, which would add unnecessary code some times but I do not think the delay would be noticeable.

0

Share this post


Link to post
Share on other sites

Yep...the way mine is currently set up is that is uses IsNewCustomObject() to generate an ID upon creation, looking at existing IDs and adding 1.  Then when duplicated, it checks the ID against the object name, which changes no matter what.  If those two are different, it changes the ID number.  But, this will only happen upon regeneration, which requires changing a field.  SO, for now, that's what I do.  I'll have to look up how to deal with kObjectCreated/13.  

0

Share this post


Link to post
Share on other sites

Just keep in mind that kObjectCreated is called several times for one object, also when the tool creates a dummy object visible on the screen!

0

Share this post


Link to post
Share on other sites

For any of you; who've had success using kObjectCreated to test for creation and duplication - and, using that to set up a unique ID field - how are you accounting for the duplication of multiple selected objects?

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now