Jump to content

Creating a Table from Mtext


broncos15

Recommended Posts

So I have already created a routine that will insert a keynote table with a certain numerical block in the each row of the 1st column. For example, a 4 row table with 4 square blocks numbered 1-4. This routine is awesome to use when first starting projects, the issue is on past projects that someone instead used mtext. What I am wanting to do is to convert this mtext into a table. Once I can extract each line of the mtext I am fine with the code, but I'm having issues with how to handle the information. The text string might read when dumping the text string

"[url="file://\\A1;\\pxt30;PROPOSED"]\\A1;\\pxt30;PROPOSED[/url] USE A TABLE\\P\\PPROPOSED TABLE\\P\\THIS IS AN EXAMPLE"

. I want to extract the text and insert it into column 2 of my table, where \\P\\ is what differentiates what would be in each column. To do this I have a few questions 1)How can I find the #of \\P\\ in the text (that way I can make a table with +1 that amount of rows). 2) How can I copy what is just between the \\p\\ so that each row in column 2 reads that information. In this example, I would have row 1: PROPOSED USE A TABLE, row 2:PPROPOSED TABLE, and row 3: THIS IS AN EXAMPLE.

Link to comment
Share on other sites

The one you want is a Vl command and it returns the starting character, will try to find.

 

from help

pattern is not found; the first character of the string is position 0.

Examples

(vl-string-search "foo" "pfooyey on you")

1

(vl-string-search "who" "pfooyey on you")

nil

(vl-string-search "foo" "fooey-more-fooey" 1)

11

 

; note problem with p & P need to strcase it so always P
(setq str "[url="file://\\A1;\\pxt30;PROPOSED"]\\A1;\\pxt30;PROPOSED[/url] USE A TABLE\\P\\PPROPOSED TABLE\\P\\THIS IS AN EXAMPLE")

Command: (vl-string-search "[url="file://\\p"]\\p[/url]" str)
4
Command: (vl-string-search "[url="file://\\P"]\\P[/url]" str 7)
31

Link to comment
Share on other sites

The one you want is a Vl command and it returns the starting character, will try to find.

 

 

 

; note problem with p & P need to strcase it so always P
(setq str "[url="file://\\A1;\\pxt30;PROPOSED"]\\A1;\\pxt30;PROPOSED[/url] USE A TABLE\\P\\PPROPOSED TABLE\\P\\THIS IS AN EXAMPLE")

Command: (vl-string-search "[url="file://\\p"]\\p[/url]" str)
4
Command: (vl-string-search "[url="file://\\P"]\\P[/url]" str 7)
31

BigAl, thank you so much for the help! So when I am testing it on an mtext object that has 5 \\P\\, it only returns the first one. Code
(setq
       info (vl-string-search "[url="file://\\P\\"]\\P\\[/url]" (vla-get-textstring obj)))

. How can I find the location of every paragraph/empty space?

Link to comment
Share on other sites

Here is a string split function that may help:

; Based on code by Luis Esquivel. See: https://www.theswamp.org/index.php?topic=7272.msg90039#msg90039
; (KGA_String_Split "aabbaaccaa" "aa" nil) => ("" "bb" "cc" "")
; (KGA_String_Split "aabbaaccaa" "AA" nil) => ("aabbaaccaa")
; (KGA_String_Split "aabbaaccaa" "AA" T)   => ("" "bb" "cc" "")
; (KGA_String_Split "aabbaaccaa" "" nil)   => nil
(defun KGA_String_Split (str sub ignoreCaseP / i j len lst srchStr)
 (if (/= 0 (setq len (strlen sub)))
   (progn
     (if ignoreCaseP
       (progn
         (setq srchStr (strcase str))
         (setq sub (strcase sub))
       )
       (setq srchStr str)
     )
     (setq i 0)
     (while (setq j (vl-string-search sub srchStr i))
       (setq lst (cons (substr str (1+ i) (- j i)) lst))
       (setq i (+ j len))
     )
     (reverse (cons (substr str (1+ i)) lst))
   )
 )
)

Link to comment
Share on other sites

If you look at the command check the help I did not mention that you can imply a start position in the string (vl-string-search "\\p" str startposition)

 

so (vl-string-search "\\p" str) start at very first character note help this is 0 but if left out starts at beginning.

find 1st \\p returns 4 use substr to make a list

so (vl-string-search "\\p" str 6) use substr & cons to add to list a 2nd line

so (vl-string-search "\\p" str 33) use substr & cons to add to list a 3rd line

keep repeating till no more

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.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...