4D Write Pro: deleting elements (images/page breaks/session breaks)


If I add an anchored image in a 4D Write pro document using code: WP Add picture, how can I delete it using code?

I also want to clean up a template document by removing unnecessary page breaks and section breaks. How to delete those in code?

Kind regards,

I think this has been answered before,

but it is a bit counter-intuitive; use https://doc.4d.com/4Dv17/4D/17/WP-SET-TEXT.301-3770079.en.htmlWP SET TEXT> on the range passing “”

Hello Koen

Deleting anchored pictures is not possible yet if you udon’t have interface (you can’t use standard action) FYI, we’re working on a “WP Delete” that will allow the deletion of almost anything (except the doc itself)
(Should be available in v17R5 or v17R6)

About cleaning breaks, he is a sample code that will keep only paragraphs (in a new document…)

<code 4D>
WPareaNew:=WP New
$colParagraphs:=WP Get elements(WParea;wk type paragraph)
For each ($paragraph;$colParagraphs)
$RangeDoc:=WP New($paragraph)
WP INSERT DOCUMENT(WPareaNew;$RangeDoc;wk append)
End for each
</code 4D>

Hope this helps


Hi Roland,

Thanks for chiming in.
Concerning the anchored images, I think I can wait until the WP Delete is implemented.

I tried your code for cleaning breaks. I just added:

<code 4D>
WP INSERT DOCUMENT(WParea;WPareaNew;wk replace)
</code 4D>

To replace the content of the original document.

But there are two problems:

  1. I’m also getting header and footer text as paragraphs in the collection.
  2. The paragraphs collection is not ordered, the result I’m getting is mixed up.
    Eg: create a new document, type text P1, insert section break, type P2, insert page break, type P3. Then go back to page 1 and add a section 1 header (H1) and footer (F1)
    When running the code, I get:

But I could solve both by changing the second line of the code to:

<code 4D>
$rangeBody:=WP Create range(WParea;wk start text;wk end text)
$collection:=WP Get elements($rangeBody;wk type paragraph)
</code 4D>

Is this the right way?
In my testing the paragraphs came in the correct order, but can I be sure this will always be the case?

Kind regards,

ok, sorry my code was a bit too generic (quick and durty)

If you use the BODY as source. the paragraphs will be sorted. yes always.

But use the command “WP Get body”, it’s done for that :slight_smile:



Removing picture in 4D Write Pro is easier with the 4D v18 R2. You can find more details on the 4D blog.

Download 4D v18 R2 and find all the 4D v18 R2 new features on our web site.