Page 1 of 1

Create an entity on another Layer (D4D)

PostPosted: Tue Nov 06, 2018 3:07 pm
by dhs
Hi,
To create an entity on a layer that is not the current layer in Classic DCAL I have previously saved the current layer, switched to another layer to create the entity, and then switched back to the saved layer... similar procedure to copy any entity to another (non-current) layer.

This is not possible in D4D as the Lyr_Set procedure does not work. I seem to recall that simply changing the layer in the entity record does not work, so can anybody tell me a method to copy an entity to another layer in D4D ?

Thanks,
David H.

Re: Create an entity on another Layer (D4D)

PostPosted: Tue Nov 06, 2018 4:02 pm
by David A. Giesselman
dhs wrote:... I seem to recall that simply changing the layer in the entity record does not work, so can anybody tell me a method to copy an entity to another layer in D4D ?

Are you calling ent_update after changing the layer field?

Re: Create an entity on another Layer (D4D)

PostPosted: Tue Nov 06, 2018 5:53 pm
by dhs
Dave G wrote: Are you calling ent_update after changing the layer field?

Yes, I am calling ent_update. The following code is from a small test macro that I wrote:
Code: Select all     lyr_create ('Test Layer', lyr_addr);
     mode_init (mode);
     mode_lyr (mode, lyr_curr);
     addr := ent_first (mode);
     if ent_get (ent, addr) then begin
         ent.lyr := lyr_addr;
         ent_update (ent);       // crashes on this call
     end;
     callNone(retval);


It fails on the ent_update call with "DataCAD (internal diagnostics) fault 19 Error from: 736" and crashes out of the drawing.

Re: Create an entity on another Layer (D4D)

PostPosted: Mon Oct 21, 2019 7:39 am
by sam_bar
David A. Giesselman wrote:
dhs wrote:... I seem to recall that simply changing the layer in the entity record does not work, so can anybody tell me a method to copy an entity to another layer in D4D ?



Tray to write somthing between
ent.lyr := lyr_addr;

//and
ent_update (ent);

// for example
pause(0.01);


Mybee that may help

Samuel Bar
Israel

Re: Create an entity on another Layer (D4D)

PostPosted: Mon Oct 21, 2019 1:06 pm
by dhs
Tray to write somthing between


Thanks for the suggestion. I think I may have tried that in the past, but not absolutely sure. It would be a last resort to add a delay as I would have doubts about its reliability in all circumstances.

But in fact, my original post was incorrect:
lyr_set does in fact work in D4D. My original testing of this was trying to copy an entity to a newly created layer, so I was calling lyr_create followed by lyr_set (with lyr_set using the lyr that was returned by lyr_create). The layer was being created but lyr_set was not working (so I assumed that lyr_set did not work). The actual situation is that lyr_create does not correctly return the address of the newly created layer.
The workaround for this is to do a lyr_find to get the layer address after it is created but before calling lyr_set. This is an imperfect workaround as it is possible for D4D to create multiple layers with the same name, but it is the best solution I have been able to come up with and works in any practical situation where you would try to avoid duplicate names anyway (I think the DataCAD interface stops users creating duplicate names in recent versions, so you just need to ensure that your macro doesn't create duplicates).