Jump to content
Developer Wiki and Function Reference Links ×

IsNewCustomObject


Recommended Posts

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;

Link to comment

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

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

Link to comment

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.

Link to comment

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.

Link to comment

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.

Link to comment
  • Vectorworks, Inc Employee

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.

Link to comment

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