Change text to mtxt, add annotative scales LISP

Change text to mtxt, add annotative scales LISP

Kate.RobinsonR9FXS
Participant Participant
999 Views
6 Replies
Message 1 of 7

Change text to mtxt, add annotative scales LISP

Kate.RobinsonR9FXS
Participant
Participant

Hello,

 

I am exporting contour xrefs from a 3d program which spits out the labels as text. I have created a lisp which converts this text to mtext, adds a background mask, and justifys all the text to middle centre and this works great. What i have also created is a simple script which turns on ANNOAUTOSCALE then cycles through the CANNOSCALE of certain scales which essentially gives me somewhat automated annotative text scales.

 

The manual things i have to do

1. open and select all text to make it annotative

2. run the script which gives annotation scales to my text

3. run the lisp which turns all the txt to mtxt etc

4. change the background mask to 1.1 not 1.5 as that is set as the default.

 

Information im looking for.

1. is it possible to set the text objects to annotative? alternatively could set the a textsyle which is already annotative?

2. is it possible to change the background mask border offset via lisp? (have googled alot but no dice)

2. is it possible to add my lisp and script together to run all at once

 

 

Lisp txttomtext code

(defun C:ContourExport (/ ss1 en n)

;; Select all Text objects
(setq ss1 (ssget "_X" (list (cons 0 "TEXT"))))

(setq i -1)
(if ss1
(repeat (sslength ss1)
(setq elist (cdr (assoc -1 (entget (ssname ss1 (setq i (1+ i)))))))
(command "TXT2MTXT" elist "")
)
)

;; Select all MText objects
(setq ss1 (ssget "_X" (list (cons 0 "MTEXT"))))

(if ss1
(progn
(setq n (sslength ss1))
(repeat n
(setq n (1- n))
(setq en (vlax-ename->vla-object (ssname ss1 n)))
(if (vlax-property-available-p en 'BackgroundFill)
(vlax-put en 'BackgroundFill 1)
)
(vlax-put en 'AttachmentPoint 5) ; Set the attachment point to middle center
)
)
(prompt "\nNo MText found.")
)
(princ)
)

 

Script code

ANNOAUTOSCALE 1

CANNOSCALE "1:500 (M)"
CANNOSCALE "1:2000 (M)"
CANNOSCALE "Metres 1:1000"

 

0 Likes
Accepted solutions (1)
1,000 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant

Post 2 dwgs, initial state and desired.

0 Likes
Message 3 of 7

Kate.RobinsonR9FXS
Participant
Participant

done

0 Likes
Message 4 of 7

ВeekeeCZ
Consultant
Consultant

Those annotative styles, can't they be part of the dwt you're exporting to?

0 Likes
Message 5 of 7

Kate.RobinsonR9FXS
Participant
Participant

Do you mean the text styles? they are apart of the dwt but i can't export to those specific styles if that whats you mean

KateRobinsonR9FXS_0-1698743458571.png

ArialNarrow2.5 is the anno Texstyle i would put them on after export.

0 Likes
Message 6 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

Ok, I see, but 1:2000 scale is not part of it. 

 

(vl-load-com)

(defun c:CountourExportsTextFix ( / s i e ts)

  (if (setq s (ssget "_X" '((0 . "TEXT"))))
    (progn
      (setvar '*txt2mtxtcombinemtext 0)
      (command "_.TXT2MTXT" s "")))

  (setq ts (tblobjname "Style" "ArialNarrow2.5"))
  
  (if (setq s (ssget "_X" '((0 . "MTEXT"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i))))
;      (setpropertyvalue e "Attachment" 5) it does not change the point
      (vlax-put (vlax-ename->vla-object e) 'AttachmentPoint 5)
      (setpropertyvalue e "BackgroundFill" 1)
      (setpropertyvalue e "UseBackgroundColor" 1)
      (setpropertyvalue e "BackgroundTransparency" 0)      
      (setpropertyvalue e "BackgroundScaleFactor" 1.1)
      (setpropertyvalue e "Annotative" 1)
      (and ts (setpropertyvalue e "TextStyleId" ts))
      ))

  (setvar 'ANNOAUTOSCALE 1)
  (setvar 'CANNOSCALE "1:500 (M)")
  (command "_.-scalelistedit" "_d" "1:2000 (M)" "_add" "1:2000 (M)" "1:2" "_e")
  (setvar 'CANNOSCALE "1:2000 (M)")
  (setvar 'CANNOSCALE "Metres 1:1000")
  (setvar 'ANNOAUTOSCALE 0)
  
  (princ)
  )

 

0 Likes
Message 7 of 7

Kate.RobinsonR9FXS
Participant
Participant

That worked a treat! Thanks heaps.

 

The anno scales can definitely be added to the dwt, not sure why 1:2000 was missing.

0 Likes