News:

Please note new Forum URL: forum.designcad.com

Main Menu
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.

Unlock-All macro

Started by Bob P, January 13, 2013, 05:30:45 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bob P

V22.1
Gents,

I'm just trying to create a command-line macro to unlock all layers.  I haven't found a direct way (sys or record macro) to do it, so I tried this as a brute-force method.  The problem is that my docs for V15 and V17 are different.  The first macro doesn't run at all. See the notes in the macro.
'Unlock all layers
'Version 1 using allowed values from the V15 docs

for n=1 to 2000
if layer(n)=0 then layer(n)=6  'This line is not perfect, since it changes an invisible/empty layer to visible
if layer(n)=3 then layer(n)=7  'This line returns an error message!  But - both the values are allowed according to V15.  I don't see the problem.
next n

end


Then I tried this using only the V17 allowed values.  Sloppier even, but it runs.  Unfortunately is doesn't do anything...
'Unlock all layers Version 2
'Uses only allowed values from V17 docs.

for n=1 to 2000
if layer(n)=0 then layer(n)=6
if layer(n)=2 then layer(n)=6
next n

end


prl

#1
Bob,

The Layer Statement can't be used like that in the if statement.    Layer(n)=0 is an assignment.  You need to use the Layer function to be processed with the if statement. See my code posted before yours (http://forum.designcad.com/index.php?topic=4754.msg29955#msg29955).


And to save you some time, the only way to unlock all is to use the statement Layer(i) = 6 and put that through a layers loop. That makes the layers visible and editable (unlocked).  To trick DesignCAD, I put my loop inside a suppressed screen regen.  This will let Phil select his group or solid and then it immediately locks the layers with appropriate visibility (on/off) as he had it.

dcadRob

If you have entities in a layer then layer(n) will return an odd number which you are not testing.

Brute force is :
For i=1 to 2000
Layer(i)=6
Next i

prl

Bob, in case I confused you (and myself).  There are a few places in BasicCAD where BasicCAD functions can't be used as variables.   Right at the moment I can't remember if DesignCAD will evaluate the if statement with layer(n)=0 as a statement or if it will properly evaluate the layer(n) function as a variable for the comparison.   Hence I've always separated out the layer function just to be sure.

y = layer(n) 'the function

if y = 0 then . . . . .




paulerens

#4
This I have already tried earlier, but does not work.

Lar

#5
You have to use the following with if/then when dealing with the status of layers:

'y=layer(lay)
'if ODD(y)=0,         'no entities in layer lay
'if ODD(y)=1          'entities are in layer lay
'if ODD(y\2)=0      'layer lay is invisible.
'if ODD(y\2)=1      'layer lay is visible.
'if ODD(y\4)=0      'layer lay is not editable.
'if ODD(y\4)=1      'layer lay is editable.
'if ODD(y\8)=1      'lay is the current layer.


'0 – Invisible and not editable
'2 – Visible but not editable
'6 – Visible and editable
'14 – Set as current layer


So to unlock all that are on and locked:

for lay=0 to 2000
y=layer(lay)
if ODD(y\2)=1 and ODD(y\4)=0 then layer(lay)=6
next


Lar

prl

#6
Guys, this is for the Layer function with my take on the direct results.  See if you can come up with other combinations.  I can check the states with a drawing item below:

Sorting by function code:
  0 - Not visible / empty / not editable
  1 - Not visible / not empty / not editable
  2 - Visible / empty / not editable
  3 - Visible / not empty / not editable
  4 - Not visible / empty / editable
  5 - Not visible / not empty / editable
  6 - Visible / empty / editable
  7 - Visible / not empty / editable
14 - Current Active Layer / empty (Always visible / always editable)
15 - Current Active Layer / not empty (Always visible / always editable)


Sorting by Layer entities:
  0 - Empty / not visible / not editable
  2 - Empty / visible / not editable
  4 - Empty / not visible / editable
  6 - Empty / visible / editable
14 - Empty / Current Active Layer (Always visible / always editable)

  1 - Not empty / not visible / not editable
  3 - Not empty / visible / not editable
  5 - Not empty / not visible / editable
  7 - Not empty / visible / editable
15 - Not empty / Current Active Layer (Always visible / always editable)



   

Dr PR

prl,

To quote Lar:

'y=layer(lay)
'if ODD(y)=0,         'no entities in layer lay
'if ODD(y)=1          'entities are in layer lay
'if ODD(y\2)=0        'layer lay is invisible.
'if ODD(y\2)=1        'layer lay is visible.
'if ODD(y\4)=0        'layer lay is not editable.
'if ODD(y\4)=1        'layer lay is editable.
'if ODD(y\8)=1        'lay is the current layer.


'0 – Invisible and not editable
'2 – Visible but not editable
'6 – Visible and editable
'14 – Set as current layer


Sorry about the idiotic happy face. The forum did that, not me.

The control variable is a 4 bit nibble (the lower 4 bits of a byte), with each bit defined this way:

Bit 0 = layer empty state, 0 = the layer is empty, 1= the layer is not empty
Bit 1 = layer visibility state, 0 = invisible, 1 = visible
Bit 2 = layer locked state, 0 = locked, 1 = unlocked
Bit 3 = current layer, 0 = not current layer, 1 = current layer

Note: bit 2 DOES NOT control the "editability" of  alayer as defined in the User Reference and help files - see below.

Now do the binary to decimal conversions:

Bibary    Decimal     Functions
0000 =       0      =  not current, locked, invisible, empty
0001 =       1      =  not current, locked, invisible, not empty
0010 =       2      =  not current, locked, visible, empty
0011 =       3      =  not current, locked, visible, not empty
0100 =       4      =  not current, unlocked, invisible, empty
0101 =       5      =  not current, unlocked, invisible, not empty
0110 =       6      =  not current, unlocked, visible, empty
0111 =       7      =  not current, unlocked, visible, not empty
1000 =       8      =  current, locked, invisible, empty
1001 =       9      =  current, locked, invisible, not empty
1010 =      10     =  current, locked, visible, empty
1011 =      11     =  current, locked, visible, not empty
1100 =      12     =  current, unlocked, invisible, empty
1101 =      13     =  current, unlocked, invisible, not empty
1110 =      14     =  current, unlocked, visible, empty
1111 =      15     =  current, unlocked, visible, not empty

If you do the math that lar has posted to test each bit independently,

if dividing by 1 does not return an odd value, bit 0 = 0  = the layer is empty
if dividing by 1 returns an odd value, bit 0 = 1               = the layer is not empty
if dividing by 2 does not return an odd value, bit 1 = 0  = the layer is invisible
if dividing by 2 returns an odd value, bit 1 = 1               = the layer is visible
if dividing by 4 does not return an odd value, bit 2 = 0  = the layer is not editable (locked)
if dividing by 4 returns an odd value, bit 2 = 1               = the layer is editable (unlocked)
if dividing by 8 does not return an odd value. bit 3 = 0  = the layer is not the current layer
if dividing by 8 returns an odd value. bit 3 = 1               = the layer is the current layer

As you can see, bit 1 controls the visibility of a layer, and bit 2 controls whether or not the contents of the layer can be changed. These are the two variable I have been talking about in other threads.

