Jump to content
Developer Wiki and Function Reference Links ×

Update PIO with duplication


Recommended Posts

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
Link to comment

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);

 
Link to comment

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.

Link to comment

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
Link to comment

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.

Link to comment

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

Link to comment

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.

Link to comment

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.  

Link to comment
  • 4 weeks later...

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