Author Topic: What's wrong with this macro?  (Read 816 times)

Gymbo

  • Jr. Member
  • **
  • Posts: 77
What's wrong with this macro?
« on: March 24, 2018, 04:32:06 PM »
Code: [Select]
if layer(10) = 0 then
layer(10) = 1
else
layer(10) = 0
endif
>regenerate
{
}

It turns off the layer but won't turn it back on again.
Regards,

Jim

Pearco

  • Hero Member
  • *****
  • Posts: 857
Re: What's wrong with this macro?
« Reply #1 on: March 24, 2018, 05:22:46 PM »
Gymbo;

Layer (10)=6  'Layer 10 is on

Layer (10)=0   'Layer 10 is off

I use this system in a toolbox to control items on layers I want on and off during the design of a cabinet or what ever I work on.
I use one macro to turn off and another to turn on in the same tool box.

Try this way in your macro.

 
Jim
User since ProDesign 1.5

JJG

  • Hero Member
  • *****
  • Posts: 735
Re: What's wrong with this macro?
« Reply #2 on: March 25, 2018, 01:40:50 AM »
Hy Gymbo,

if you want to do a toggle function (= what you are trying to do ...) this is below how you have to write the code :

Code: [Select]
a=layer(10) 'store layer 10 statment

IF not a=6 THEN
LAYER(10)=6 'set layer 10 on ; you can use 14 instead of 6 if you want as current layer (the current layer is always visible and editable)
else
LAYER(10)=0 'sélectionner objet créé
end if

REGEN

End.

 ;)

bdeck

  • Hero Member
  • *****
  • Posts: 896
Re: What's wrong with this macro?
« Reply #3 on: March 25, 2018, 02:57:15 AM »
This demo might show the problem.
Seems to be a bug  in DC keeping the 0 bit set in layer(10).   EDIT: see reply 6.
Dunno why the 0 bit is set in layer(10) but not in layer(0).
Also, sys(3) must be set to some  layer other than 10, or the layer(10) statement fails.
Maybe someone else knows why.

Code: [Select]
'FL10.d3m flip layer 10
L=layer(10)
if L <2 then
Layer(10) = 6
else
Layer(10) = 0
endif
LL=layer(10)
L0=layer(0)
L1=layer(1)
>regenerate
{
}
print "L0, L1, L, LL  =  ",L0, L1, L, LL,"      hit a key"
anykey
« Last Edit: March 26, 2018, 09:35:34 AM by bdeck »

Gymbo

  • Jr. Member
  • **
  • Posts: 77
Re: What's wrong with this macro?
« Reply #4 on: March 25, 2018, 08:31:55 AM »
Thanks everyone for your prompt replies. I'm not sure why my  toggle didn't work, even when I replace 1 with 6, I used that method to toggle sys(26) and it works fine. Also where does one find the on/off definitions for layer(?).

bdeck's code did the job, but JJG's didn't ???
Regards,

Jim

Pearco

  • Hero Member
  • *****
  • Posts: 857
Re: What's wrong with this macro?
« Reply #5 on: March 25, 2018, 02:17:44 PM »
Gymbo;

I found them in the Layer statement as part of the developers manual.
Jim
User since ProDesign 1.5

bdeck

  • Hero Member
  • *****
  • Posts: 896
Re: What's wrong with this macro?
« Reply #6 on: March 25, 2018, 08:56:33 PM »
Dunno why the 0 bit is set in layer(10) but not in layer(0).

It appears that the "1" is a flag indicating that the layer is not empty.
Since basiccad has no bitwise operators, a simple way to test for it is with the MOD function.

Flag = layer(10) MOD 2         ' = 0 or 1
L = layer(10) - Flag                  ' =  0, 2, 6, or 14
« Last Edit: March 25, 2018, 10:38:52 PM by bdeck »

Gymbo

  • Jr. Member
  • **
  • Posts: 77
Re: What's wrong with this macro?
« Reply #7 on: March 26, 2018, 09:27:29 AM »

I found them in the Layer statement as part of the developers manual.
I downloaded DrollTroll's DesignCAD Developers Kit and his Windows 7 help file, could find no reference to this.
Regards,

Jim

bdeck

  • Hero Member
  • *****
  • Posts: 896
Re: What's wrong with this macro?
« Reply #8 on: March 26, 2018, 09:28:36 AM »
Also where does one find the on/off definitions for layer

Aside from the discussion in the Layer() Statement, there is a brief discussion in the "System Functions" section  (which I had never seen) of the sdk (Macros17.hlp).

The Layer function retrieves a (presumably) 4 bit value (converted to floating point) made up as follows:

Layer() = populated + visible * 2 + editable * 4 + current * 8

where:
      populated, visible, editable, and current  are all logical values of 0 or 1 occupying the 0, 1, 2, or 3 bit of the stored value.
      populated is a Read Only bit
      if editable =1 then visible must be =1   (The statement "Layer(x)=4" generates an error)

Either of the following can be used to find the value of the first bit:
      populated= odd(layer(x)),   or
      populated= layer(x) mod 2


« Last Edit: March 26, 2018, 09:47:39 AM by bdeck »

Dr PR

  • Hero Member
  • *****
  • Posts: 5611
Re: What's wrong with this macro?
« Reply #9 on: March 26, 2018, 10:36:44 AM »
bd,

Out of curiosity, it is possible to make invisible layers editable (at least for objects to be selected) by opening the Layers Dialog and clicking "Unlock All." This allows you to select all of a multi-layer group or solid if part is on a non-visible layer. The entire selected group/solid can then be edited (at least moved, exploded or deleted).

However, since objects on an invisible layer cannot be selected by clicking, gravity snap or Select All, invisible objects cannot be edited even if the layer is unlocked (editable).

Can you do these things with the Layer() statement in macros?

Phil
DesignCAD user since 1987

bdeck

  • Hero Member
  • *****
  • Posts: 896
Re: What's wrong with this macro?
« Reply #10 on: March 26, 2018, 12:47:33 PM »
Can you do these things with the Layer() statement in macros?

Hi Phil,

Here's a macro that sets the properties of layer 1 in the line marked ***********

Then it uses the "Change" command to change the color of each entity sequentially to red.

So at least this type of editing seems to work when the layer is set to 0 (not visible, not editable) or 2 (visible, not editable).

Dunno about other types of editing. I never use layers. Also dunno how color by layer affects this macro.

bd

Code: [Select]
' change color of entities on hidden layer
Alias ENT_COLOR  &H0104 
L= layer(1)
L=L - (L mod 2)
sys3=sys(3)
if sys3=1 then sys(3)=0
ne=sys(9)
for i=1 to ne
LAYER(1)=0          ' choose a value 0,2,4,6,14    *****************************
entity i
Query Ent_Color, redval, greenval, blueval ' find out the entity's color
Change Ent_Color, 240,0,0
Update
LAYER(1)=2          ' make layer visible
regen
print "hit a key, esc to exit"
anykey k
entity i
Change Ent_Color, redval, greenval, blueval ' find out the entity's color
Update
regen
if k = 27 then goto bail
next

bail:         'restore original layer properties
sys(3)=sys3
LAYER(1)=L
end

bdeck

  • Hero Member
  • *****
  • Posts: 896
Re: What's wrong with this macro?
« Reply #11 on: March 26, 2018, 04:01:58 PM »
Here's one that hides layer 1, then selects, moves, and deselects a sequence of entities on a hidden layer 1, then unhides it.
As much as I despise handles in 2d work, had to use them within the macro because of a longstanding bug in the move command.

Code: [Select]
Alias ENT_SELECTED  &H010C 

L= layer(1)
L=L - (L mod 2)

sys3=sys(3)
if sys3=1 then sys(3)=0
s3=sys(3)
ne=sys(9)

>deselect
{
}
for i=1 to ne
LAYER(1)=0        ' choose a value 0,2,4,6,14    *****************************
entity i
Change Ent_Selected, 1
Update

>SetHandle
{
  <Pointxyz 0, 0, 0
}
>Move
{
<Type 1
<Reference 0
<Pointxyz  2, 2, 0
}

LAYER(1)= 2     ' make layer visible
regen
print sys3, s3, L, "hit a key,    esc to exit"
anykey k

>SetHandle
{
  <Pointxyz 2,2,0
}
>Move
{
<Type 1
<Reference 0
<Pointxyz 0, 0, 0
}
>deselect
{
}
regen
if k = 27 then goto bail
next

bail:         'restore original layer properties
sys(3)=sys3
LAYER(1)=L
end



 

Lar

  • Hero Member
  • *****
  • Posts: 2815
Re: What's wrong with this macro?
« Reply #12 on: March 26, 2018, 06:00:07 PM »


No one has yet put up all of the layer functions together so here they are...


Code: [Select]

'LAYER FUNCTIONS


'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\=1         -> x is the current layer.     [y=14, or 15]
'
'0 – Invisible and not editable
'2 – Visible but not editable
'6 – Visible and editable
'14 – Set as current layer


What I do is if I want to make the layer do something I use the four numbers at the end (0, 2, 6, and 14) - {eg, layer(1)=14 makes layer 1 the current layer} but if I am checking the status of a layer the result can be any of the numbers so it's best to use the if ODD functions.

Of course, don't copy the apostrophes in the active code. The apostrophes are there because I normally paste all that info at the end all my layer macros so I can find it all easily (well, I use to anyway, not sure if I've been doing it lately).


Lar
« Last Edit: March 26, 2018, 06:19:20 PM by Lar »

Gymbo

  • Jr. Member
  • **
  • Posts: 77
Re: What's wrong with this macro?
« Reply #13 on: March 28, 2018, 12:22:40 PM »
I found a pdf on the web that describes the statements and functions used in BasicCAD:
http://www.wwslalom.net/dc/macrohelp.pdf
Regards,

Jim

Bob P

  • Hero Member
  • *****
  • Posts: 1208
    • Era Replica Automobiles
Re: What's wrong with this macro?
« Reply #14 on: March 28, 2018, 01:59:57 PM »
That help file dates back to 2008. There are many updates after that. (Mostly sys function additions.) The Basicad section has several updates.