The "editability" control that the program code enforces is the logical and of bits 1 and 2, so the editability state is determined by examining these two bits (where x means don't care):

x00x = locked, invisible     = uneditable
x01x = locked, visible        = uneditable
x10x = unlocked, invisible = uneditable
x11x = unlocked, visible    = editable

To determine if a layer is "editable" as defined in the program code you must do this:

IF dividing by 2 returns an odd value, bit 1 = 1 = the layer is visible

AND

IF dividing by 4 returns an odd value, bit 2 = 1  = the layer is unlocked

THEN the layer is "editable" (visible and unlocked).

However, any time bit 2 = 1 (unlocked) you can edit the contents of the layer, even if bit 1 = 0 (the layer is not visible)!

For this reason, you can edit the contents of an "uneditable" layer. The term "editability" is a misnomer. However, you cannot edit the contents of a locked layer (bit 2 = 0) even if the layer is visible.

Does this answer your questions?

Phil
DesignCAD user since 1987

prl

I moved this post from the "UnlockALL" executable topic to here since we are jumping back and forth.


Quote from: Dr PR on January 14, 2013, 02:50:01 PM
You left out states 8 through 13, all on the currently active layer. I presume you want your code to work with objects on the currently active layer?

8 to 13 don't make physical sense so DesignCAD doesn't let you do them.

So if I take your binary table and do a one for one search and replace using not editable=locked, and editable=unlocked, what is the difference besides terminology?

0000 =       0      =  not current, not editable, invisible, empty
0001 =       1      =  not current, not editable, invisible, not empty
0010 =       2      =  not current, not editable, visible, empty
0011 =       3      =  not current, not editable, visible, not empty
0100 =       4      =  not current, editable, invisible, empty
0101 =       5      =  not current, editable, invisible, not empty
0110 =       6      =  not current, editable, visible, empty
0111 =       7      =  not current, editable, visible, not empty
1000 =       8      =  current, not editable, invisible, empty
1001 =       9      =  current, not editable, invisible, not empty
1010 =      10     =  current, not editable, visible, empty
1011 =      11     =  current, not editable, visible, not empty
1100 =      12     =  current, editable, invisible, empty
1101 =      13     =  current, editable, invisible, not empty

1110 =      14     =  current, editable, visible, empty
1111 =      15     =  current, editable, visible, not empty


prl

Quote from: Dr PR on January 14, 2013, 02:18:45 PM
is "editable" (visible and unlocked).


So this is the reason you're using extra terminology,  you're defining "editable" as the editable flag and the visible flag.   To me, the editable flag bit and term stand alone.

It can be called anything - editable/not editable,  unlocked/locked,  change bit ON/OFF,  read only OFF/ON,  lock icon open/lock icon closed.


paulerens

prl,
You as an expert, is DC  faster  by OLE control , as basicCAD ?
Thanks.
Paul.

prl

Paul,

Generally speaking, when it comes to cycling the drawing database and doing something useful during those loops, BasicCAD is several times (tens of times) faster than OLE.  OLE has to translate everything using OLE variants and is painfully slow.  Many times I do what GarryK does, write a GUI front end that builds and executes a basiccad program.


paulerens


Dr PR

prl,

I guess we will never see eye-to-eye on this one. I haven't "defined" anything. The program clearly has two variables, visible and unlocked (or whatever you want to call them). I have demonstrated that they can be changed independently.

The User Reference and on-line Help define "editable." It states:

Editable (lock icon): Determines whether or not the objects in the highlighted layer can be edited.

It is clear from the way the program works that "editable" is the logical AND of the visible and unlocked variables. This is how the lock icon works - when you press "Unlock All" in the layers dialog ALL layers (visible and invisible) are unlocked, however the lock icon does not change to show invisible layers are unlocked because it is an "editability" icon.

As I have demonstrated you can edit objects on invisible layers even though the lock icon shows them to be uneditable.

****

You are right that states 8 through 13 make no sense because the current layer must be "editable " (visible and unlocked). DesignCAD sets both the visible and unlocked variables when a layer becomed the current layer - in other words it makes it "editable." This is what the user sees while using the program with the keyboard and mouse.

****

One reason I have kept this discussion going is because you are talking about doiong things with macros. If you are just testing these variables you should never see states 8 through 13.

However, if you can set these variables with a macro, you had better know what you are doing and avoid creating states 8 through 13. You really need to know what all of these variables do, and what combinations are not valid. If there is no way to control these variables from a macro this is a moot point.

Also, since you can unlock invisible layers you probably can delete objects on these layers with a macro once they are unlocked. This would be another way to edit "uneditable" layers.

Phil
DesignCAD user since 1987

prl

#14
Quote from: Dr PR on January 17, 2013, 12:48:28 AM
I haven't "defined" anything. The program clearly has two variables, visible and unlocked (or whatever you want to call them). I have demonstrated that they can be changed independently.

Phil, you contribution is great. You're just a little overwhelming.  Nobody besides maybe you and I are interested in the 4 bit combinations.

When I first read your post from way back you said, "Locked editable" which to me reads as 0=1.   Only makes sense if you introduce extra definitions for  terms.  So if one separates out the layer editable bit term (whatever you want to call it) with the resulting states (0 to 15) and whatever you want to call them,  things can make sense with new terms.  But it does lend itself to having to manage more words when the layer function can handle it all easily with just three terms; visible, empty, editable.

So for terminology, we go back to the beginning.  "You can only edit what is visible".  You read this as a definition for the resulting state. I read it as a "rule" for what happens when you set the layer "editable" bit, aka "change bit", "read only bit, "lock bit".  To me it implied DesignCAD enforced a "rule" for managing the various layer combinations thereby blocking meaningless and/or harmful states .

My take was when a user clicks the lock icon on an invisible layer, the method assigned to that lock icon flips the layer editable bit to ON and also the layer visibility bit to ON.  This would block states 4 and 5  and this is actually the way it works right now.  So I assumed DesignCAD would not let you set states 4 and 5 because of the "rule".

But then you clearly demonstrated that DesignCAD violates its own rule with the "Unlock ALL" button in the layer dialog.  To be consistent with the "rule", if a layer was invisible and you hit that big "Unlock ALL" button, it should not only unlock the layer but also make it visible, just as if you did it individually in the layer toolbar for all layers (tedious).  Fortunately, the big "Unlock ALL' button method doesn't do that. It doesn't flip the visibility setting to ON.  And it doesn't properly update the padlock icon to open showing the invisible layers  as editable.  So it seems to be a "get out of jail" function for layer trapped items for those that know.  Was this intentional?  Could be or it could be an "IF" condition not properly closed off.

In the end it doesn't matter to me because layer state 5 is useful.   States 4, and 8 to 13 aren't.  But you never know, maybe someone else can find a use and loophole for them.


Edit: And from a programmer's view, a summary

States 4 and 5 can't be set by the programmer.  Only the "Unlock ALL" button in the Layer options dialog can set those states.  You can, however, read them.

States 8 to 13 - I've been trying to trick DesignCAD into producing these states.  So far these states appear blocked and will always default to 14 or 15.