Jump to content

Justify Text with no options?


ILoveMadoka

Recommended Posts

I've got a few different routines to change the justification to any

of the available justifications in Autocad. Each one is pretty verbose.

What I'm looking for is a simple routine to pick my text and have it change it to Left Center .

No options, no user input.

 

Select Objects

Enter

Enter

Done!

 

Anyone have a simple routine like that or can you point me to one?

 

You guys are awesome!

TIA!

Link to comment
Share on other sites

Here is an old one I downloaded once...

(defun c:tj (/ j e p11 p10 f en plin p10n fn y)
   (setq j (getstring "\nLeft/Center/Middle/Right  "))
   (setq j (strcase j))
   (setq e (entget (car (entsel))))
   (setq p11 (assoc 11 e))
   (setq p10 (assoc 10 e))
   (setq f (assoc 72 e))
   (setq en e)
   (if (= (cdr f) 0) (setq plin (cons 11 (cdr p10))))
   (if (= (cdr f) 0) (setq en (subst plin p11 en)))
   (if (and (= j "L") (/= (cdr f) 0))
       (progn
           (setq p10 (cons 10 (cdr p11)))
           (setq en (subst p1on p10 en))
       )
   )
   (IF (= J "L") (setq fn 0))
   (IF (= J "C") (setq fn 1))
   (IF (= J "M") (setq fn 4))
   (IF (= J "R") (setq fn 2))
   (setq fn (cons 72 fn))
   (setq en (subst fn f en))
   (entmod en)
       (princ)
)

Link to comment
Share on other sites

Nope that's not it.

I have that one and it doesn't address the

"newer" justifications.

