Jump to content

text insert point


leventdal

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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:

 
(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:

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

Link to comment
Share on other sites

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:

 

 

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.

Link to comment
Share on other sites

  • 1 year later...

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 !

Link to comment
Share on other sites

Try this:

 

(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))

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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

 

(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))


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