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.

Push/Pop layer Macro?

Started by MarkX, December 21, 2012, 08:41:20 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MarkX

My work flow seems to be going like this. I have an object that I need to build on. In order to find my reference points, I switch to a guide layer and lay down my guides. Then I switch back to the starting layer. All this layer changing is tedious, and easy to forget.

Is there a macro that would let me say "Push 10" and change to layer 10? And then when I say "Pop" it would pop back to the last layer I was on? It wouldn't have to remember a stack of former layers -- just the last one ... because quite frankly I'm not likely to remember that far back.

Thanks!
Mark

prl

That's easy to do.  If nobody else does it for you in the next couple hours,  I'll write them up later this evening.




DrollTroll

yes it should be pretty simple to program, with the caveat that if YOU don't immediately use the Pop macro when you're done (say you manually switch to another layer), when you eventually do use Pop you'll most likely be back on a different layer than expected. In other words, the macros will only be able to keep track of what the macros knew about, not what you did in the interim.
Rough outline:
Push.d3m -- accepts one commandline argument (layer number). Writes the current layer to a text file (let's call it "push.txt"), and switches to the newly specified layer.
Pop.d3m -- no commandline argument required. Reads the last-written layer from push.txt, and restores to that layer.
With a bit of creating programming, this *could* be used to store a stack of layers, then pop back out of them in reverse order (if that might be useful). In such a case, pop.d3m might need an optional argument to "pop all" to return to the first layer in the stack. Nah, that's probably too complicated to be worth the effort of programming it. Can't think of a good use case....
25 years with DesignCAD

DrollTroll

First drafts. Someone can probably do better.
Push.d3m and Pop.d3m must be run from the command line so put them in your default macro folder (See the File Locations tab of Options).
Additionally, Push.d3m *must* be run from the command line so you can pass a layer number (ex. spacebar, "Push 10", enter). I started to add an input dialog box in case you forgot to include the layer number, but I got lazy on the logic required. Pop.d3m uses a text file for its input, so no command line input needed -- you can run it from the command line (spacebar, "pop", enter) or from Tools/Macro Execute.
25 years with DesignCAD

prl

#4
Quote from: DrollTroll on December 21, 2012, 09:28:57 AM
First drafts.

My fiddles are in blue.

pushv2.d3m -- writes the current layer to a text file, then switches to a specified layer.
' arguments: target layer number.
' outputs "poplayer.txt"
' Caveats: Must be run from the DesignCAD command line (ex. push 10) - not really
lay$ = Sys$(0)
If lay$ = "" Then input "Push command: enter layer number ", lay$

fmt$ = "%d"
Parse lay$, fmt$, laynum
If laynum < 0 or laynum > 2000 Then
  Message "Please enter a positive layer number less than 2000"
  End
End If
Open "o", 1, "*\poplayer.txt"
Print #1, Sys(3)
Close 1
Sys(3) = laynum

'Mark's favorite construction line colors follow
sys(300)=0
sys(301)=0
sys(302)=255


End

MarkX

#5
Thanks guys! You're great!

I was thinking about the color issue, but didn't want to push my luck ;-)

The problem with setting the color in the push macro is two-fold, part of which may be a bug.

The first problem is that the original color isn't restored when you pop. I know this would require saving extra info, so I'm not asking that anyone do that ;-)

The second problem -- the one that may be a bug -- is that the color swatch indicator doesn't change over on the right hand side. Lines now continue to be drawn in blue (PRL's color) despite showing "black" (my starter color) over in the swatch area.  So there's nothing overt to remind you that you just switched colors.

Many thanks!
Mark

Edit: I was thinking that I could just use a color-by-layer layer for my reference layer. But it turns out that when you use these macros to pop back from a by-layer layer, the line style and color stays the the same as that of the by-layer layer. In this case you can actually see from the line style drop-down that the style has been maintained, though you still can't see the color in the swatch. Once again, not sure if this is a bug, but it seems like one to me. Once you're back on your original not-by-layer layer, shouldn't your old default style and color return?

Edit 2: The Problem where the linestyle doesn't change back when you select a not-by-layer layer seems to be a bug in DC. Or am I not understanding correctly? If I'm on a style-by-layer layer and then switch back to a regular layer, shouldn't by former default style be active? Instead, the style used by the by-layer layer continues to be used.

prl

Latest fiddle.  Changes to Dt's code is in blue.  Mark, yes there is a bug in the color toolbox.  It should work like the line toolbox which updates itself when you make changes.  This will get you closer to what you want.  Full toggling between two setups.  The color-by-layer thing will probably work as a heads-up indicator.  I'll look into that.


