+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    Feb 2008
    Posts
    2

    Default text insert point

    Registered forum members do not see this ad.

    Hi,

    This is my first post in this forum. And as you'll notice I am a beginner to AutoCAD macros. I have worked with Excel macros for quite a while.

    But with AutoCAD it's all different.

    I couldn't find a reference help for macros. (object model, methods, collections, etc; such CHM files are present for Excel, Word,...)

    So I can't even get the coordinates of a dot.

    I am trying to insert "dot" elements at exactly the same coordinates (x, y, z) with all of the existing "text" elements.


    Any help on this routine and general help, resources for a beginner would be highly appreciated.

    Thanks in advance.

  2. #2
    Senior Member
    Using
    Inventor 2012
    Join Date
    May 2007
    Posts
    215

    Default

    i've found that if you install the acad help files when you install the base program, there are LOTS of helpful tips and resource help files...

    as for your particular problem, i can't help there... i'm a macro newbie too...

  3. #3
    Super Moderator fuccaro's Avatar
    Using
    AutoCAD 2006
    Join Date
    Nov 2002
    Location
    Romania, Marosvasarhely
    Posts
    3,543

    Default

    Hello leventdal and welcome in the forum!
    You are right, the AutoCAD customisation is not like Excel.
    What you ask is easy to acomplish using a small Lisp routine.
    First of all, grab together in a selection set all the TEXT entities in the drawing:
    Code:
     
    (setq ss (ssget "X" (list '(0 . "TEXT"))))
    Now go trough the selection set and for each text entitie extract the insert point coords, wich are stored in the list following the number 10 in the entitie list.
    Finaly, create an AutoCAD point at those coords.
    See here my solution:
    Code:
    (defun c:test()
      (setq ss (ssget "X" (list '(0 . "TEXT"))))
      (repeat (setq i (sslength ss))
        (setq tx1 (ssname ss (setq i (1- i)))
       a10 (assoc 10 (entget tx1))
       poi (list '(0 . "POINT") a10)
       )
        (entmake poi)
        )
      )
    Don't be afraid if you can't use Lisp routines; click here: http://www.cadtutor.net/forum/showthread.php?t=1390

    I renamed this thread. Please in the future use relevant names.
    It's nice to be nice, but sometimes is nicer to be evil!.
    Tip: Please do not PM or email me with CAD questions - use the forums, you'll get an answer sooner.

  4. #4
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    Feb 2008
    Posts
    2

    Default

    Thanks for the quick responses.

    I couldn't reply to the post earlier due to heavy workload.

    First of all after Hickoz_bro's advice, I checked the installation disk for CHM files which I couldn't find before.
    There is one called acadauto.chm

    Very useful information about using Visual Basic for macros.

    fuccaro, thanks for the code. But I have no LISP knowledge so for now I'll stick with VB.

    Here's what I learnt so far:

    Code:
     
     
    nObjects = Application.ActiveDocument.ModelSpace.Count 'Gets number of objects.
     
    Application.ActiveDocument.ModelSpace.Item(i) ' returns the object i in the model space
    'You can get  many of the object properties through this line
     
    Application.ActiveDocument.ModelSpace.Item(i).GetBoundingBox minExt, maxExt 'gets the max min coordinates of an object.
     
    Set oAcadPoint = ThisDrawing.ModelSpace.AddPoint(Point) 'creates a point referenced by oAcadPOint
    Used them with some "for" statements.
    That's all I needed for now.

    Thanks again for the help.
    Last edited by leventdal; 1st Mar 2008 at 07:43 pm.

  5. #5
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    Feb 2010
    Location
    Constanta, Romania
    Posts
    4

    Default

    Hello and sorry for bump-ing an old thread - i`m kinda new in lisp programming so here i go askin` for some help:
    I have some text elements that are 2d (x and y values) and i need to insert "dot" with the values from text - till now fuccaro`s lisp will do fine ...but, i also need to insert in "dot" the z value that is written in text value box !
    So ...i need to read the text value box in the z value box and then fucaro`s lisp will take care of rest.
    Thanks in advance !

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,882

    Default

    Try this:

    Code:
    (defun c:txt2pt (/ Point i ss ent pt)
    
      (defun Point (pt) (entmakex (list (cons 0 "POINT") (cons 10 pt))))
    
      (if (setq i -1 ss (ssget '((0 . "TEXT,MTEXT"))))
        (while (setq ent (ssname ss (setq i (1+ i))))
          (setq pt (cdr (assoc 10 (entget ent))))
    
          (Point (list (car pt) (cadr pt)
                       (cond ((distof (cdr (assoc 1 (entget ent))))) (0.0))))))
    
      (princ))
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  7. #7
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    Feb 2010
    Location
    Constanta, Romania
    Posts
    4

    Default

    That was quick ! and ... IT WORKS !!! Thanks, Lee Mac

  8. #8
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,882

    Default

    Quote Originally Posted by ERDOS View Post
    That was quick ! and ... IT WORKS !!! Thanks, Lee Mac

    You're welcome
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  9. #9
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    Feb 2010
    Location
    Constanta, Romania
    Posts
    4

    Default

    also, while keeping myself busy with LeeMac lisp (thanks again), i noticed that some of the text is xxxx and i need it to be x.xxx - can i select all my xxxx text and divide by 1000 ?

  10. #10
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,882

    Default

    Registered forum members do not see this ad.

    This should account for non-numerical text being selected too:

    Code:
    (defun c:txtby1000 (/ i ss ent num str elst)
    
      (if (setq i -1 ss (ssget '((0 . "TEXT,MTEXT"))))
        (while (setq ent (ssname ss (setq i (1+ i))))
          (setq num (distof (setq str (cdr (assoc 1 (setq elst (entget ent)))))))
          (entmod
            (subst
              (cons 1 (if num (rtos (/ num 1000.)) str)) (assoc 1 eLst) eLst))))
    
      (princ))
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. Changing the centre point of a block upon insert
    By edgley in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 9
    Last Post: 11th Feb 2008, 09:30 am
  2. Insert/Copy w/base point not working
    By brassworks in forum AutoCAD Drawing Management & Output
    Replies: 13
    Last Post: 14th Dec 2007, 07:15 pm
  3. ...add a line of text to insert into a lisp...
    By Gar in forum AutoCAD General
    Replies: 1
    Last Post: 19th Dec 2006, 06:56 pm
  4. I need insert text with position x y (E,N)
    By afritis in forum AutoCAD Drawing Management & Output
    Replies: 1
    Last Post: 23rd Jul 2006, 11:56 pm
  5. Insert Text String
    By Bass'nBoots in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 21st Oct 2005, 06:32 pm

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