Jump to content

Recommended Posts

Posted

I used the "Annotate Suite" in AutoCAD 2011, which has 25 LISP programs for use with text and mtext. It was developed by PowerSolutions, which closed down, so the latest version only works in AutoCAD 2011 and below. I found some LISPs throughout the years that perform the same functions, and I used them, but there is one that I have never found and would like someone to develop. It is the Paragraph Adjustment. It is very useful for adjusting general project notes by increasing or decreasing all the paragraphs of the note to a maximum width allowed by the format of the project sheet available for each project. It does not automatically adjust all 10, 15 notes, but it helps a lot in interactive mode, adjusting paragraph by paragraph by repeating the PA command. Attached is the original explanation from the Suite's user manual. Can anyone help? I would greatly appreciate it.

PA.dwg

Posted

So how are your LISP abilities? From what I see it should be reasonably easy to create something...

 

If you use the LISP command GETPOINT twice and record the results in 2 variables (this is the easiest method)

Extract the X coordinates from these 2 points using CAR on each of these calculate the distance in x - this is the width of the rectangle, save as a variable

If it was me I'd subtract a little from that just so my text wasn't over running any lines

Select the text using ENTGET for single texts and save its handle as a variable

Use ENTMOD method (there is a good worked example online) to update the text

 

And that should set mtext width to the paragraph width.

 

 

If you have dtexts that over run the rectangle area you'll need to convert these to mtext (help is out there and also help to work out dtext width)... and then proceed as above.

 

Might give you a start to work something out

Posted (edited)

I can see a few problems, the text is very different mix, for me I would look at mtext. There is txt2mtxt as 1st step, this allows the changing of a paragraph width.

 

Ok may have an idea for this

This is the text required

for a test.

 

If you look carefully the 1st line does not have a full stop so could convert into mtext, does end of line have a full stop " If so make a new line. You would select the text and use a sort on Y for line order.

 

This would be a straight txt2mtxt. But then run option remove seperate lines. 

This is the text required for a test.

This is the text required for a test.

This is the text required for a test.

 

"This is the text required for a test. This is the text required for a test. This is the text required for a test."

 

So may be 2 -3 different functions. Need to think about it. 

 

A start dont run ! For the 3 lines do txt2mtxt 1st, will look into width.

