VectorGeek Posted May 13, 2016 Share Posted May 13, 2016 Hi friends: I just realized while debugging a script that this procedure generates both a message and an alert dialog. In other words, IsNewCustomObject is not working because the code appears to execute twice during object placement. So the first time, IsNewCustomObject is TRUE, then it's FALSE, all during a single placement of a PIO. I recall Miguel posting something about this, but I'm at a loss to understand is this is truly what is happening. If this is true (running code twice), is the IsNewCustomObject procedure of any use? Thanks!!! V_G. IF IsNewCustomObject(myName) = true THEN BEGIN iullength := pullength; iulthick := pulthick; cp01X := itotalrun + iullength; cp01Y := itotalrise - iulthick; SetRField(myHand,myName,'CONTROLPOINT01X',Num2StrF(cp01X)); SetRField(myHand,myName,'CONTROLPOINT01Y',Num2StrF(cp01Y)); Message('I'm New'); END ELSE BEGIN cp01X := itotalrun + iullength; cp01Y := itotalrise - iulthick; SetRField(myHand,myName,'CONTROLPOINT01X',Num2StrF(cp01X)); SetRField(myHand,myName,'CONTROLPOINT01Y',Num2StrF(cp01Y)); alrtdialog('1234'); END; Quote Link to comment
Hippocode Posted May 13, 2016 Share Posted May 13, 2016 (edited) It could be that when creating a new object, it's made to recalculate twice. Once with the event "OnFirstCreated" which makes your function return true, and once as an external reset at which point it isn't a new object anymore. You can test this by adding a dialog out of the scope of your IF ELSE structure. Edited May 13, 2016 by Hippocode Quote Link to comment
VectorGeek Posted May 13, 2016 Author Share Posted May 13, 2016 Thanks Hippo. So "IsNewCustomObject" is really useless then, because the second time, the object isn't new? V-G. Quote Link to comment
Hippocode Posted May 13, 2016 Share Posted May 13, 2016 Thanks Hippo. So "IsNewCustomObject" is really useless then, because the second time, the object isn't new? V-G. I disagree. The function works as expected. What do you want to do actually ? Quote Link to comment
MullinRJ Posted May 14, 2016 Share Posted May 14, 2016 VG, PIO code executes multiple times when placing an object. If you put an AlrtDialog() call in your event loop at the very top, you can count how many times it actually goes through. The count may differ between object creation and object regeneration, but I'm not sure anymore. I've forgotten more than I currently remember on this topic. I know on one loop through your code, VW builds the gray outline that shows on the screen before you click to place it. Another loop actually builds your object. If you want to see how many times VW thinks your object is new, change your Message() to an AlrtDialog() and count. This is all part of the fun of figuring out how things really get done. Please be careful and avoid having too much fun at one time. It could drive you to drink (or worse). Good luck, Raymond Quote Link to comment
Miguel Barrera Posted May 15, 2016 Share Posted May 15, 2016 I did test this a long time ago and do not know if it works know. What I found back then was that it returns true only on the first instance of the object in the current document. If you insert any more objects of the same kind in the document, it returns false. I would expect that the function will return true every time that you insert a new object. The workaround that I use is to test for a parameter value that should not be empty. If empty, it is a new object. If it has a value, then it has gone thru the reset event already. As Raymond described above, the first iteration of the reset event draws the outline of the object but the parameters are not filled in if you have any SetRField calls. It is on the second reset event that parameters are saved. Quote Link to comment
Miguel Barrera Posted May 15, 2016 Share Posted May 15, 2016 I did test this a long time ago and do not know if it works know. What I found back then was that it returns true only on the first instance of the object in the current document. If you insert any more objects of the same kind in the document, it returns false. I would expect that the function will return true every time that you insert a new object. The workaround that I use is to test for a parameter value that should not be empty. If empty, it is a new object. If it has a value, then it has gone thru the reset event already. As Raymond described above, the first iteration of the reset event draws the outline of the object but the parameters are not filled in if you have any SetRField calls. It is on the second reset event that parameters are saved. Quote Link to comment
Miguel Barrera Posted May 15, 2016 Share Posted May 15, 2016 I did test this a long time ago and do not know if it works know. What I found back then was that it returns true only on the first instance of the object in the current document. If you insert any more objects of the same kind in the document, it returns false. I would expect that the function will return true every time that you insert a new object. The workaround that I use is to test for a parameter value that should not be empty. If empty, it is a new object. If it has a value, then it has gone thru the reset event already. As Raymond described above, the first iteration of the reset event draws the outline of the object but the parameters are not filled in if you have any SetRField calls. It is on the second reset event that parameters are saved. Quote Link to comment
Vectorworks, Inc Employee klinzey Posted May 16, 2016 Vectorworks, Inc Employee Share Posted May 16, 2016 Also be sure you are not running with developer mode turned on. Because you are compiling the plug-in every time you will get extra events. With developer mode turned on you will often see problems with multiple selection and pop-up because the VS event messaging can only handle a singe message per reset. Quote Link to comment
VectorGeek Posted May 18, 2016 Author Share Posted May 18, 2016 Ray, Miguel, Kevin: Thanks for the feedback. I think Kevin has it - it's related to Developer Mode. Of course that's how we do all our testing, but the users never turn it on. That's why I was seeing inconsistent results! Cheers. V-G. 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.