Thank you for the reply!
But i have already tried it doing the way you suggested.
It still gives the same error.
I have protected the traces that are critical so that they do not get deleted accidentally or get altered. So, whenever i try to delete those vias in the unwanted layers, it also throws an exception that they are protected, which is valid.
I am not sure whether this is hindering my approach!
But i cannot unprotect fhem for the fear of them getting deleted when i try to delete vias in the unwanted layers.
you are talking about the partial vias or through vias?
through vias need not to be deleted when you are deleting the layers, but partial vias has to be temporarily set to through vias for deleting the layers
Ideally it is best to delete the layers that you aren't using.
Remember that you don't need to generate a Gerber file for every layer. So if you delete all routing off Layers 4 and 5 you can ignore them and then delete them from the CAM list. I've seen that is designs before from a professional designer that I work with. That is a simple workaround.
Its better to delete everything off the layers you do not want and then reduce the number of layers. The problem with still having the layers in the pcb file is if you have even one trace on those layers then you will not get any connectivity errors in pads and the gerbers will be incorrect.