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.

Macro to turn on/off layers

Started by MarkX, January 08, 2013, 07:40:38 PM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

MarkX

I'm pretty sure I saw that someone had written a macro that would let you use the command line to quickly turn on/off sets of layers. I tried searching through the forum to no avail.

Can someone point me to them and/or post them?

Thank you!
Mark

Bob P

I have my own set of macros here.  Note that the savl.d3m macro creates separate file lists for each of the layer groups that you create with the <name of the file>.dva through .dvz.

MarkX

Hi Bob,

I'll have to poke around in the code. The first time I tried using the "L" command it failed -- its looking for a hard-coded colors.txt file in a DCMAX15 folder.

Thanks!
Mark

Bob P

This eliminates the need for colors.txt, but it won't change the color of an entity when the layer is changed.  I use the color to identify the layer a lot, so changing the color is useful to me.

'Program l.d3m 
'version 14 command line version
'If nothing is selected, it changes the current layer
'If entities are selected, it changes the layers of the entities to the command line argument

dim entlist(4000)

layy$=sys$(0)
if layy$ = "" then input "Enter layer number: ", layy$
dest = val(layy$)

if sys(80)=0 then
layer(dest)=14
end
else
end if

nsel = sys(80)
for j = 1 to nsel
getselect j, entlist(j)
next j
sys(80)=0

>RegenerateAll
{
}

END:


If you want to retain my color-changing, you'll have to change the path to the colors.txt file within the macro.

MarkX

 Hi Bob,

I'm getting the attached message when I try to restore a layer set.

This happened right after defining the set, so there's no possibility that I changed the layers before invoking the rv command.

Thanks!
Mark

Bob P

#5
What is the highest number layer in your drawing?  It can easily be changed, but for speed reasons, the macro only works for the first 120 layers.  Easily changed though.
I've attached the rv and savl macros compatible with 2000 layers.  At least according to my quick tests...

MarkX

Quote from: Bob P on January 11, 2013, 02:36:40 AM
What is the highest number layer in your drawing?  It can easily be changed, but for speed reasons, the macro only works for the first 120 layers.  Easily changed though.
I've attached the rv and savl macros compatible with 2000 layers.  At least according to my quick tests...
The highest layer is 8.

Thanks!
Mark

Bob P

Everything works for me.  If the new macro is still broken for you, I'll have to look through the code again.  It's been 6 years since I wrote that, so I'll have to re-learn the macro's flow.

MarkX

Quote from: Bob P on January 11, 2013, 10:51:21 AM
Everything works for me.  If the new macro is still broken for you, I'll have to look through the code again.  It's been 6 years since I wrote that, so I'll have to re-learn the macro's flow.
Hi Bob,

I'm guessing that there's a new layer status type or that status 0 is being sent back as 5. Although the error said that the layer was out of range, in fact it appears that its happening at layer #3. But the status code is 4. I don't see a status "4" in the Version 17 reference. (it was status 5, but your program adjusts it to 4).

So ... anyone know what status 4 is supposed to mean? I believe that the status was supposed to be "0" : Invisible and not Editable. So maybe just need a special adjustment for case where original status = 5.

Thanks!
Mark

Bob P

It could have to do with locked-but-visable layers.  I never use those, but it's a status that that might show up in your drawing.

dcadRob

Use ODD() to decode the meaning:
QuoteLAYER(x) - Layer status of layer x. Returns 0-15

[legal values: 0, 1, 2, 3, 6, 7, 14, 15]

Assume y=LAYER(x)

if ODD(y)=0,-> no entities in layer x. [y = 0, 2, 6, or 14]

if ODD(y)=1,-> entities are in layer x. [y = 1, 3, 7, or 15]

if ODD(y\2)=0, -> layer x is invisible. [y = 0 or 1]

if ODD(y\2)=1, -> layer x is visible. [y = 2, 3, 6, 7, 14, or 15]

if ODD(y\4)=0, -> layer x is not editable. [y = 0, 1, 2, or 3]

if ODD(y\4)=1, -> layer x is editable. [y = 6, 7, 14, or 15]

if ODD(y\ 8 )=1, -> x is the current layer. [y = 14 or 15]
So 4 means - no entities, not visible, editable
and 5 means - entities, not visible, editable

prl

Quote from: dcadRob on January 12, 2013, 05:40:24 AM
So 4 means - no entities, not visible, editable
and 5 means - entities, not visible, editable

Yes,  but as far as I know, we can't set those states with the Layer statement.  You'll have to pick one of the following:

QuoteThe LAYER statement can be used to set a layer to be visible/invisible or editable/uneditable. It can also be used to set the current layer. The following values can be used with the LAYER statement:

0 – Invisible and not editable
2 – Visible but not editable
6 – Visible and editable
14 – Set as current layer (the current layer is always visible and editable)

dcadRob

It may be possible that a 4 or 5 layer exists but can't be set that way with BasicCAD.

I recall that there was a discussion about some of these weird states (ie not visible but editable).

Was it a bug? I don't remember. There have been a lot of changes to layers so it's possible.

prl

Quote from: dcadRob on January 12, 2013, 06:26:18 AM
I recall that there was a discussion about some of these weird states (ie not visible but editable).

Was it a bug? 

That discussion was between Phil and myself.  He demonstrated the existence of these new states.  Bug, partially implemented new feature back in version 15, hard to say.

If we could set those states, I could give Phil a macro for the way he uses groups across turned off layers.

Dr PR

Just to rehash that discussion, DesignCAD maintains separate variables for visibility and locked. Therefore, a layer can exist in these four logical states:

A. Visible and unlocked
B. Visible and locked
C. Invisible and unlocked
D. Invisible and locked

However, the program enforces an artificial "editability" protocol onto the four logical states. To the user normally there are only two states of editability as defined by this logical truth table:

                Unlocked      Locked
Visible      Editable       Uneditable
Invisible   Uneditable   Uneditable

This is because the program automatically locks a layer when you make it invisible.

The user can lock a visible layer to produce three common conditions:

E. Visible and unlocked (editable)
F. Visible and locked (not editable)
G. Invisible and locked (not editable)

However, if you open the Layers Dialog and click "Unlock All" the locked state of ALL layers will be switched to unlocked - even for invisible layers. This creates a fourth editability state:

H. Invisible and unlocked (editable if you can figure out how to select it)

In this state the Layers  Dialog "locked" icon does not change to show that invisible layers are unlocked. The "lock" icon only shows the "editability" status, and it doesn't do that correctly. Any way you look at it this is a bug.

You can't select invisible objects on unlocked invisible layers by gravity snapping to them. However, if they are a part of a multilayer group, and part of the group is visible, you can select the entire group by snapping to a visible part.

****

The confusion about how this works is because DesignCAD tries to "think" for the user to prevent logical state D to occur (invisible and unlocked). To me, this is irrational and has always been a bug. Normally this wouldn't be a problem, because we wouldn't disable a layer if we wanted to edit objects on that layer.

However, another bug in DesignCAD makes it necessary for users to be able to create the invisible and unlocked state. Sometimes after a solid Boolean operation with an object having a complex surface grid the program moves some of the grid facets to other layers. This generates a grid (and the solid it is a part of) that exists on two layers, the original layer and another layer that the user is unaware of. If the wayward facets are on an invisible and locked layer the solid can no longer be selected. The user has no way to determine where the wayward facets are scattered (usually they are on layer zero, but I have found them on high numbered layers as well).

Fortunately, all you have to do is:

1. Open the Layers Dialog and click "Unlock All." This unlocks all invisible layers (logical state C, editable state H).

2. Select the solid, open the Info Box, and reassign the desired layer to the solid. This brings the wayward grid facets back the same layer as the rest of the grid.

3. The Info Box will also indicate that the solid has "multiple" materials and more than one color. You must also reassign the material to the solid, and you may have to reassign the color. When the program misplaces the grid facets it usually turns them into the "Aluminum" material. At least this is what happens to grids that are the "Default" material.

****

The sad part of this is that there never was a need for "editable" and "uneditable" states. The visible/invisible and locked/unlocked states work perfectly rationally. However, some bright guy thought that the average user wasn't capable of thinking logically (perhaps true) and forced "editability" upon us.

Some people claim that the invisible and unlocked state is a bug. This is totally incorrect! If this non-bug is ever "fixed" we will be totally screwed. We will end up with objects in the drawings that cannot be selected and removed.

One option is to make all layers visible (Layers Dialog "Show All") but this will destroy the visible/invisible states that the user has set up. If it is a large drawing the solid of interest might be lost in a cloud of other objects, making it harder to see and select. Then we can unlock all layers. After doing these two things we can select the miscreant solid and use the Info Box to repair it.

It is a lot simpler to just unlock all layers without changing the visibility, and then select the solid. This is possible because of the four logical states that exist in the current program.

Phil
DesignCAD user since 1987