Jump to content
Macro Express Forums

Modding HTML file - trying to dele <section> to </section>


Recommended Posts

ME5

my level: beginner

 

Objective: select and delete a single entire HTML section, running from <section> to </section>

Complication: the number of HTML lines between these two key words varies from file to file, so I can't just SHIFT + down-arrow a fixed number of times to select the code prior to DELETE.

 

Is there a SELECT or  SELECT UNTIL command (I don't see one)... in this case, I'd select until reaching the ">" in "</section>"

It's always a relatively short number of keytrokes that make up the section content... I'm not seeing an IF command that looks for specific characters -- but I see IF CLIPBOARD -- should I just pump </section> into the clipboard?

 

Absent a SELECT command, how do I select a variably-long section of character content?

Link to comment
Share on other sites

Typical example:

Quote

<section class="tsd-index-section ">
                        <h3>
                            Rules
                        </h3>
                        <ul class="tsd-index-list">
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#__mod3" class="tsd-kind-icon">__mod3</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#color" class="tsd-kind-icon">color</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#length" class="tsd-kind-icon">length</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#modelnode" class="tsd-kind-icon">model<wbr>Node</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#papersize" class="tsd-kind-icon">paper<wbr>Size</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#paperunits" class="tsd-kind-icon">paper<wbr>Units</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#rendernode" class="tsd-kind-icon">render<wbr>Node</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#scenename" class="tsd-kind-icon">scene<wbr>Name</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#sheetname" class="tsd-kind-icon">sheet<wbr>Name</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#showborder" class="tsd-kind-icon">show<wbr>Border</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#size" class="tsd-kind-icon">size</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#viewscale" class="tsd-kind-icon">view<wbr>Scale</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#width" class="tsd-kind-icon">width</a></li>
                        </ul>
                    </section>

 

Link to comment
Share on other sites

Sure, the whole file, because I don't know what you're looking for - unfortunately it's on the long side. I've underlined the section to delete:

Quote

<!doctype html>
<html class="minimal no-js">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>DrawingSheet | Base Library docs</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="../assets/css/main.css">
</head>
<body>
<header>
    <div class="tsd-page-toolbar">
        <div class="container">
            <div class="table-wrap">
                <div class="table-cell">
                    <strong><a href="../designs-index.html" style="text-decoration: underline;">....</a></strong>
                    &nbsp;
                    <strong><a href="../js-index.html" style="text-decoration: underline;">....</a></strong>
                </div>
                <div class="table-cell">Copyright &copy; 2020</div>
                <div class="table-cell" style="font-size: smaller;">&nbsp;&nbsp;(v.0.0)</div>
            </div>
        </div>
    </div>
    </header><div class="container container-main">
    <div class="content-wrap">
        <section class="tsd-panel tsd-comment">
            <div class="tsd-comment tsd-typography">
                <div class="lead">
                    <a href="#drawingsheet" id="drawingsheet" style="color: inherit; text-decoration: none;">
                        <h1>DrawingSheet</h1>
                    </a>
                    <p><strong>Mixins</strong>: <a href="rectanglemixin.html">RectangleMixin</a>, <a href="rectanglerendermixin.html">RectangleRenderMixin</a>, <a href="baseassembly.html">BaseAssembly</a></p>
                </div>
                <p>A single sheet of virtual paper, representing an engineering drawing that can contain scaled views of scenes from modele space.  A drawing sheet uses it own &#39;paper units&#39; so that it maps to an actual paper size in PDF and other outputs.</p>
                <p>A drawing sheet is always its own <a href="scene.html">Scene</a>, with the scene name the same as the <code>sheetName</code>.  Any geometry (not just 2d graphics) can be placed into a drawing sheet, but it will always be viewed as if in a Top view, with +X to the right, and +Y to the top.</p>
                <p>DrawingSheets are the only object that can have <a href="viewport.html">Viewport</a> children.  DrawingSheets cannot have DrawingSheet children, and cannot appear in another scene.</p>
            </div>
        </section>
        <section class="tsd-panel-group tsd-index-group">
            <h2>Index</h2>
            <section class="tsd-panel tsd-index-panel">
                <div class="tsd-index-content">
                    <section class="tsd-index-section ">
                        <h3>
                            Rules
                        </h3>
                        <ul class="tsd-index-list">
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#__mod3" class="tsd-kind-icon">__mod3</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#color" class="tsd-kind-icon">color</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#length" class="tsd-kind-icon">length</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#modelnode" class="tsd-kind-icon">model<wbr>Node</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#papersize" class="tsd-kind-icon">paper<wbr>Size</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#paperunits" class="tsd-kind-icon">paper<wbr>Units</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#rendernode" class="tsd-kind-icon">render<wbr>Node</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#scenename" class="tsd-kind-icon">scene<wbr>Name</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#sheetname" class="tsd-kind-icon">sheet<wbr>Name</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#showborder" class="tsd-kind-icon">show<wbr>Border</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#size" class="tsd-kind-icon">size</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#viewscale" class="tsd-kind-icon">view<wbr>Scale</a></li>
                            <li class="tsd-kind-property tsd-parent-kind-class"><a href="drawingsheet.html#width" class="tsd-kind-icon">width</a></li>
                        </ul>
                    </section>

                </div>
            </section>
        </section>
        <section class="tsd-panel-group tsd-member-group ">
            <h2>Rules</h2>
            <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
                <a name="__mod3" class="tsd-anchor"></a>
                <h3>__mod3</h3>
                <div class="tsd-signature tsd-kind-icon">__mod3<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
                <div class="tsd-comment tsd-typography">
                    <div class="lead">
                        <p>Internal Use Only.</p>
                    </div>
                    <p><em>Flags</em> : cached, external</p>
                    <p><em>Expression</em> : <code>R.THREE.makeDrawingSheet(this.renderName,this.length,this.width,this.paperUnits)</code></p>
                </div>
                <!--
-->
            </section>
            <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
                <a name="color" class="tsd-anchor"></a>
                <h3>color</h3>
                <div class="tsd-signature tsd-kind-icon">color<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
                <div class="tsd-comment tsd-typography">
                    <div class="lead">
                        <p>Override of the standard rule to make all content black instead of gray.</p>
                    </div>
                    <p><em>Flags</em> : cached</p>
                    <p><em>Expression</em> : <code>&quot;black&quot;</code></p>
                </div>
                <!--
-->
            </section>
            <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
                <a name="length" class="tsd-anchor"></a>
                <h3>length</h3>
                <div class="tsd-signature tsd-kind-icon">length<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
                <div class="tsd-comment tsd-typography">
                    <div class="lead">
                        <p>This can be set to create a custom paper size, but is normally automatically obtained from the <a href="drawingsheet.html#size">size</a> parameter.</p>
                    </div>
                    <p><em>Flags</em> : cached, parameter</p>
                    <p><em>Default expression</em> : <code>this.papersize[this.size].xSize</code></p>
                </div>
                <!--
-->
            </section>
            <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
                <a name="modelnode" class="tsd-anchor"></a>
                <h3>model<wbr>Node</h3>
                <div class="tsd-signature tsd-kind-icon">model<wbr>Node<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span></div>
                <div class="tsd-comment tsd-typography">
                    <div class="lead">
                        <p><em>Behavior to change in upcoming release</em></p>
                    </div>
                    <p><em>Flags</em> : cached</p>
                    <p><em>Expression</em> : <code>this.showBorder</code></p>
                </div>
                <!--
-->
            </section>
            <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
                <a name="papersize" class="tsd-anchor"></a>
                <h3>paper<wbr>Size</h3>
                <div class="tsd-signature tsd-kind-icon">paper<wbr>Size<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">any</span></div>
                <div class="tsd-comment tsd-typography">
                    <div class="lead">
                        <p>Sheet space units: ISO sizes assume mm, ANSI assume inch</p>
                    </div>
                    <p><em>Flags</em> : cached</p>
                    <p><em>Expression</em> : <code>{&#39;ANSI A Landscape&#39;: { xSize: 11, ySize: 8.5 }, &#39;ANSI A Portrait&#39;: { xSize: 8.5, ySize: 11 }, &#39;ANSI B&#39;: { xSize: 17, ySize: 11 }, &#39;ANSI C&#39;: { xSize: 22, ySize: 17 }, &#39;ANSI D&#39;: { xSize: 34, ySize: 22 }, &#39;ANSI E&#39;: { xSize: 44, ySize: 34 }, A4: { xSize: 210, ySize: 297 }, A3: { xSize: 297, ySize: 420 }, A2: { xSize: 420, ySize: 594 }, A1: { xSize: 594, ySize: 841 }, A0: { xSize: 841, ySize: 1189 } }</code></p>
                </div>
                <!--
-->
            </section>
            <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
                <a name="paperunits" class="tsd-anchor"></a>
                <h3>paper<wbr>Units</h3>
                <div class="tsd-signature tsd-kind-icon">paper<wbr>Units<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
                <div class="tsd-comment tsd-typography">
                    <div class="lead">
                        <p>This can be set to &#39;in&#39; or &#39;mm&#39;, but is normally automatically obtained from the <a href="drawingsheet.html#size">size</a> parameter.</p>
                    </div>
                    <p><em>Flags</em> : cached, parameter</p>
                    <p><em>Default expression</em> : <code>this.size.startsWith(&quot;ANSI&quot;) ? &quot;in&quot; : &quot;mm&quot;</code></p>
                </div>
                <!--
-->
            </section>
            <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
                <a name="rendernode" class="tsd-anchor"></a>
                <h3>render<wbr>Node</h3>
                <div class="tsd-signature tsd-kind-icon">render<wbr>Node<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span></div>
                <div class="tsd-comment tsd-typography">
                    <div class="lead">
                        <p><em>Behavior to change in upcoming release</em></p>
                    </div>
                    <p><em>Flags</em> : cached</p>
                    <p><em>Expression</em> : <code>this.showBorder</code></p>
                </div>
                <!--
-->
            </section>
            <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
                <a name="scenename" class="tsd-anchor"></a>
                <h3>scene<wbr>Name</h3>
                <div class="tsd-signature tsd-kind-icon">scene<wbr>Name<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
                <div class="tsd-comment tsd-typography">
                    <div class="lead">
                        <p>Override of the standard rule so that it is always the <a href="drawingsheet.html#sheetname">sheetName</a>.</p>
                    </div>
                    <p><em>Flags</em> : cached</p>
                    <p><em>Expression</em> : <code>this.sheetName</code></p>
                </div>
                <!--
-->
            </section>
            <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
                <a name="sheetname" class="tsd-anchor"></a>
                <h3>sheet<wbr>Name</h3>
                <div class="tsd-signature tsd-kind-icon">sheet<wbr>Name<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
                <div class="tsd-comment tsd-typography">
                    <div class="lead">
                        <p>The name of the sheet, and thus the scene.</p>
                    </div>
                    <p><em>Flags</em> : cached, parameter</p>
                    <p><em>Default expression</em> : <code>&quot;Sheet1&quot;</code></p>
                </div>
                <!--
-->
            </section>
            <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
                <a name="showborder" class="tsd-anchor"></a>
                <h3>show<wbr>Border</h3>
                <div class="tsd-signature tsd-kind-icon">show<wbr>Border<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span></div>
                <div class="tsd-comment tsd-typography">
                    <div class="lead">
                        <p>Whether to show a rectangular border representing the paper boundary.</p>
                    </div>
                    <p><em>Flags</em> : cached, parameter</p>
                    <p><em>Default expression</em> : <code>true</code></p>
                </div>
                <!--
-->
            </section>
            <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
                <a name="size" class="tsd-anchor"></a>
                <h3>size</h3>
                <div class="tsd-signature tsd-kind-icon">size<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
                <div class="tsd-comment tsd-typography">
                    <div class="lead">
                        <p>The standard nominal paper size of this sheet. Must be one of the elements in the <a href="drawingsheet.html#papersize">paperSize</a> list.</p>
                    </div>
                    <p><em>Flags</em> : cached, parameter</p>
                    <p><em>Default expression</em> : <code>&quot;ANSI B&quot;</code></p>
                </div>
                <!--
-->
            </section>
            <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
                <a name="viewscale" class="tsd-anchor"></a>
                <h3>view<wbr>Scale</h3>
                <div class="tsd-signature tsd-kind-icon">view<wbr>Scale<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
                <div class="tsd-comment tsd-typography">
                    <div class="lead">
                        <p>The default scale for viewports on this sheet. This is the size on the sheet relative to model space.</p>
                    </div>
                    <p><em>Flags</em> : cached, parameter</p>
                    <p><em>Default expression</em> : <code>1.0</code></p>
                </div>
                <!--
-->
            </section>
            <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
                <a name="width" class="tsd-anchor"></a>
                <h3>width</h3>
                <div class="tsd-signature tsd-kind-icon">width<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
                <div class="tsd-comment tsd-typography">
                    <div class="lead">
                        <p>This can be set to create a custom paper size, but is normally automatically obtained from the <a href="drawingsheet.html#size">size</a> parameter.</p>
                    </div>
                    <p><em>Flags</em> : cached, parameter</p>
                    <p><em>Default expression</em> : <code>this.papersize[this.size].ySize</code></p>
                </div>
                <!--
-->
            </section>
        </section>
    </div>
</div>
</body>
</html>

 

Link to comment
Share on other sites

This brute force method isn't fast.

The macro will fail, maybe spectacularly, if the document does not contain "<section" or "</section"

But hoping this will get you started.

 

Variable Set Bool %SectionEndFound% to "False"
Variable Set Integer %LineCount% to 0
 
Text Type (Simulate Keystrokes): <CONTROL>f // Find start of section
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): <section
Text Type (Simulate Keystrokes): <ENTER>
Text Type (Simulate Keystrokes): <ESC>
 
Repeat Until %SectionEndFound% Equals "True" // Check each line for end of section
  Text Type (Simulate Keystrokes): <HOME><SHIFT><END> // Select entire line
  Clipboard Copy
  Text Type (Simulate Keystrokes): <END><ARROW RIGHT> // Deselect line and go to start of next line
  Variable Set String %Text% from the clipboard contents
  If Variable %Text% Contains "</section>"
    Variable Set Bool %SectionEndFound% to "True"
  End If
  Variable Modify Integer %LineCount%: Increment
End Repeat
 
Text Type (Simulate Keystrokes): <END> // Select the section, starting at end of line
Repeat Start (Repeat %LineCount% times)
  Text Type (Simulate Keystrokes): <SHIFT><ARROW UP> // Select up one line
End Repeat
Text Type (Simulate Keystrokes): <SHIFT><HOME> // Select to start of first line of section
 
Text Type (Simulate Keystrokes): <DELETE> // Delete the selection

  
<VARIABLE SET BOOL Destination="%SectionEndFound%" Command="263" Value="FALSE"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%LineCount%" Value="0"/>
<COMMENT/>
<TEXT TYPE Action="0" Text="<CONTROL>f" _COMMENT="Find start of section"/>
<DELAY Flags="\x02" Time="200"/>
<TEXT TYPE Action="0" Text="<section"/>
<TEXT TYPE Action="0" Text="<ENTER>"/>
<TEXT TYPE Action="0" Text="<ESC>"/>
<COMMENT/>
<REPEAT UNTIL Variable="%SectionEndFound%" Condition="\x00" Value="True" _COMMENT="Check each line for end of section"/>
<TEXT TYPE Action="0" Text="<HOME><SHIFT><END>" _COMMENT="Select entire line"/>
<CLIPBOARD COPY/>
<TEXT TYPE Action="0" Text="<END><ARROW RIGHT>" _COMMENT="Deselect line and go to start of next line"/>
<VARIABLE SET STRING Option="\x02" Destination="%Text%" NoEmbeddedVars="FALSE"/>
<IF VARIABLE Variable="%Text%" Condition="\x06" Value="</section>" IgnoreCase="FALSE"/>
<VARIABLE SET BOOL Destination="%SectionEndFound%" Command="263" Value="TRUE"/>
<END IF/>
<VARIABLE MODIFY INTEGER Option="\x07" Destination="%LineCount%"/>
<END REPEAT/>
<COMMENT/>
<TEXT TYPE Action="0" Text="<END>" _COMMENT="Select the section, starting at end of line"/>
<REPEAT START Start="1" Step="1" Count="%LineCount%" Save="FALSE"/>
<TEXT TYPE Action="0" Text="<SHIFT><ARROW UP>" _COMMENT="Select up one line"/>
<END REPEAT/>
<TEXT TYPE Action="0" Text="<SHIFT><HOME>" _COMMENT="Select to start of first line of section"/>
<COMMENT/>
<TEXT TYPE Action="0" Text="<DELETE>" _COMMENT="Delete the selection"/>

 

Link to comment
Share on other sites

So it is just that one section to be deleted, uniquely identified by its first line containing the string
<section class="tsd-panel tsd-index-panel">
yes?

If so one way would be to use Text File Begin Process. Test each line for that string. If it does not contain the string use Variable Modify String > Add Text to build an output variable. When it *is* encountered, skip the Add Text and instead set a flag. Test the flag for each subsequent line and if it is still set continue ignoring the Add Text command But also test for the string
</section>
and when found reset the flag.

The remaining content will then be added to your output variable, which you will finally save to a file, replacing the original.

 

Ah, I see acantor beat me to it, so try his complete macro first!

 

Link to comment
Share on other sites

2 minutes ago, terrypin said:

So it is just that one section to be deleted, uniquely identified by its first line containing the string
<section class="tsd-panel tsd-index-panel">
yes? YES

If so one way would be to use Text File Begin Process. Test each line for that string. If it does not contain the string use Variable Modify String > Add Text to build an output variable. When it *is* encountered, skip the Add Text and instead set a flag. Test the flag for each subsequent line and if it is still set continue ignoring the Add Text command But also test for the string
</section>
and when found reset the flag.

The remaining content will then be added to your output variable, which you will finally save to a file, replacing the original.

And I"ll parse through with help manual in hand...

Ah, I see acantor beat me to it, so try his complete macro first!

I'm planning to learn from both



Thanks also to you, terrypin. By the time I'm done, my grasp of ME5 should be a lot stronger!

 

Link to comment
Share on other sites

Rats.

@acantorME5 doesn't  have Variable Set Boolean 

 

Little details like this and Split String, Join String (and possibly much more) weren't included in the product comparison chart on https://www.macros.com/compareproducts.htm -- result: I bought the wrong version.

 

I've emailed sales/customer support to put into motion my move to ME6 Pro.

 

Frankly, I can't imagine doing any coding of anything without string handling and Boolean operations...

Link to comment
Share on other sites

My code can be easily modified so you don't need Boolean variables.

 

Variable Set Integer %FakeBool% to 0 // 0 = FALSE, 1 = TRUE
Variable Set Integer %LineCount% to 0
 
Text Type (Simulate Keystrokes): <CONTROL>f // Find start of section
Delay: 200 milliseconds
Text Type (Simulate Keystrokes): <section
Text Type (Simulate Keystrokes): <ENTER>
Text Type (Simulate Keystrokes): <ESC>
 
Repeat Until %FakeBool% Equals "1" // Check each line for end of section
  Text Type (Simulate Keystrokes): <HOME><SHIFT><END> // Select entire line
  Clipboard Copy
  Text Type (Simulate Keystrokes): <END><ARROW RIGHT> // Deselect line and go to start of next line
  If Clipboard Contains "</section>"
    Variable Set Integer %FakeBool% to 1
  End If
  Variable Modify Integer %LineCount%: Increment
End Repeat
 
Text Type (Simulate Keystrokes): <END> // Select the section, starting at end of line
Repeat Start (Repeat %LineCount% times)
  Text Type (Simulate Keystrokes): <SHIFT><ARROW UP> // Select up one line
End Repeat
Text Type (Simulate Keystrokes): <SHIFT><HOME> // Select to start of first line of section
 
Text Type (Simulate Keystrokes): <DELETE> // Delete the selection

<VARIABLE SET INTEGER Option="\x00" Destination="%FakeBool%" Value="0" _COMMENT="0 = FALSE, 1 = TRUE"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%LineCount%" Value="0"/>
<COMMENT/>
<TEXT TYPE Action="0" Text="<CONTROL>f" _COMMENT="Find start of section"/>
<DELAY Flags="\x02" Time="200"/>
<TEXT TYPE Action="0" Text="<section"/>
<TEXT TYPE Action="0" Text="<ENTER>"/>
<TEXT TYPE Action="0" Text="<ESC>"/>
<COMMENT/>
<REPEAT UNTIL Variable="%FakeBool%" Condition="\x00" Value="1" _COMMENT="Check each line for end of section"/>
<TEXT TYPE Action="0" Text="<HOME><SHIFT><END>" _COMMENT="Select entire line"/>
<CLIPBOARD COPY/>
<TEXT TYPE Action="0" Text="<END><ARROW RIGHT>" _COMMENT="Deselect line and go to start of next line"/>
<IF CLIPBOARD Option="\x01" Text="</section>" CaseSensitive="FALSE"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%FakeBool%" Value="1"/>
<END IF/>
<VARIABLE MODIFY INTEGER Option="\x07" Destination="%LineCount%"/>
<END REPEAT/>
<COMMENT/>
<TEXT TYPE Action="0" Text="<END>" _COMMENT="Select the section, starting at end of line"/>
<REPEAT START Start="1" Step="1" Count="%LineCount%" Save="FALSE"/>
<TEXT TYPE Action="0" Text="<SHIFT><ARROW UP>" _COMMENT="Select up one line"/>
<END REPEAT/>
<TEXT TYPE Action="0" Text="<SHIFT><HOME>" _COMMENT="Select to start of first line of section"/>
<COMMENT/>
<TEXT TYPE Action="0" Text="<DELETE>" _COMMENT="Delete the selection"/>

 

Link to comment
Share on other sites

Using the method I outlined, this delivers the modified HTML in about one second, using your example file.

 

// Set the EOL character for later use.
Variable Set to ASCII Char 13 to %CR% // Set CR
Variable Set to ASCII Char 10 to %LF% // Set LF
Variable Set String %CRLF% to "%CR%%LF%"
// Set the 'flag' to 'Retain', so that all such lines will be kept.
Variable Set String %tAction% to "Retain"
// Start Text Process; Get tLine for each line of HTML
Text File Begin Process: C:\users\Test.html
 
// Test for start of section
  If Variable %tLine% Contains "<section class="tsd-index-section ">"
    Variable Set String %tAction% to "Ignore"
    Goto:EndProcess
  Else // Not start of section
  // Test for end of selection
    If Variable %tLine% Contains "</section>" // End of section
      AND
    If Variable %tAction% Equals "Ignore" // End of section
      Variable Set String %tAction% to "Retain"
      Goto:EndProcess
    Else // Not end of section
    // Test if tAction = Retain
      If Variable %tAction% Equals "Retain"
        Goto:Add
      Else
        Goto:EndProcess
      End If
    End If
  End If
   
  :Add
  // Add this line to the output variable
  Variable Modify String %tOutput%: Append Text (%tLine%)
  // Also add an EOL.
  Variable Modify String %tOutput%: Append Text String Variable (%CRLF%)
  :EndProcess
Text File End Process
Text Box Display: Final Output // Disabled after testing
// Save to new file Result.html in same folder.
(Or immediately replace original if preferred.)
Variable Modify String: Save %tOutput% to "C:\Users\Result.html"
 
<COMMENT Value="Set the EOL character for later use."/>
<VARIABLE SET TO ASCII CHAR Value="13" Destination="%CR%" _COMMENT="Set CR"/>
<VARIABLE SET TO ASCII CHAR Value="10" Destination="%LF%" _COMMENT="Set LF"/>
<VARIABLE SET STRING Option="\x00" Destination="%CRLF%" Value="%CR%%LF%" NoEmbeddedVars="FALSE"/>
<COMMENT Value="Set the 'flag' to 'Retain', so that all such lines will be kept."/>
<VARIABLE SET STRING Option="\x00" Destination="%tAction%" Value="Retain" NoEmbeddedVars="FALSE"/>
<COMMENT Value="Start Text Process; Get tLine for each line of HTML" _BACK="0080FFFF"/>
<TEXT FILE BEGIN PROCESS Filename="C:\\users\\Test.html" Start_Record="1" Process_All="TRUE" Records="1" Variable="%tLine%"/>
<COMMENT/>
<COMMENT Value="Test for start of section"/>
<IF VARIABLE Variable="%tLine%" Condition="\x06" Value="<section class=\"tsd-index-section \">" IgnoreCase="FALSE"/>
<VARIABLE SET STRING Option="\x00" Destination="%tAction%" Value="Ignore" NoEmbeddedVars="FALSE"/>
<GOTO Name="EndProcess"/>
<ELSE _COMMENT="Not start of section"/>
<COMMENT Value="Test for end of selection"/>
<IF VARIABLE Variable="%tLine%" Condition="\x06" Value="</section>" IgnoreCase="FALSE" _COMMENT="End of section"/>
<AND/>
<IF VARIABLE Variable="%tAction%" Condition="\x00" Value="Ignore" IgnoreCase="FALSE" _COMMENT="End of section"/>
<VARIABLE SET STRING Option="\x00" Destination="%tAction%" Value="Retain" NoEmbeddedVars="FALSE"/>
<GOTO Name="EndProcess"/>
<ELSE _COMMENT="Not end of section"/>
<COMMENT Value="Test if tAction = Retain"/>
<IF VARIABLE Variable="%tAction%" Condition="\x00" Value="Retain" IgnoreCase="FALSE"/>
<GOTO Name="Add"/>
<ELSE/>
<GOTO Name="EndProcess"/>
<END IF/>
<END IF/>
<END IF/>
<COMMENT/>
<LABEL Name="Add"/>
<COMMENT Value="Add this line to the output variable"/>
<VARIABLE MODIFY STRING Option="\x06" Destination="%tOutput%" Value="%tLine%" NoEmbeddedVars="FALSE"/>
<COMMENT Value="Also add an EOL."/>
<VARIABLE MODIFY STRING Option="\x07" Destination="%tOutput%" Variable="%CRLF%" NoEmbeddedVars="FALSE"/>
<LABEL Name="EndProcess"/>
<TEXT FILE END PROCESS/>
<TEXT BOX DISPLAY Title="Final Output" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 %tOutput%\r\n\\par }\r\n" Left="502" Top="-1" Width="1243" Height="1175" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _ENABLED="FALSE" _COMMENT="Disabled after testing"/>
<COMMENT Value="Save to new file Result.html in same folder.\r\n(Or immediately replace original if preferred.)"/>
<VARIABLE MODIFY STRING Option="\x11" Destination="%tOutput%" Filename="C:\\Users\\Result.html" Strip="FALSE" NoEmbeddedVars="FALSE"/>
<COMMENT/>
<COMMENT/>
 

 

Link to comment
Share on other sites

OK. (Again, I'm now working in ME6 Pro)

So much to learn, so little time -- 

 

I've copied what I'll call the 2nd iteration of the script in Terrypin's post above - the section of the code quotation that begins, "<COMMENT Value="Set the EOL..." etc.

 

I pasted it into ME6 Pro's direct editor.

When I try to save the .mex file, I get a series of pop up errors:

The variable "CR" is not current defined (but it IS in the script)

Same for variables "LF" and "CRLF", "tAction", "tLine", "tOutput"

 

As far as I can see, all of these variables are in fact declared. 

 

Should I be copying and pasting what I'll call the first iteration, the portion beginning, "//Set the EOL character for later use." and extending through to "Variable Modify String: Save %Output% to... etc."?

Link to comment
Share on other sites

When you copy and paste a macro the variables are, in fact, not created. Macro Express (and Macro Express Pro) looks through the script for variables and prompts you to create them. There are at least 2 prompts per variable. Normally it works just fine to press the ENTER key a bunch of times until it stops asking for new variables.

 

But, there are some rare cases where a command support different variable types. For example, it might allow either a string or an integer. In these cases Macro Express tries to make a good guess about which type of variable to define but once in a while it guesses wrong. For macros that you are writing this is normally not a problem. But for a macro from someone else you may need to figure out what type of macro is needed.

 

This may not affect you at all but if the macro misbehaves you know what to look for. If there is a problem usually you will see a message that says the variable is the wrong type.

Link to comment
Share on other sites

You don't say how you get your html file. But, since you have upgraded to Macro Express Pro you should check out the new HTTP Get command. This command allows you to specify a URL and a variable. Macro Express Pro will load the html and save it to the specified variable.

Link to comment
Share on other sites

Samrae, thanks. I've been through the scripting docs and skimmed the variables docs, but didn't happen on the information you've given me. (I'm sure it's there somewhere, now that I know what to look for). It didn't occur to me that vslues were pre-evaluated, thinking that evaluation happened at runtime. Interesting. Probably speeds up execution measurably.

 

I hadn't gotten as far as addressing how the files would be brought onto the virtual table for surgery. I'll definitely look into the HTML command(s).

Link to comment
Share on other sites

The fastest way to re-assign variables after pasting the code into a new macro is to simply hit Ctrl+s to start a Save. MEP will then prompt repeatedly as shown in my screenshot, and you then tap Enter (or Y) until finished.

BTW, note that the six variables I've used are all text types and the three whose types might ever be ambiguous are all prefixed with 't'.

 

TestPaste.thumb.jpg.c15b6bdaa39ca69a331c025f349dd800.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I've also exported the file as an MEX. Use File > Import > Import Macros... and browse to the file to import it. It will usually be placed in the Unassigned category. Reassign the variables and Edit the file paths appropriately. Here's a 'Before and After'.

 

Comparison.jpg

Delete-HTML-Section.mex

Link to comment
Share on other sites

2 hours ago, terrypin said:

I've also exported the file as an MEX. Use File > Import > Import Macros... and browse to the file to import it.

 

Ah - I thought that the code snippets included in the answers above had been saved as MEX, and that the contents had been pasted from the MEX file. By just now opening an MEX in Notepad, I see that a MEX file is formatted far differently than the content I saw above in the quote panes.

 

That leads to a couple more newbie questions:

 

What kind of export created the code snippets above? Or are they simply the result of cutting from the direct editor and pasting into the forum quotation pane?

 

Why are these code snippets expressed in two segments/example blocks containing the same actions? Is this a convention that evolved for forum postings?

 

(By "segments" I mean that each quote block above contains the same information in two formats. These formats correspond to the two view types that can be toggled in the direct editor, type (1) where commands are in angle brackets ["script"]; type (2) where command lines are plain text ["ASCII".])

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...