Need clarification regarding new layer's placement in Layers list

This section is for general discussion about Gadgets
Post Reply
rblondeau
Posts: 4
Joined: Sun Dec 10, 2023 5:52 am
Model of CNC Machine: Longmill MK2

Need clarification regarding new layer's placement in Layers list

Post by rblondeau »

I have a requirement for my Gadget to create a new layer immediately below a selected Vector's layer in the Layer's Tab. I'm able to do everything except having the new layer be at a specific location in the list.

I can create the new layer using the CADLayerManager:GetLayerWithName(string layer_name) method but the new layer is always created at the end of the list.

I can see that there is a CADLayerManager:AddLayer(CadLayer layer, int index) method but that takes a pre-existing method as an argument.

I have tried to create a reference to my new layer, removing the layer from CadLayerManager using the :RemoveLayer(CadLayer layer) method and then adding the layer back to the CadLayerManager using the :AddLayer(CadLayer layer, int index) method but that gives me the error:
(global createNewLayer)
AddLayer: std::runtime_erro: 'luabind: smart pointer does not allow ownership transfer'


Here is the code that I thought might work...

Code: Select all

	local newLayer = g_job.LayerManager:GetLayerWithName(newLayerName)
	g_job.LayerManager:RemoveLayer(newLayer)
	 g_job.LayerManager:AddLayer(newLayer, originalLayerIndex + 1)
If I can only create a new layer with the :GetLayerWithName() method and it puts the layer at the end of the list, how can I get a layer that I could then add to the list at a specific index using the :AddLayer() method?

I'm assuming I'm either overthinking this or I am misinterpreting the Vectric Interface documentation. Can someone show me how to do this?

Thanks,
Rob

ps: a CADLayerManager:Move(up or down) method would sure be nice in this situation :D

rblondeau
Posts: 4
Joined: Sun Dec 10, 2023 5:52 am
Model of CNC Machine: Longmill MK2

Re: Need clarification regarding new layer's placement in Layers list

Post by rblondeau »

I'm starting to think that this may be a bug...

By putting in MessageBox() calls after each of these lines, I can see that the layer appears on the Layers Tab after the GetLayerWithName() call.

I then can see that the layer disappears from the Layers Tab after the RemoveLayer().

I know that my newLayer variable is still referencing a valid layer because I can display it's .Name with a MessageBox() and it's correct.

It's just adding the layer back to the LayerManager that's the problem. Note: I did try using a valid specific Index value in the :AddLayer() call just to make sure it wasn't the +1 that was causing the problem. The error still occurs.

User avatar
Adrian
Vectric Archimage
Posts: 14544
Joined: Thu Nov 23, 2006 2:19 pm
Model of CNC Machine: ShopBot PRS Alpha 96x48
Location: Surrey, UK

Re: Need clarification regarding new layer's placement in Layers list

Post by Adrian »

I'm really busy at the moment so I don't have the time to investigate fully but this sounds a lot like an issue I was having a few years ago.

That turned out to be that I was holding references to a list that were no longer valid because of the removal of an item from the list so when I tried to put a new one in (it was something with toolpaths from memory) it put it on the end rather than where I expected.

I maintained two lists in the end. Again, from memory, the same technique is used in the Vectric gadgets but I don't recall which one at the moment.

If anything pops into my head about more detail while I'm rushing around with the Christmas prep I'll post again.

Post Reply