DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Need Macro to Delete Empty Layer Names ???

Started by CLM, April 28, 2010, 07:47:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

CLM

Many times when I import a drawing from AutoCAD or some other program, I get a lot of layers and layer names that I don't neccesarily want to keep. I routinely move the imported entities from several layers into a single layer. When I am done I end up with a pile of empty layers that have the names from the imported file. I'd like to have a macro that can look through all the layers in my DCAD file to see if they are empty or not. If the layer is empty, then I want it to automatically delete the empty layer's name.

Does anyone have a simple macro to do this?   ???

Lar

#1
The following macro unnames empty layers while maintaining all the layer setups (to access a layer's name in a macro it has to be made the current layer so otherwise all your layers will be turned on by the time the macro ends) and it doesn't matter how many layers your version has. It will first ask your permission in case you run the macro by mistake.

Still, test on a trial file first.

Lar
ps: I also noticed that if you save, run the macro then close, or open the file, run the macro then close the file dcad won't ask if you want to save... so to fix that I have the macro draw a small line then Undo.


'***MacroStart***
'Unname Empty Layers.d3m
'by Lay, Nassau, Bahamas
'29 April 2010
'Macro to clear the names of empty layers.

sys(1027)=4   'message box style yes/no...
message " This Macro will Clear the Names of Empty Layers. Do you want to Continue?..."
'if no...
if sys(1028)=7 then end
sys(1027)=0  'restore default message box style [ok]

CurLay=sys(3)  'record the original current layer

sys(36)=1   'silent mode

on error goto fin  'for versions that have less than 2000 layers (below v19)
for lay=0 to 2000
y=layer(lay)
if ODD(y)=0 then  'if layer is empty then...

if ODD(y\2)=0 then   'layer is off...
LayStat=0
goto nx
end if
if ODD(y\2)=1 and ODD(y\4)=0 then    'lay is on but uneditable...
LayStat=2
goto nx
end if
if ODD(y\2)=1 and ODD(y\4)=1 then
if ODD( y\8 )=1 then                                   'lay is current...
LayStat=14
goto nx
end if
end if
'if none of the above...
LayStat=6     'lay is on and editable...
nx:

layer(lay)=14            'has to make layer current to access its name...
sys$(93)=""              'layer name is made blank...

layer(CurLay)=14     'restore orig. current layer...
layer(lay)=LayStat    'restore status of this layer, even if it's the orig. current lay...

end if 'ODD(lay)=0

next 'lay

fin:
'if you save, run the macro then close, or open the file, run the macro then close the file...
'dcad won't ask if you want to save so I'm doing the following:
>line
{
<pointxyz 0,0,0
<pointxyz 1,0,0
}
>Undo
{
}

sys(36)=0   'silent mode off
message "-done-"
end
''***MacroEnd***

magic

#2
Hi Lar,

You seem to have a smiley in the middle of your macro. How does that work? 8)

It's a good idea to insert code in a code box (Please check that I read your smiley right):

'***MacroStart***
'Unname Empty Layers.d3m
'by Lay, Nassau, Bahamas
'29 April 2010
'Macro to clear the names of empty layers.

CurLay=sys(3)  'record the original current layer

sys(36)=1   'silent mode

on error goto fin  'for versions that have less than 2000 layers (below v19)
for lay=0 to 2000
y=layer(lay)
if ODD(y)=0 then  'if layer is empty

y=layer(lay)
if ODD(y\2)=0 then   'layer is off...
LayStat=0
goto nx
end if
if ODD(y\2)=1 and ODD(y\4)=0 then    'lay is on but uneditable...
LayStat=2
goto nx
end if
if ODD(y\2)=1 and ODD(y\4)=1 then
if ODD(y\8)=1 then                                   'lay is current...
LayStat=14
goto nx
end if
end if
'if none of the above...
LayStat=6     'lay is on and editable...
nx:

layer(lay)=14            'has to make layer current to access its name...
sys$(93)=""              'layer name is made blank...

layer(CurLay)=14     'restore orig. current layer...
layer(lay)=LayStat    'restore status of this layer, even if it's the orig. current lay...

end if 'ODD(lay)=0

next 'lay

fin:
'if you save, run the macro then close, or open the file, run the macro then close the file...
'dcad won't ask if you want to save so I'm doing the following:
>line
{
<pointxyz 0,0,0
<pointxyz 1,0,0
}
>Undo
{
}

sys(36)=0   'silent mode off
message "-done-"
end
''***MacroEnd***


Code changed as per your instructions, Lar.

Thank you very much.
It's a kind of magic!




Lar

#3
Thanks, Magic.

All that means is that there's an 8 followed by a ), which the forum interprets as a 'Cool' smiley.

To fix that I will simply put a space between the 8 and the ).

Lar



Lar

Magic, I added some stuff after "fin" near the bottom of the macro (see the ps in my opening post). maybe you can update your macro box.

Lar

CLM

Lar,

Thank you very much for this macro. Sorry for the delayed response. It works perfectly.

Thanks,

CLM