' pushv3.d3m -- writes the current layer to a text file, then switches to a specified layer.
' arguments: target layer number.
' outputs "poplayer.txt"
' Caveats: Must be run from the DesignCAD command line (ex. push 10) - not really
lay$ = Sys$(0)
If lay$ = "" Then input "Push command: enter layer number ", lay$

fmt$ = "%d"
Parse lay$, fmt$, laynum
If laynum < 0 or laynum > 2000 Then
  Message "Please enter a positive layer number less than 2000"
  End
End If
Open "o", 1, "*\poplayer.txt"
precision 0
Print #1, Sys(3)
Print #1, sys(300) 'red index
Print #1, sys(301) 'green index
Print #1, sys(302) 'blue index
Print #1, sys(4) 'line type
Print #1, sys(5) 'line scale
Print #1, sys(6) 'line width

Close 1
Sys(3) = laynum

'Mark's favorite construction line settings
sys(4)=8
sys(300)=0
sys(301)=0
sys(302)=255


End




'popv3.d3m -- restores the previous layer as listed in poplayer.txt
On Error Goto NoFile
Open "i" 1, "*\poplayer.txt"
Input #1, oldlayer

If oldlayer < 0 or oldlayer > 2000 Then
  Message "invalid layer specified. Unable to pop previous layer"
  End
End If
sys(3) = oldlayer

'load saved settings, color, line type, style, width'
Input #1, sys300
Input #1, sys301
Input #1, sys302
Input #1, sys4
Input #1, sys5
Input #1, sys6

sys(300)=sys300
sys(301)=sys301
sys(302)=sys302
sys(4)=sys4
sys(5)=sys5
sys(6)=sys6


End

NoFile:
Message "Unable to locate poplayer.txt. Task aborted."
End


prl

Mark, version 4 attached with the color-by-layer trick.

' pushv4.d3m -- writes the current layer to a text file, then switches to a specified layer.
' arguments: target layer number.
' outputs "poplayer.txt"
' Caveats: Must be run from the DesignCAD command line (ex. push 10) - not really
lay$ = Sys$(0)
If lay$ = "" Then input "Push command: enter layer number ", lay$

fmt$ = "%d"
Parse lay$, fmt$, laynum
If laynum < 0 or laynum > 2000 Then
  Message "Please enter a positive layer number less than 2000"
  End
End If
Open "o", 1, "*\poplayer.txt"
precision 0
Print #1, Sys(3)
Print #1, sys(300)
Print #1, sys(301)
Print #1, sys(302)
Print #1, sys(4) 'line type
Print #1, sys(5) 'line scale
Print #1, sys(6) 'line width
Close 1
Sys(3) = laynum

'Mark's favorite construction line settings

sys(541) = 1 'color by layer ON
sys(4)=8
layname$="Const_Layer_"+lay$
sys$(93) = layname$
sys(531) = 0
sys(532) = 0
sys(533) = 255
sys(530) = 1
SetLayerProps laynum

'toggle the layer toolbar to get it to update
sys(219) = 0
sys(219) = 1

'turn off color toobar for emphasis
sys(226) = 0

End



'popv4.d3m -- restores the previous layer as listed in poplayer.txt
On Error Goto NoFile
Open "i" 1, "*\poplayer.txt"
Input #1, oldlayer

If oldlayer < 0 or oldlayer > 2000 Then
  Message "invalid layer specified. Unable to pop previous layer"
  End
End If
sys(3) = oldlayer

sys(541) = 0 'color by layer OFF

'load saved settings, color, line type, style, width'
Input #1, sys300
Input #1, sys301
Input #1, sys302
Input #1, sys4
Input #1, sys5
Input #1, sys6

sys(300)=sys300
sys(301)=sys301
sys(302)=sys302
sys(4)=sys4
sys(5)=sys5
sys(6)=sys6

sys(226) = 1 'turn ON color toolbar

End

NoFile:
Message "Unable to locate poplayer.txt. Task aborted."
End

MarkX

Hi PRL,

This is looking good! For my purposes, I commented out the code that sets the properties of the target layer. I want the drawing properties to be controlled by the layer. That way I can have one layer for quick guides, and another for profiles and not have to change the code for each line-type. Previously (version 3) when I popped back, it was still using the line types and color from the guide line layer, but you seem to have that fixed with the toolbar refresh. Turning off the color swatch toolbar was a good idea, to help remind me that I need to pop back before starting something new.

Thanks!
Mark