[solved] deleteObject() usage

Use this forum to ask questions about how to do things in QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
woddy
Junior Member
Posts: 13
Joined: Mon Mar 05, 2018 10:44 pm

[solved] deleteObject() usage

Post by woddy » Tue Mar 13, 2018 10:28 am

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)
Last edited by woddy on Wed Mar 14, 2018 10:53 am, edited 1 time in total.

User avatar
andrew
Site Admin
Posts: 9019
Joined: Fri Mar 30, 2007 6:07 am

Re: deleteObject() usage

Post by andrew » Wed Mar 14, 2018 10:23 am

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

woddy
Junior Member
Posts: 13
Joined: Mon Mar 05, 2018 10:44 pm

Re: [solved] deleteObject() usage

Post by woddy » Wed Mar 14, 2018 10:53 am

Thanks a lot i can do it now.

Post Reply

Return to “QCAD 'How Do I' Questions”