I think the Middle Left, etc.. use both (assoc 71 & (assoc 72

 

Autocad release 9 had just come out when I started CAD...

So Middle Left and such were not around back then..

 

I guess if I could nail down group codes are specific

to a particular justification I could modify the above code

to suit.

Link to comment
Share on other sites

(defun c:tjLeft(/ ss obj)
 (vl-load-com)
 (and
   (setq ss (ssget "_+.:E:S" '((0 . "TEXT"))))
   (setq obj (vlax-ename->vla-object (ssname ss 0)))
   (vla-put-alignment obj acAlignmentLeft)
 )
 (princ)
)

;|
acAlignmentLeft
acAlignmentCenter
acAlignmentRight
acAlignmentAligned
acAlignmentMiddle
acAlignmentFit
acAlignmentTopLeft
acAlignmentTopCenter
acAlignmentTopRight
acAlignmentMiddleLeft
acAlignmentMiddleCenter
acAlignmentMiddleRight
acAlignmentBottomLeft
acAlignmentBottomCenter
acAlignmentBottomRight
|;

Link to comment
Share on other sites

So what is the syntax for Center Justified?

I thought it was simply replacing acAlignmentLeft

with acAlignmentCenter but that moved my text to 0,0

 

Thanks so much!

 

 

(defun c:tjLeft(/ ss obj)
 (vl-load-com)
 (and
   (setq ss (ssget "_+.:E:S" '((0 . "TEXT"))))
   (setq obj (vlax-ename->vla-object (ssname ss 0)))
   (vla-put-alignment obj acAlignmentLeft)
 )
 (princ)
)

;|
acAlignmentLeft
acAlignmentCenter
acAlignmentRight
acAlignmentAligned
acAlignmentMiddle
acAlignmentFit
acAlignmentTopLeft
acAlignmentTopCenter
acAlignmentTopRight
acAlignmentMiddleLeft
acAlignmentMiddleCenter
acAlignmentMiddleRight
acAlignmentBottomLeft
acAlignmentBottomCenter
acAlignmentBottomRight
|;

Link to comment
Share on other sites

Use this routine to get the object properties:

(defun c:dump (/ ent obj)
 (while (setq ent (entsel "\nSelect entity to get object data: "))
   (setq obj (vlax-ename->vla-object (car ent)))
   (vlax-dump-object obj t)
   (vlax-release-object obj)
 )
 (princ)
)

 

Select object:
#<VLA-OBJECT IAcadText 02ce832c>
; IAcadText: AutoCAD Text Interface
; Property values:
;   Alignment = 0
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00ac8928>
;   Backward = 0
;   Color = 256
;   Document (RO) = #<VLA-OBJECT IAcadDocument 01b694bc>
;   Handle (RO) = "A367"
;   HasExtensionDictionary (RO) = 0
;   Height = 5.0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 02cebb0c>
;   InsertionPoint = (1799.16 -194.612 0.0)
;   Layer = "POWER"
;   Linetype = "ByLayer"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   Normal = (0.0 0.0 1.0)
;   ObjectID (RO) = 29887800
;   ObjectName (RO) = "AcDbText"
;   ObliqueAngle = 0.0
;   OwnerID (RO) = 29804560
;   PlotStyleName = "ByLayer"
;   Rotation = 0.0
;   ScaleFactor = 1.0
;   StyleName = "SIMPLEX 0"
;   TextAlignmentPoint = (0.0 0.0 0.0)
;   TextGenerationFlag = 0
;   TextString = "this is a"
;   Thickness = 0.0
;   UpsideDown = 0
;   Visible = -1

 

See if this is what you wanted:

 

(defun c:tjc(/ ss obj)
 (vl-load-com)
 (if
   (and
     (setq ss (ssget "_+.:E:S" '((0 . "TEXT"))))
     (setq obj (vlax-ename->vla-object (ssname ss 0)))
     (setq ipt (vla-get-InsertionPoint obj)))
   (progn
     (vla-put-alignment obj acAlignmentCenter)
     (vla-put-TextAlignmentPoint obj ipt)
   )
 )
 (princ)
)

;|
acAlignmentLeft
acAlignmentCenter
acAlignmentRight
acAlignmentAligned
acAlignmentMiddle
acAlignmentFit
acAlignmentTopLeft
acAlignmentTopCenter
acAlignmentTopRight
acAlignmentMiddleLeft
acAlignmentMiddleCenter
acAlignmentMiddleRight
acAlignmentBottomLeft
acAlignmentBottomCenter
acAlignmentBottomRight
|;

Link to comment
Share on other sites

  • 7 months later...

Sorry i dont know much about programming within autoCAD. Could someone tell me how i would install this? i'm using land desktop 06

Link to comment
Share on other sites

Sorry i dont know much about programming within autoCAD. Could someone tell me how i would install this? i'm using land desktop 06

 

add it to your ACAD.LSP file

Link to comment
Share on other sites

Copy the code making sure you get the last line of the code, sometimes that is missed.

Paste it into your text editor like NotePad.

Save it to your ACAD folder, I have a sub folder named LISP which I save to.

Use APPLOAD at the command line

Navigate to the file you just saved & load it or add to your StartUp Suite to be loaded for each DWG.

Note that load will only install the routine for the current DWG & only for this session.

 

Look at the lisp file for (defun

the one above has this

(defun c:tjc(/ ss obj)

c: means you can run it from the command line by typing tjc

If the c: was missing like this

(defun tjc(/ ss obj)

You would need to enter (tjc) to run it.

 

Anyone seeing anything I left out please chime in.

 

HTH

Link to comment
Share on other sites

Anyone seeing anything I left out please chime in.

 

Great bit of advice, just a few pointers I might add if I may...

 

  • When saving the file in notepad or another Text Editor, make sure that the box "Save as Type" is set to "All Files", and use the extension ".lsp" when saving.

  • Alternatively to using the Start-up Suite, you could make a call to load the LISP from your ACADDOC.lsp which loads at every drawing session.

  • More help can be found here

 

HTH also,

 

Lee 8)

Link to comment
Share on other sites

Thanks Lee,

 

Also Note

 

If you want to use a file to automatically load a lisp I do not recommend using the ACAD.lsp file!

It may be over written any time you upgrade ACAD or re-install ACAD.

 

Use the ACADDOC.lsp like this:

First see if it exist by typing this at the command line

(findfile "acaddoc.lsp")

 

If it returns a path you should use your editor to add a line to it.

(load "AlansAutoLoad.lsp")

make up a file name for your system like (load "MyAutoLoad.lsp")

 

If the file does not exist then create one with your editor.

Add this

(load "MyAutoLoad.lsp")
(princ)

 

then save as ACADDOC.LSP making sure you save it in the ACAD search path.

 

Now create another file with your editor called MyAutoLoad.lsp

 

Add this to the file:

;;; ===============================================
;;;    Lisp Routine Loader
;;;    AUTOLOAD only loads the routine when needed
;;; ===============================================
;;;------  Lisp name -- Function name(s) -------  Discription  -----------------------
(AUTOLOAD "MyLispFileName" '("FunctionName")) ; comment what it does

(princ)
;;  End of file

 

Also save it to the ACAD search path.

 

Now each time your open a DWG the "MyLispFileName" routine will be loaded if you enter

FunctionName at the command line.

Link to comment
Share on other sites

This information should definitely be added to the FAQ at some point 8)

 

The article we have in there at the moment is somewhat brief...

http://www.cadtutor.net/faq/questions/53/How+do+I+automatically+load+variables%3F

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