Pick instead of typing in text for use in existing Lisp routine.

Pick instead of typing in text for use in existing Lisp routine.

dlbsurveysuk
Collaborator Collaborator
460 Views
4 Replies
Message 1 of 5

Pick instead of typing in text for use in existing Lisp routine.

dlbsurveysuk
Collaborator
Collaborator

Hi,

I generally have drawings with a cross marking a tree position and a line of text denoting the trunk girth, spread, height, and species.

 

The text is formatted as "tr-sp-h-spe" eg. "0.12-3.40-5.0-OAK"

 

I can then use the following Lisp routine to type in the tree information which will then draw a scaled tree with formatted info.

 

(defun c:tree ()

   (command "osnap" "INSERT")

      (setq xy (getpoint "Where? "))

         (setq tr (getreal "Girth? "))
         (setq sp (getreal "Spread? "))
         (setq h (getreal "Height? "))
         (setq spe (getstring "Species? "))

     (command "osnap" "none")


                 (command "LAYER" "M" "TRTEXT" "")
                 (setq txy (polar xy 0.4636 0.894))

                    (command "TEXT" txy "" "" spe)
                    (command "TEXT" "" (strcat "G "(rtos tr 2 2)))
                    (command "TEXT" "" (strcat "S "(rtos sp 2 1)))
                    (command "TEXT" "" (strcat "H "(rtos h  2 0)))

                 (command "LAYER" "M" "TRTR" "")

                    (command "INSERT" "treebole" xy (/ tr PI) "" "" "")

                 (command "LAYER" "M" "TRCAN" "")

                    (command "INSERT" "trcan" xy sp "" "" "")
)


I'd like to be able to pick the position and then pick the text (instead of typing in all the info).

 

I know the text could be split into a list using the "-" as a delimiter, and that the numerical text could be converted to real numbers using "atof" which could then be used in the above routine instead of the "getreal" commands.

 

Problem is that my Lisp skills aren't up to actually writing the code...

 

Any help would be appreciated.
Thanks.

0 Likes
Accepted solutions (1)
461 Views
4 Replies
Replies (4)
Message 2 of 5

hak_vz
Advisor
Advisor

@dlbsurveysuk 

Something like this? This create text entity, you can modify this according to your needs.

 

(defun c:pjp (/ pick_text pt new_text i e eo sequence)
	(defun pick_text(msg / e)
		(setq e (car(entsel msg)))
		(if (and (not e) (= (getvar 'Errno) 7)) (pick_text msg) e)
	)
	(setq
		pt (getpoint "\nPick joined text position >")
		new_text ""
		i -1
		sequence '("\nSpecies? " "\nGirth? " "\nSpread? " "\nHeight? " )
	)
	(while  (and (< (setq i (1+ i)) (length sequence))(setq e (pick_text (nth i sequence))))
		(setq eo (vlax-ename->vla-object e))
		(cond 
			((vlax-property-available-p eo 'TextString)
				(setq new_text (strcat new_text (vlax-get eo 'TextString) "-"))
			)
		) 
	)
	(entmake
		(list
			(cons 0 "TEXT")
			(cons 100 "AcDbText")
			(cons 10 pt)
			(cons 8 "TRTEXT")
			(cons 40 (getvar 'TextSize))
			(cons 1 (substr new_text 1 (1- (strlen new_text))))
			(cons 50 0)
		)
	)
	(princ)
)

 

 

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 3 of 5

ВeekeeCZ
Consultant
Consultant
Accepted solution

Possibly like this:

 

(defun c:tree ()
  
  ;; String to List  -  Lee Mac  ;; http://www.lee-mac.com/stringtolist.html
  ;; Separates a string using a given delimiter
  ;; str - [str] String to process
  ;; del - [str] Delimiter by which to separate the string
  ;; Returns: [lst] List of strings
  
  (defun LM:str->lst ( str del / pos )
    (if (setq pos (vl-string-search del str))
      (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
      (list str)))
  
  (command "osnap" "INSERT")
  (setq xy (getpoint "Where? "))
  
  (setq en (car (entsel "Pick a spec: ")))
  (setq lst (LM:str->lst (cdr (assoc 1 (entget en))) "-"))
  
  ;;;  (setq tr (getreal "Girth? "))
  ;;;  (setq sp (getreal "Spread? "))
  ;;;  (setq h (getreal "Height? "))
  ;;;  (setq spe (getstring "Species? "))
  
  (setq tr (atof (car lst)))
  (setq sp (atof (cadr lst)))
  (setq h (atof (caddr lst)))
  (setq spe (last lst))
  
  (command "osnap" "none")
  
  
  (command "LAYER" "M" "TRTEXT" "")
  (setq txy (polar xy 0.4636 0.894))
  
  (command "TEXT" txy "" "" spe)
  (command "TEXT" "" (strcat "G "(rtos tr 2 2)))
  (command "TEXT" "" (strcat "S "(rtos sp 2 1)))
  (command "TEXT" "" (strcat "H "(rtos h  2 0)))
  
  (command "LAYER" "M" "TRTR" "")
  
  (command "INSERT" "treebole" xy (/ tr PI) "" "" "")
  
  (command "LAYER" "M" "TRCAN" "")
  
  (command "INSERT" "trcan" xy sp "" "" "")
  )

 

Message 4 of 5

Sea-Haven
Mentor
Mentor

if you use a dynamic block rather than insert 2 blocks for trunk and spread, mine have a circle for trunk and spread a pattern, as they are 2 objects can be scaled seperately. I have something for CIV3D not plain text. Adding to BeekeeCZ code would be worthwhile. Make Dynamic blocks FIR OAK PINE etc. Maybe even play with visibilty so 1 block with various patterns.

 

 

Message 5 of 5

dlbsurveysuk
Collaborator
Collaborator

Thanks works perfectly. I forgot to mention I'd already looked at Lee Mac's string to list routine but for some reason I couldn't see how to implement it. Now that you've done it for me I can see exactly how it all works. Thanks again.

0 Likes