Carles Olle Posted December 10, 2016 Share Posted December 10, 2016 Hi, I'm creating PIO that can be created inside a symbol. I'm using a code similar to this: def execute(): objDlg = createObjectDialog() if vs.RunLayoutDialog(objDlg, objectDialogHandler) == kOK: if createSymbol == "True": vs.BeginSym(symbolName) object = vs.CreateCustomObject("MyObject", 0, 0, 0) vs.Record(picture, "MyObject") vs.Field(picture, "MyObject", "objectName", objectName) ... vs.ResetObject(object) vs.SetName(object, objectName) if createSymbol == "True": vs.EndSym() The symbol is created properly. The problem comes when, from the Resource Manager panel you right click the created symbol and select "Duplicate..."; When you duplicate the symbol, the object instance of the original symbol is used for the duplicated symbol. In this way, if you modify the object inside the duplicated symbol, the object inside the original symbol (same instance) is also affected. Is there a way to force to create a new object instance (copy) whenever you duplicate a symbol? Thanks --Carlos Quote Link to comment
Hippocode Posted December 10, 2016 Share Posted December 10, 2016 This is how symbols are designed to work. Only the definition is unique, all placed symbols are exact copies. The only way around, is to make your wrapper an object, or maybe your current object the parent of whatever you want to create. Then each object instance can be unique. Also, you can still save that object as a red symbol if you want it to appear in the resource browser as well. Quote Link to comment
JBenghiat Posted December 12, 2016 Share Posted December 12, 2016 Is the snippet above part of the PIO, or a separate menu command that places the PIO inside a symbol. If it is part of the PIO, you should only do this as part of a button press. If I'm understanding the scenario correctly, you have a PIO inside of a symbol. You then duplicate the symbol in the resource browser. What you see is expected--the duplicated symbol contains an exact duplicate of the PIO. You should be able to edit the symbol definition and change the parameters of the PIO without the original PIO changing. If you're looking to have the duplicated PIO do something on duplication, like generate a unique ID number, you can set the PIO to event enabled and respond to the object-created event. HTH, Josh Quote Link to comment
Carles Olle Posted December 12, 2016 Author Share Posted December 12, 2016 Hi Josh, Yes, the code is part of a menu command. Yes, your understanding is correct. I take some actions when the PIO instance is duplicated; Change a contained Image Prop, change the ID, etc. The PIO entry function is called when I duplicate the PIO manually (not as part of a symbol duplication) but the PIO entry function does not seem to be called when the duplication happens as part of a symbol duplication and the two PIOs end up containing the same Image Prop. This is the snipped I use for the kObjOnInitXProperties event handling: if theEvent == vs.kObjOnInitXProperties: # Enable custom shape pane _ = vs.SetObjPropVS( vs.kObjXPropHasUIOverride, True ) _ = vs.SetObjPropVS( vs.kObjXHasCustomWidgetVisibilities, True ) vs.SetPrefInt(vs.varParametricEnableStateEventing, 1) _ = vs.SetObjPropVS( vs.kObjXPropAcceptStates, True ) _ = vs.SetObjPropVS( vs.kObjXPropAcceptStatesInternal, True ) InitParameters() Cheers --Carlos Quote Link to comment
JBenghiat Posted December 13, 2016 Share Posted December 13, 2016 Your object appears to be event enabled and accepting states. You want to check for this state: kObjectCreated = 13. This will be true when the object is created via any method, including inserting and duplicating. -Josh 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.