Staircase macro deluxe

Hello-
I decided to take the staircase macro that is mentioned in the tome of mapping and modify it a little. To wit, I wanted to have the reference line deleted when the macro was done. At first I thought this should be easy, just erase the entity. But the problem seems to be that whatever point I choose to select the reference entity is also a point that one of the "step" lines goes through, so both the reference line and the step line get erased. Digging into the macro a little, I thought if I choose a point on the reference line that is not near the points selected for drawing the steps, that should allow me to do a get entity using the new point and nothing should be deleted. Well this works fine for horizontal and vertical reference lines, but anything at an angle, the reference line is deleted, but the first one or two step lines are also deleted. And I can't for the life of me figure out why. I have experimented with values of 0.1 to 1.5 and 0.5 gets the best results.

MACRO STAIRCASE
ECOFF
SELSAVE
LWIDTH 0;LSTYLE solid;FSTYLE solid
GV varStepWidth 10
GV varStepWidth ^DEnter the stairway width [10]:
GV varStepDepth 1
GV varStepDepth ^DEnter the step spacing [1]:
GE varEntity ^DSelect object to draw the staircase along:
IFERR MacroDone
GLEN varEntityLen varEntity
GN varStepNum varEntityLen/varStepDepth
GV varUnit 100/varStepNum
GV varCurStep 0
GP varEntPoint % (varUnit*.5) varEntity <--Here I get a point on the reference entity that shouldn't be a "step" line as well
GP varP1 % 0 varEntity
GBRNG varB1 varP1 % .01 varEntity
LINE ref varP1 <varB1+90,(varStepWidth/2) ref varP1 <varB1-90,(varStepWidth/2);
:Loop
GV varCurStep varCurStep+1
GP varP1 % (varCurStep*varUnit) varEntity
GBRNG varB1 varP1 % (varCurStep*varUnit)-.01 varEntity
LINE ref varP1 <varB1-90,(varStepWidth/2) ref varP1 <varB1+90,(varStepWidth/2);
IFP varStepNum-varCurStep Loop
SELBYP
OFFSETCPY (varStepWidth/2) varEntity ref varP1 <varB1+90,1
OFFSETCPY (varStepWidth/2) varEntity ref varP1 <varB1-90,1
SELBY1
GE varEntDel varEntPoint <-- Here I "reselect" the reference entity but at a new point on the line
SELBY1
ERASE varEntDel <-- Here I erase the entity
REDRAW
:MacroDone
SELREST
ECON
ENDM

As I said, this works fine for horizontal and vertical reference lines, but any line other than those...

Pete the Perplexed

