SamIWas Posted July 2, 2017 Share Posted July 2, 2017 (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 July 2, 2017 by SamIWas Quote Link to comment
Hippocode Posted July 2, 2017 Share Posted July 2, 2017 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); Quote Link to comment
Pat Stanford Posted July 3, 2017 Share Posted July 3, 2017 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. Quote Link to comment
SamIWas Posted July 5, 2017 Author Share Posted July 5, 2017 (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 July 5, 2017 by SamIWas Quote Link to comment
Pat Stanford Posted July 5, 2017 Share Posted July 5, 2017 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. Quote Link to comment
JBenghiat Posted July 12, 2017 Share Posted July 12, 2017 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 Quote Link to comment
Miguel Barrera Posted July 16, 2017 Share Posted July 16, 2017 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. Quote Link to comment
SamIWas Posted July 18, 2017 Author Share Posted July 18, 2017 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. Quote Link to comment
Hippocode Posted July 18, 2017 Share Posted July 18, 2017 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! Quote Link to comment
C. Andrew Dunning Posted August 11, 2017 Share Posted August 11, 2017 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? Quote Link to comment
Recommended Posts
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.