Page 1 of 1

[solved] deleteObject() usage

Posted: Tue Mar 13, 2018 10:28 am
by woddy
Hello,
I wrote a script action to draw circles on work screen by getting the radius and center from user. The RCircleEntity works fine it can draw circles and addObject adds them on screen. But what i want to do is to remove previous circle after user draws a new one. The past circle should be removed and the new one need to be shown.

To do that i defined another circle (circle2) that gets the previous circle values and to delete circle2 i used deleteObject operation. The actions works well for the first few circles and then qcad crashes. How can i define the second circle and delete object operation so that qcad wont crash?

Code: Select all

var circle = new RCircleEntity(
            this.getDocument(),
            new RCircleData(new RVector(pos.x, pos.y),distance))
op.addObject(circle);
var a = 1;
var circle2 = 0;
  if (a<2) {
   circle2 =   new RCircleEntity(
   his.getDocument(),
   new RCircleData(new RVector(pos.x, pos.y),distance)) }
  if (circle2 != circle && a>1) {
   op.deleteObject(circle2);
  }  
   

The problem seeems in 'op.deleteObject(circle2);' since when i delete it qcad is not crashing and also i can get the desired Rcircle values for circle and circle2. I just dont know how to use deleteObject properly,
Thanks

Version: 3.19.2.0 (3.19.2)

Re: deleteObject() usage

Posted: Wed Mar 14, 2018 10:23 am
by andrew
You need to reference the previously added entity through its ID. Creating a new entity with the same geometry is just a new entity without any relationship to the original entity.

Here's an example for adding and then deleting an entity:
https://github.com/qcad/qcad/blob/maste ... eObject.js

Re: [solved] deleteObject() usage

Posted: Wed Mar 14, 2018 10:53 am
by woddy
Thanks a lot i can do it now.