+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 21
  1. #1
    Senior Member
    Discipline
    Manufacture
    BrianTFC's Discipline Details
    Occupation
    Structral Detailer
    Discipline
    Manufacture
    Using
    AutoCAD 2017
    Join Date
    Jan 2012
    Location
    Indiana
    Posts
    158

    AutoCAD How do I center the text in the rectangle and repeat the last input?

    Registered forum members do not see this ad.

    Hi All,

    I'm having a little trouble figuring out how to center my text in the middle of the rectangle after its created. Here's what I have so far, it works but it waits for me to place it. Also I do a lot of panels that are the same size so I also want the lisp to remember the last input so I can continue to use it until I hit escape or return.
    If I could get some help I would appreciate it.

    Code:
    (defun C:CRP7()
      (setq cmdold (getvar "cmdecho"))
      (setvar "cmdecho" 0)
      (setq PL (getstring "Enter a Panel Label :"))
      (setq PA (getpoint "Select Panel Area :"))
      (command "-boundary" "Advanced" "Island" "No" "Nearest" "" pa "")
      (command "_.change" (entlast) "" "_p" "_la" "Router - Green - V groove" "")
      
      (setq ts(getvar "textsize"))
      (setq tsty(getvar "textstyle"))
      
      (if(= 0 (cdr(assoc 40(tblsearch "style" tsty))))
            (progn
        
      (command "text" "Justify" "Center" pa ts 0 PL)))
      (setvar "cmdecho" cmdold)
         
      (princ)
     )
    Thanks Brian

  2. #2
    Super Member hmsilva's Avatar
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2016
    Join Date
    Dec 2012
    Location
    Cascais, Portugal
    Posts
    531

    Default

    Hi Brian,

    if you are not using AutoCAD 2015, try the following program.
    The 'bpoly' function, is generating an error in AC2015, (not sure why)...
    Change the default prompt "123" to a panel size.
    Code:
    (vl-load-com)
    (defun c:demo ( / adoc bp cen lays msp pa pl plo reg sfa txt)
      (setq adoc (vla-get-activedocument (vlax-get-acad-object))
            msp (vla-get-modelspace adoc)
            lays (vla-get-layers adoc)
        )
      (vla-add lays "Router - Green - V groove")
      (while (and (setq pa (getpoint "\n Select Panel Area: "))
                  (setq pl (getstring (strcat "\nEnter a Panel Label <" (cond (*pl) ("123")) ">: "))
                        *pl (cond ((/= pl "") (strcase pl)) (*pl) ("123"))
                        )
                  (setq bp (bpoly pa))
                  )
          (setq plo (vlax-ename->vla-object bp)
                sfa (vlax-make-safearray vlax-vbObject '(0 . 0))
          )
          (vla-put-layer plo "Router - Green - V groove")
          (vlax-safearray-put-element sfa 0 plo)
          (setq reg (car (vlax-safearray->list (vlax-variant-value (vla-addregion msp sfa))))
                cen (vlax-get reg 'centroid)
                )
          (vla-delete reg)
          (setq txt (vla-AddText msp *pl (vlax-3D-point (trans cen 1 0)) (getvar 'TEXTSIZE)))
          (vla-put-alignment txt 10)
          (vla-put-textalignmentpoint txt (vlax-3D-point (trans cen 1 0)))
          (vla-put-rotation txt (angle (list 0 0)(getvar 'UCSXDIR)))
        )
      (princ)
      )
    Hope that helps
    Henrique
    Last edited by hmsilva; 17th Feb 2015 at 12:04 pm. Reason: Code revised

  3. #3
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,892

    Default

    Perhaps an alternative method if you entlast the bpoly then get 'coordinates then middle of 1st and 3rd is center point.

    Code:
    (defun getcoords (ent)
      (vlax-safearray->list
        (vlax-variant-value
          (vlax-get-property
        (vlax-ename->vla-object ent)
        "Coordinates"
          )
        )
      )
    )
     
    (defun co-ords2xy ()
    ; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
    (setq numb (/ (length co-ords) 2))
    (setq I 0)
    (repeat numb
    (setq xy (list (nth (+ I 1) co-ords)(nth I co-ords) ))
    (setq coordsxy (cons xy coordsxy))
    (setq I (+ I 2))
    ) ; end repeat
    )
     
    (setq co-ords (getcoords (entlast)))
    A man who never made mistakes never made anything

  4. #4
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,085

    Default

    @ Henrique

    Don't you think with me that it is better to move the functions to a separate sub-function to get the Activedocument , ModelSpace , Layers collection then Adding a new layer out of the loop of the while function ?

    Regards

  5. #5
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,892

    Default

    Like Tharwat you will see in my code 2 defuns because I have 1 in my library lisp for std stuff that I use all the time. My post about civ3d lables opens the Aec database only defun in new code. Same Getval nice dcl for input. Its got to the stage where I need to go through all code and standardise.
    A man who never made mistakes never made anything

  6. #6
    Super Member hmsilva's Avatar
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2016
    Join Date
    Dec 2012
    Location
    Cascais, Portugal
    Posts
    531

    Default

    Quote Originally Posted by Tharwat View Post
    @ Henrique
    Don't you think with me that it is better to move the functions to a separate sub-function to get the Activedocument , ModelSpace , Layers collection then Adding a new layer out of the loop of the while function ?
    Regards
    Hi Tharwat,

    of course you're right!

    The code at #3 was written with an 'if' function, when posted, I saw that the OP wanted the code in a loop, and I modified it (quick and dirty) to a 'while'...

    My primary goal was, trying to demonstrate to OP an alternative method, and above all, trying to pass the idea that we should validate the return data from a function, before submit that data to another function/command.

    Code in message #3 revised.

    Cheers
    Henrique

  7. #7
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,085

    Default

    Quote Originally Posted by hmsilva View Post
    The code at #3 was written with an 'if' function, when posted, I saw that the OP wanted the code in a loop, and I modified it (quick and dirty) to a 'while'...
    Undoubtedly it's nice

  8. #8
    Full Member
    Using
    AutoCAD 2013
    Join Date
    Oct 2014
    Posts
    63

    Default

    Hi

    please find the attached lisp.

    This is from lee mac.
    it's work fine

    thanks
    yathishkumar
    Attached Files

  9. #9
    Super Member hmsilva's Avatar
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2016
    Join Date
    Dec 2012
    Location
    Cascais, Portugal
    Posts
    531

    Default

    Quote Originally Posted by Tharwat View Post
    Undoubtedly it's nice
    Thank you Tharwat!

  10. #10
    Senior Member
    Discipline
    Manufacture
    BrianTFC's Discipline Details
    Occupation
    Structral Detailer
    Discipline
    Manufacture
    Using
    AutoCAD 2017
    Join Date
    Jan 2012
    Location
    Indiana
    Posts
    158

    Default

    Registered forum members do not see this ad.

    Henrique,

    I'm using AutoCAD 2015, I just haven't gotten a chance to update my info on here. so how do we fix this?

    Thanks
    Brian

Similar Threads

  1. Repeat user input until value is true
    By Andrew1979 in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 3rd Dec 2014, 02:00 pm
  2. How to center-align a rectangle to a group/block?
    By BWCAD in forum AutoCAD Beginners' Area
    Replies: 7
    Last Post: 9th Nov 2012, 06:55 am
  3. Make a rectangle centered around center point?
    By kingneptune117 in forum AutoCAD Beginners' Area
    Replies: 16
    Last Post: 21st Jun 2012, 05:38 pm
  4. how do I repeat last input
    By mfranke in forum AutoCAD General
    Replies: 8
    Last Post: 23rd Nov 2007, 07:56 pm
  5. Need lisp to Align text to middle center of a box/rectangle?
    By Ste1978 in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 21st Nov 2007, 03:56 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts