PDA

View Full Version : Text to Mtext



bowtle
2008-05-06, 03:34 AM
I have searched unsucessfully for a way to convert multiple single text entities into multiple Mtext entities preserving the insertion point ... The express tools Txt2Mtxt agglomerates all the text into one entity and does not preserve the insertion point

I know a liitle about lisp, even less about visual lisp and less again about vba ... and have given up on trying to write something myself.

I have found a couple of visual lisp programs searching the forums that do the same as the express tools but can't find one to do what i would like.

Any help would be greatly appreciated


Greg B

rkmcswain
2008-05-06, 12:11 PM
So you want it to hold the insertion point and move the text string?

Brian Benton
2008-05-06, 12:11 PM
You want to be able to select multiple text objects and convert them to Mtext but not join them as one object?

bowtle
2008-05-06, 12:27 PM
Yes that is exactly what i want to do...

Since my first post i have had another attempt at writing something myself ... it works for a single entity but crashes because i cant end the MText command.

I have since posted the code in the Autolisp forum.



;;;
;;; convert multiple text entities to multiple mtext entities maintaining the insertion point
;;;

;;; basically create a selection set of the entities to change, extract all the relevant information
;;; ie size, style, rotation angle, insertion point, justification
;;; erase the text and create a piece of mtext
;;;




(defun C:Tx2M (/ ss itm elist H V hnd ent ins)


;;;
;;;--------------------------------------
;;; convert acad polar angle to a bearing
;;; polar angle must be in decimal degrees
;;;______________________________________
;;;
(defun polar_ang_to_bng (a)
(setq a (- 450 a) )
(if (>= a 360)
(setq a (- a 360)) (setq a a)
) ;if
) ;




(prompt "\nSelect Text objects to convert to MText: ")
(setq ss (ssget (list (cons 0 "TEXT"))))
(setq itm 0)
(if ss
(repeat (sslength ss)

(setq hnd (ssname ss itm)) ; get the handle for itm
(setq ent (entget hnd)) ;

(setq
en_type (cdr (assoc 0 ent))
en_txt (cdr (assoc 1 ent)) ; the text value
en_lyr (cdr (assoc 8 ent)) ; the layer the text is in
en_size (cdr (assoc 40 ent)) ; text size
en_ang (cdr (assoc 50 ent)) ; text angle
en_style (cdr (assoc 7 ent)) ; text style

en_H (cdr (assoc 72 ent)) ; get the horizontal alignment of the text
en_V (cdr (assoc 73 ent)) ; get the vertical alignment of the text
); setq

(if (and (= en_H 0) (= en_V 0)) ; if the horiz and vert just = 0 then
(setq en_ins (cdr (assoc 10 ent))) ; we have the default insertion point
(setq en_ins (cdr (assoc 11 ent))) ; otherwise get the insertion point
)


(setq en_just "")

(cond
( (= en_V 3) (setq en_just "T" ) )
( (= en_V 2) (setq en_just "M" ) )
( (= en_V 1) (setq en_just "B" ) )
)

(cond
( (= en_H 0) (setq en_just (strcat en_just "L" )) )
( (= en_H 1) (setq en_just (strcat en_just "C" )) )
( (= en_H 2) (setq en_just (strcat en_just "R" )) )
)

;
; angle is POLAR in radians - 0 horizontal increase anticlockwise
; convert to degrees & bearings - 0 vertical increase clockwise
;
(setq en_ang (/ (* en_ang 180.0) Pi) )

(setq en_ang (Polar_ang_to_Bng en_ang)) ; convert polar to bearing

(setq en_ang (- en_ang 90.0)) ; subtract 90 because mtext is different



;(while (> en_ang 180.0) (setq en_ang (- en_ang 180.0)))




(command "ERASE" hnd "")
(command "Layer" "Set" en_lyr "")
(command "MTEXT" en_ins "Height" en_size "Justify" en_just "Rotation" en_ang "Style" en_style "Width" "0" en_txt "")

); repeat

); if

); function





Any advice or assistance would be much appreciated

GregB

rkmcswain
2008-05-06, 01:01 PM
Yes that is exactly what i want to do... Which one? Post #2 or post #3?

bowtle
2008-05-06, 10:10 PM
Which one? Post #2 or post #3?

Sorry .. was late last night ... actually want it to do both

1. So you want it to hold the insertion point and move the text string?

... Yes hold the insertion point and the text justification


2. You want to be able to select multiple text objects and convert them to Mtext but not join them as one object?

... Yes


Thanks

rkmcswain
2008-05-06, 10:51 PM
2. You want to be able to select multiple text objects and convert them to Mtext but not join them as one object?


ToolPac (http://www.dotsoft.com/toolpac.htm) includes a tool to convert a selection set of TEXT into MTEXT but not join them into a single mtext string.

I don't recall what happens regarding the insertion point however.