(setq obj (vlax-ename->vla-object (car (entsel "\nPick mtext object "))))
(setq str (vlax-get obj 'textstring))
(while (wcmatch str "*\\P*")
(setq str (vl-string-subst " " "\\P" str))
)
(vlax-put obj 'textstring str)
(vlax-put obj 'width 6)

image.png.261f4cd9fe6d9903aae80100fdb5eca5.png

Edited by BIGAL
Posted

Hopefully these make sense as a starting point. 

 

; https://www.cadtutor.net/forum/topic/94735-paragraph-adjust/

; By AlanH Dec 2024

(defun AH:strippara ( / ent obj str ht )
(setq ent (entsel "\nPick mtext "))
(setq obj (vlax-ename->vla-object (car ent)))
(setq str (vlax-get obj 'textstring))
(setq ht (cdr (assoc 40 (entget (car ent)))))
(while (wcmatch str "*\\P*")
  (setq str (vl-string-subst " " "\\P" str))
)
(vlax-put obj 'textstring str)
(vlax-put obj 'width (/ (* 0.85 (* ht (strlen str))) 3.))
(princ)
)

(defun AH:textlines ( / )
(setq ss (ssget '((0 . "TEXT"))))
(setq lst '())
(repeat (setq x (sslength ss))
  (setq obj (vlax-ename->vla-object (ssname ss (setq x (1- x)))))
    (setq str (vlax-get obj 'textstring))
  (setq ins (vlax-get obj 'insertionpoint))
  (setq y (cadr ins))
(setq lst (cons (list Y str) lst))
)

(setq lst (vl-sort lst '(lambda (x y) (> (car x)(car y)))))
(setq str "")

(foreach val lst
 (setq nstr (cadr val))
 (setq num (strlen nstr))
 (if (= (substr nstr num) ".")
  (setq str (strcat str " " nstr "\\" "P"))
  (setq str (strcat str " " nstr))
 )
)

(setq pt (getpoint "\nPick point for mtext "))
(setq ht (cdr (assoc 40 (entget (ssname ss 0)))))
(command "mtext" Pt (mapcar '+ pt (list 3.5 0.0 0.0)) "-" "")
(setq obj (vlax-ename->vla-object (entlast)))
(vlax-put obj 'textstring str)
(vlax-put obj 'width (/ (* 0.85 (* ht (strlen str))) 3.))

(princ)
)

(defun c:T1 ( / )(AH:strippara))
(defun c:T2 ( / )(AH:textlines))

(alert "text-mtext\n\nT1 is used for adding paragrpahs looking for the period .\n\nT2 is used to select plain text and convert to mtext.")

 

  • Like 1
  • 2 weeks later...
Posted

Thanks for the answer, Steven. My experience in creating lisps is almost zero, just very basic things. What I did over 40 years using CAD, since version 2.64b (which I still have today), was to look for lisps with functions that I wanted to use and, by editing and mixing various parts of lisps, create one that would perform the function I needed. In the case of PA, it seems very clear to me how it works. Imagine a text with several paragraphs. You select them with a window where the first point is above and to the left of the first paragraph that you want to adjust, and the second point in the window selects all the paragraphs below that you want to adjust, and by pulling the window to the right side, the right line of the window defines the limit of the width that each paragraph can have. Ready, it adjusts the selected paragraphs, and within the limits to the right of the open window. I understand that PA transforms every selected paragraph chain into Mtext, and based on the window we open it limits the text on the right side by defining a new width for this Mtext, redistributing it downwards or upwards, and then explodes the Mtext. It seems simple at first, but not to me. Notes in a project can have 30, 40 paragraphs, and depending on the project I have to adjust them to different spaces, sometimes 14 cm, sometimes 17,5cm, sometimes I want to gain space in height, therefore external in width, and sometimes the opposite. And for this, it is not very useful to keep transforming each paragraph into Mtext, redistributing it, going to the next one and so on. PA does this more quickly. This also applies to notes and observations distributed throughout the project, where PA helps to redistribute the text in the space where the note or observation is. For me, it is extremely useful and I use it daily in all projects.

Posted
On 12/10/2024 at 8:27 PM, BIGAL said:

I can see a few problems, the text is very different mix, for me I would look at mtext. There is txt2mtxt as 1st step, this allows the changing of a paragraph width.

 

Ok may have an idea for this

This is the text required

for a test.

 

If you look carefully the 1st line does not have a full stop so could convert into mtext, does end of line have a full stop " If so make a new line. You would select the text and use a sort on Y for line order.

 

This would be a straight txt2mtxt. But then run option remove seperate lines. 

This is the text required for a test.

This is the text required for a test.

This is the text required for a test.

 

"This is the text required for a test. This is the text required for a test. This is the text required for a test."

 

So may be 2 -3 different functions. Need to think about it. 

 

A start dont run ! For the 3 lines do txt2mtxt 1st, will look into width.

(setq obj (vlax-ename->vla-object (car (entsel "\nPick mtext object "))))
(setq str (vlax-get obj 'textstring))
(while (wcmatch str "*\\P*")
(setq str (vl-string-subst " " "\\P" str))
)
(vlax-put obj 'textstring str)
(vlax-put obj 'width 6)

image.png.261f4cd9fe6d9903aae80100fdb5eca5.png

Thanks for the answer Bigal. I replied to Steven and I think you are right about transforming it into mtext, defining a new width, and I think you can explode the mtext back into text. Just type PA, open the window and it's done. I attached a video where you can see how Paragraph Adjust works. The open window involves the paragraphs from the first to the last that you want to redistribute in width, and the second point in the window on the right defines the new maximum width of the texts. And that's it, it's done.

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...