Jump to content

Recommended Posts

Posted

T just is needed for my bricscad, change back to text justify for acad.

Typed on phone auto correct makes life hard

Posted

I have updated the code now works out the hor or ver it uses a 20 degree check, a bit rough but seems to work. One less user input.

 

; https://www.cadtutor.net/forum/topic/88262-mtext-align-and-mtext-width-0/

; simple align text to line
: By AlanH July 2024

;;; Justification Macros
;;;
;;; https://www.cadtutor.net/forum/topic/35569-text-justification-lisp/?do=findComment&comment=289008
;;;
;;; BY alanjt (a.k.a. Alan J. Thompson)
;;;
;;; Customized By SLW210
;;;

(defun c:alt1 ( / _justifyIt horver ent fo k ans but ss oldsnap pt obj ptn fname)

(defun dtr (a)
(* pi (/ a 180.0))
)

(defun _justifyIt (justify title / )
 (princ (strcat "\nSelect *Text to " title " justify: "))
 (if (setq ss (ssget '((0 . "ATTDEF,MTEXT,TEXT"))))
   (command "_.TJUST" ss "" justify)
 )
 (princ)
)

(defun horver ( / )
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (= ahdef nil)(setq ahdef 1))
(setq ans (ah:butts ahdef "h"  '("Horizontal or vertical " "Hor " "Ver"))) ; ans holds the button picked value
(setq ahdef but)
)

(while (setq ent (car (entsel "\nPick single text for alignment Enter to exit ")))

(setq pt (cdr (assoc 10 (entget ent))))
(setq X (car pt) Y (cadr pt))

(if (= fname nil)
(progn
(setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))

(write-line "AHtxtpos : dialog 	{" fo)
(write-line "	label =\"Please Choose \" ;" fo)
(write-line "	: column	{" fo)
(write-line "	: boxed_radio_row	{" fo)
(write-line " width = 24 ;" fo)
(write-line "	: radio_button	{" fo)
(write-line "key = \"Rb1\";" fo)
(write-line "label = \"Top L\";" fo)
(write-line "	}" fo)
(write-line "	: radio_button	{" fo)
(write-line "key = \"Rb2\";" fo)
(write-line "label = \"Top Mid\";" fo)
(write-line "	}" fo)
(write-line "	: radio_button	{" fo)
(write-line "key = \"Rb3\";" fo)
(write-line "label = \"Top R\";" fo)
(write-line "	}" fo)
(write-line "	}" fo)
(write-line "spacer_1 ;" fo)
(write-line "	: boxed_radio_row	{" fo)
(write-line "	: radio_button	{" fo)
(write-line "key = \"Rb4\";" fo)
(write-line "label = \"Mid L\";" fo)
(write-line "	}" fo)
(write-line "	: radio_button	{" fo)
(write-line "key = \"Rb5\";" fo)
(write-line "label = \"Center\";" fo)
(write-line "	}" fo)
(write-line "	: radio_button	{" fo)
(write-line "key = \"Rb6\";" fo)
(write-line "label = \"Mid R\";" fo)
(write-line "	}" fo)
(write-line "	}" fo)
(write-line "spacer_1 ;" fo)
(write-line "	: boxed_radio_row	{" fo)
(write-line "	: radio_button	{" fo)
(write-line "key = \"Rb7\";" fo)
(write-line "label = \"Bot L \";" fo)
(write-line "	}" fo)
(write-line "spacer_1 ;" fo)
(write-line "	: radio_button	{" fo)
(write-line "key = \"Rb8\";" fo)
(write-line "label = \"Bot mid\";" fo)
(write-line "	}" fo)
(write-line "	: radio_button	{" fo)
(write-line "key = \"Rb9\";" fo)
(write-line "label = \"Bot R\";" fo)
(write-line "	}" fo)
(write-line "	}" fo)
(write-line "spacer_1 ;" fo)
(write-line "	ok_cancel;" fo)
(write-line "	}" fo)
(write-line "	}" fo)

(close fo)
)
)

(setq dcl_id (load_dialog fname))
(if (not (new_dialog "AHtxtpos" dcl_id) )
(exit)
)
(set_tile "Rb1" "1")
(setq j 1)
(repeat 9
(setq k (strcat "Rb" (rtos j 2 0)))
(action_tile k  (strcat "(setq but " (rtos j 2 0) ")" "(done_dialog)"))
(setq j (+ j 1))
)
(action_tile "accept" "(done_dialog)")
(start_dialog)
(unload_dialog dcl_id)

(cond
((= but 1)(_justifyIt "_TL" "Top Left"))
((= but 2)(_justifyIt "_TC" "Top Center"))
((= but 3)(_justifyIt "_TR" "Top Right"))
((= but 4)(_justifyIt "_ML" "Middle Left"))
((= but 5)(_justifyIt "_MC" "Middle Center"))
((= but 6)(_justifyIt "_MR" "Middle Right"))
((= but 7)(_justifyIt "_BL" "Bottom Left"))
((= but 8)(_justifyIt "_BC" "Bottom Center"))
((= but 9)(_justifyIt "_BR" "Bottom Right"))
)

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)

(if (= ss nil)
(progn (alert "You have not selected anything will now exit")(exit))
)

(setq obj (vlax-ename->vla-object (ssname ss 0)))
(setq pt1 (vlax-get obj 'insertionpoint))
(setq obj (vlax-ename->vla-object (ssname ss 1)))
(setq pt2 (vlax-get obj 'insertionpoint))
(setq ang (abs (angle pt1 pt2)))
(if (> ang pi)(setq ang (- ang pi)))
; angle check is 20 degrees (dtr 20)
(cond 
((and  (> ang  (- (/ pi 2)(dtr 20))) (< ang (+ (/ pi 2)(dtr 20))))(setq dir "Ver"))
((and  (> ang  (- (* pi 1.5)(dtr 20))) (< ang (+ (* pi 1.5)(dtr 20))))(setq dir "Ver"))
((and  (> ang (- (* 2 pi) (dtr 20))) (< ang (dtr 20)))(setq dir "Hor"))
((and  (> ang  (- pi (dtr 20))) (< ang (+ pi (dtr 20))))(setq dir "Hor"))
((horver))
)

(repeat (setq k (sslength ss))
 (setq obj (vlax-ename->vla-object (ssname ss (setq k (- k 1)))))
 (setq ptn (vlax-get obj 'Insertionpoint))
 (if (= dir "Hor")
  (setq Ptn (list (car ptn) Y ))
  (setq Ptn (list X (cadr ptn)))
 )
 (vlax-put obj 'insertionpoint ptn)
) ; repeat

(setq x nil y nil)

) ; while


(vl-file-delete fname)
(setvar 'osmode oldsnap)

(princ)
)
(C:alt1)

 

Posted

I am getting 

Quote

Enter a justification option
[Left/Align/Fit/Center/Middle/Right/TL/TC/TR/ML/MC/MR/BL/BC/BR] <MC>: _TC
Command: ; error: AutoCAD.Application: Incorrect number of elements in SafeArray

 

Busy this morning, I'll see if I can get to it later, I changed the TJUST to JustifyText.

Posted (edited)

I copied the code from here and ran it, it worked fine multiple times, I am using Bricscad.

 

Just pick 1 text as ver or hor matching position, then justification, then do a normal window select of text. Enter all done. 

 

(command "_.justifytext" ss "" justify)

 

 

Testing on your sample dwg. You can send me a PM with a new dwg if you want to test. 

Edited by BIGAL
Posted

I'll try to work it out. Thanks for all the work you put in.

 

 

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