Comments

  • edited May 2013
    Yes, the Erase command is not too precise on what it selects (as is any selection in fact).
    To circumvent what you experience, I used the following steps:

    1. Move the entity to erase to a specific Layer created just for that immediately after selection (and prior to any addition)
    2. Once the drawing is over, make the new layer active
    3. Hide all other layers
    4. Erase All
    5. Show all the layers again

    The drawback is that if you had any hidden layer before using the macro, it will show at the end. I'll gladly welcome any better solution...
    You will find a more detailed version here in the Tutorial #1 pages 15+.
  • edited May 2013
    I tried the layer trick, but that doesn't work either. It seems that the OffSetCpy command duplicates everything from the source line including the layer it's on. So when you go to the layer to be erased, the reference line and the two offset copies of it are all deleted. I'm beginning to think that for this macro, the desired deletion cannot be done. At least done cleanly.
  • You need to change the layer after moving the target entity to the TOERASE layer, otherwise anything will go there too...
  • edited May 2013
    Here's the macro in its current incarnation:


    MACRO STAIRCASE
    ECOFF
    RDOFF
    SELSAVE
    POINT 10001,10001;
    LWIDTH 0;LSTYLE solid;FSTYLE solid
    GV varStepWidth 10
    GV varStepWidth ^DEnter the stairway width [10]:
    GV varStepDepth 1
    GV varStepDepth ^DEnter the step spacing [1]:
    GE varEntity ^DSelect the reference entity to draw the staircase along:
    IFERR MacroDone
    SELBY1
    GOLAYER ToErase
    CHANGEL varEntity ToErase
    SELBY1
    GOLAYER MacroConstruct
    GLEN varEntityLen varEntity
    GN varStepNum varEntityLen/varStepDepth
    GV varUnit 100/varStepNum
    GV varCurStep 0
    GP varP1 % 0 varEntity
    GBRNG varB1 varP1 % .01 varEntity
    LINE ref varP1 <varB1+90,(varStepWidth/2) ref varP1 <varB1-90,(varStepWidth/2);
    :Loop
    GV varCurStep varCurStep+1
    GP varP1 % (varCurStep*varUnit) varEntity
    GBRNG varB1 varP1 % (varCurStep*varUnit)-.01 varEntity
    LINE ref varP1 <varB1-90,(varStepWidth/2) ref varP1 <varB1+90,(varStepWidth/2);
    IFP varStepNum-varCurStep Loop
    SELBYP
    OFFSETCPY (varStepWidth/2) varEntity ref varP1 <varB1+90,1
    OFFSETCPY (varStepWidth/2) varEntity ref varP1 <varB1-90,1
    ASKBOX CC3
    Erase the reference entity?

    IFERR MacroDone
    LAYER ToErase
    HIDEA
    SELBYA
    ERASE
    SHOWA
    REDRAW
    :MacroDone
    selby1
    keep 10001,10001
    selbyl
    changel MacroConstruct
    like
    10001,10001
    selbyp
    group
    selby1
    erase 10001,10001
    SELREST
    ECON
    RDON
    ENDM

    I change the layer to MacroConstruct after moving the entity to ToErase. The offset copy command seems to not only create an offset line, but it also copies all the parameters of the reference entity, including the layer value.

    Pete
  • edited May 2013
    Posted By: FatPeteThe offset copy command seems to not only create an offset line, but it also copies all the parameters of the reference entity, including the layer value.
    Indeed it does, so you need to change the layer after the offset.
    Just wonder, which version of CC are you using because ERASE has been replaced by ERA...
  • edited May 2013
    MACRO STAIRCASE
    ECOFF
    RDOFF
    SELSAVE
    POINT 10001,10001;
    GE RefPoint 10001,10001
    LWIDTH 0;LSTYLE solid;FSTYLE solid
    GV varStepWidth 10
    GV varStepWidth ^DEnter the stairway width [10]:
    GV varStepDepth 1
    GV varStepDepth ^DEnter the step spacing [1]:
    GE varEntity ^DSelect the reference entity to draw the staircase along:
    IFERR MacroDone
    SELBY1
    GOLAYER ToErase
    CHANGEL varEntity ToErase
    SELBY1
    GOLAYER MacroConstruct
    GLEN varEntityLen varEntity
    GN varStepNum varEntityLen/varStepDepth
    GV varUnit 100/varStepNum
    GV varCurStep 0
    GP varP1 % 0 varEntity
    GBRNG varB1 varP1 % .01 varEntity
    LINE ref varP1 <varB1+90,(varStepWidth/2) ref varP1 <varB1-90,(varStepWidth/2);
    :Loop
    GV varCurStep varCurStep+1
    GP varP1 % (varCurStep*varUnit) varEntity
    GBRNG varB1 varP1 % (varCurStep*varUnit)-.01 varEntity
    LINE ref varP1 <varB1-90,(varStepWidth/2) ref varP1 <varB1+90,(varStepWidth/2);
    IFP varStepNum-varCurStep Loop
    SELBYP
    OFFSETCPY (varStepWidth/2) varEntity ref varP1 <varB1+90,1
    CHANGEL MacroConstruct
    OFFSETCPY (varStepWidth/2) varEntity ref varP1 <varB1-90,1
    CHANGEL MacroConstruct
    ASKBOX CC3
    Erase the reference entity?

    IFERR MacroDone
    LAYER ToErase
    HIDEA
    SELBYA
    ERA
    SHOWA
    REDRAW
    :MacroNoErase
    LAYER MacroConstruct
    :MacroDone
    SELBY1
    ERA RefPoint
    SELREST
    ECON
    RDON
    ENDM



    I didn't found the way to change the layer to the one stored in the RefPoint, though...
    But in your version, the point at 10001,10001 was included in the group.

    Looks like it works, except on the changing layer feature...
  • edited May 2013
    Posted By: Joachim de Ravenbel
    Posted By: FatPeteThe offset copy command seems to not only create an offset line, but it also copies all the parameters of the reference entity, including the layer value.
    Indeed it does, so you need to change the layer after the offset.
    Just wonder, which version of CC are you using because ERASE has been replaced by ERA...
    I'm using CC3...there's a macro called ERASE. I recreate that in my "test" file.

    And thank you for the help. I should have thought of the change layer command...

    Thank you very much.

    Pete
    Added later:
    Now I have a problem that the second staircase drawn will not only erase the reference line in the second staircase, but the first staircase in toto as well. I've tried using different layers for the staircases, saving and exiting CC3, nothing seems to prevent this from happening. It should be noted that it's just the staircase(s) that are deleted...anything else in the sheet/layer is not touched.
  • edited May 2013
    OK. Comparing what I have for the macro with Joachim's, it's the code to change the layer of the entities on the layer MacroConstruct to the layer that was current when the macro started (or it appears to be, it's the only difference between the two macros). This is all done with the point placed at the beginning of the macro. My question is why should the keep command followed by a changeL using the like reference cause the grouped entities to be erased on a subsequent run of the macro? The only thing being erased (supposedly) is the entity on the ToErase layer and the (now) grouped entities are on the same layer with the previously grouped entities ( providing you haven't changed layers in the meantime, and even then they are still erased).

    When I use the Info->List command on the grouped entity, all the lines in the group are on the starting layer. Running the macro a second time and NOT erasing the reference seems to have no effect on the layers of either grouped entity. Running the macro a third time and selecting TO erase the reference line, erases not only the reference line, but the previous two grouped entities. I am thoroughly confused...but then I'm new to this.

    ASKBOX CC3
    Erase the reference entity?

    IFERR MacroDone
    LAYER ToErase
    HIDEA
    SELBYA
    ERASE
    SHOWA
    REDRAW
    :MacroDone
    selby1
    layer MacroConstruct
    selby1
    keep 10001,10001
    selbyl
    changel MacroConstruct
    like
    10001,10001
    selbyp
    group
    selby1
    erase 10001,10001

    Admittedly, Joachim's version does what I started out to do...but...I like the fact that the staircase is grouped into one entity and said entity's layer is changed to the starting value found in the point. So, why does this behavior happen? I'm sure it's something obvious.
  • The only insight I can give is that groups behave oddly with layers... It's a fact that a group on a hidden layer sometimes get selected nonetheless... And it looks like it's what's happening here.
    I fully understand the wish to keep the entities grouped but I don't see any solution for the moment.

    I'd recommend adding SAVESETTINGS after SELSAVE and GETSETTINGS before ENDM. This saves things like current layer, color, fill style etc. and restores them to the initial state.
  • 2 months later
  • I got the macro working, after a nudge from Simon in the right direction. It turns out that the SELBYA command was giving the macro fits. Changed to SELBYL to erase the pertinent layer works fine. AND I got the grouping working (stole some code from the cliffface macro in the TUM). Here's the code, if you're interested:


    ASKBOX CC3
    Erase the reference entity?

    IFERR MacroDone
    LAYER ToErase
    SELBYL
    ERASE
    ToErase
    REDRAW
    :MacroDone
    SELBYL
    CHANGEL MacroConstruct
    LIKE
    10001,10001
    SELBYP
    GROUP
    SELBY1
    ERASE 10001,10001
    GETSETTINGS
    SELREST

    Like I said, this is thanks to Simon for pointing me in the right direction.

    FatPete
  • edited August 2013
    I was asked to put the whole macro up for others to use, if they so desire, so here it is. Enjoy. It seems I am not allowed to post attachments, so the code is listed below:

    MACRO STAIRCASE
    ECOFF
    RDOFF
    SELSAVE
    SAVESETTINGS
    POINT 10001,10001;
    LWIDTH 0;LSTYLE solid;FSTYLE solid
    GV varStepWidth 10
    GV varStepWidth ^DEnter the stairway width [10]:
    GV varStepDepth 1
    GV varStepDepth ^DEnter the step spacing [1]:
    GE varEntity ^DSelect the reference entity to draw the staircase along:
    IFERR MacroDone
    SELBY1
    GOLAYER ToErase
    CHANGEL varEntity ToErase
    SELBY1
    GOLAYER MacroConstruct
    GLEN varEntityLen varEntity
    GN varStepNum varEntityLen/varStepDepth
    GV varUnit 100/varStepNum
    GV varCurStep 0
    GP varP1 % 0 varEntity
    GBRNG varB1 varP1 % .01 varEntity
    LINE ref varP1 <varB1+90,(varStepWidth/2) ref varP1 <varB1-90,(varStepWidth/2);
    :Loop
    GV varCurStep varCurStep+1
    GP varP1 % (varCurStep*varUnit) varEntity
    GBRNG varB1 varP1 % (varCurStep*varUnit)-.01 varEntity
    LINE ref varP1 <varB1-90,(varStepWidth/2) ref varP1 <varB1+90,(varStepWidth/2);
    IFP varStepNum-varCurStep Loop
    SELBYP
    OFFSETCPY (varStepWidth/2) varEntity ref varP1 <varB1+90,1
    CHANGEL MacroConstruct
    OFFSETCPY (varStepWidth/2) varEntity ref varP1 <varB1-90,1
    CHANGEL MacroConstruct
    ASKBOX CC3
    Erase the reference entity?

    IFERR MacroDone
    LAYER ToErase
    SELBYL
    ERA
    ToErase
    REDRAW
    :MacroDone
    SELBYL
    CHANGEL MacroConstruct
    LIKE
    10001,10001
    SELBYP
    GROUP
    SELBY1
    ERA 10001,10001
    GETSETTINGS
    SELREST
    RDON
    ECON
    ENDM
Sign In or Register to comment.