Jump to content

Help lisp replace points to block + display text?


Recommended Posts

Posted

Hello everyone.
Can you help me create lisp replace points to block + display text?
If possible, add option - Input Height text:
spacer.png

test.dwg

Posted

Help you is a good question, far better than 'can you give me'

 

So I think you can select all the points with a selection set, using these lines:

  (princ "\nSelect Points: ")
  (setq MySS (ssget '((0 . "POINT")))) ; create a selection set, filtered only points

 

I reckon you can then loop through a selection set with:

 

  (setq acount 0)
  (while (< acount (sslength MySS)) ; loop through the selection set



    (setq acount (+ acount 1))
  )

 

(these 2 parts saves you looking online, copy and paste)

 

 

And in that loop you want to interrogate each item in the selection set to get it's insert point something like:

 

    (setq MyEnt (entget (ssname MySS acount))) ; get the entity definition of the nth point in the selection set
    (setq MyPt (cdr (assoc 10 MyEnt)))         ; get the insert point
    (setq MyX   (car MyPt))                    ; X
    (setq MyY  (cadr MyPt))                    ; Y
    (setq MyZ (caddr MyPt))                    ; Z

 

I added in X, Y, Z axis as separate lines

 

 

So is that enough to give you a start, put this together, and work out how to put the text in the insert point we found (perhaps using the MyX and MyY coordinate?), and use MyZ as the text to use. Note that MyZ is a number and you'll need to use RTOS to convert that to a string to use as text and I'd wait till after the loop and then delete the whole selection set in one go.

Posted

I'll drop this one here too, a LISP to create text - slightly quicker than (command "text" .....)

 

  (defun MakeText (MyString cons10 Ht / MyText )
    (entmakex (append (list (cons 0 "TEXT")
                            (cons 100 "AcDbEntity")
                            (cons 100 "AcDbText")
                            (cons 10 cons10)   ;; insert point
                            (cons 40 Ht)       ;; font height
                            (cons 7 "VNSIMLI") ;; font
                            (cons 71 0)        ;; for justification
                            (cons 72 1)        ;; for justification
                            (cons 11 cons10)   ;;justified insert point
                            (cons 73 0)        ;; for justification
                            (cons 1 MyString)  ;;text string
              ))
    )
  )

 

and an example following on from above to use it, this would go in the while loop after the (setq MyZ .....) line

 

(MakeText (rtos MyZ) (list MyX MyY) 2.5)

 

 

 

Right over to you, post what you make up and then can look at adding the doughnut blocks in too, 

Posted

So the basics for a LISP:

You need to define the LISP using something similar to this:

 

(defun c:test ( / )

.....

  (princ) ;; End quietly
)

 

where the ..... is where the LISP goes. defun means DEfine FUNction, the c : means it can run from the command line just with the next word, and test is the LISP name. You can call it anything you want, not just test (good practice not to use an existing command name though)

( / ) is where the variables are defined. Before the / is anything that is sent to the LISP from another, anything after is for local variables that are just used in that routine.

(princ.. writes messages to the command line, (princ) writes a blank line (ends quietly) and the ; is to comment out anything afterwards - the LISP won't read that.

 

 

To have a go at making up a LISP understand that they are quite easy and anyone can. Copy the highlighted section here into say, Notepad and save somewhere with a .lsp extension. First LISP made. Use appload in CAD to load that into the program and run by typing 'test' - it won't do much at the moment though.

 

Now make the LISP do stuff.

 

Work from the beginning of the hints I have given above and in order, replace the ..... dots above with the first 2 highlighted bits of code I hinted at above (which will be in your new LSP file).

 

Add in the next 5 lines (all starting with setq..... )in the 3rd box to replace ";... add in here doing stuff, for example the next highlighted box below" and you should be getting there.

 

Save your LSP file and then do the appload to load it into CAD, and try it again with test. Still won't do a lot until the next stages. Good to error check as you go. 

 

 

Have a go at this and post below what you make up - great way to learn having a go yourself. After that will work through creating the text as in the 4th and 5th snippets of code I suggested.

 

Posted

Here you go. :)

(defun c:Test (/ hgt int sel ent get ins)
  ;;----------------------------------------------------;;
  ;;	Author : Tharwat Al Choufi			;;
  ;; website: https://autolispprograms.wordpress.com	;;
  ;;----------------------------------------------------;;
  (and (setq hgt (getdist "\nSpecify text height : "))
       (princ "\nSelect points to replace with texts : ")
       (setq int -1
             sel (ssget "_:L" '((0 . "POINT")))
       )
       (while (setq int (1+ int)
                    ent (ssname sel int)
              )
         (and (setq get (entget ent)
                    ins (assoc 10 get)
              )
              (entmake (list '(0 . "TEXT")
                             ins
                             (cons 40 hgt)
                             (cons 1 (rtos (caddr (cdr ins)) 2 2))
                             (cons 7 (getvar 'TEXTSTYLE))
                             '(71 . 0)
                             '(72 . 1)
                             (cons 11 (cdr ins))
                             '(73 . 0)
                       )
              )
              (entdel ent)
         )
       )
  )
  (princ)
)

 

  • Like 1
Posted

Thank you so much. 

Posted
7 hours ago, tuantrinhdp said:

Thank you so much. 

You're most welcome, happy to help. 

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