Author Topic: Adding a get function  (Read 399 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Water Moccasin
  • Posts: 2343
  • I can't remeber what I already asked! I need help!
Adding a get function
« on: September 12, 2018, 07:24:58 AM »
Rod was nice enough to setup a routine that I could use within Civil3D General Note Label. Basically, you set your own style and then pick a spot then type in what you would like the routine to say.

Code: [Select]
(defun note (point text)
  (command "addnotelabel" point "")
  (setq obj (vlax-ename->vla-object (entlast)))
  (vlax-put-property obj 'LabelTextContent text)
  )

(defun C:test ()
  (note (getpoint "\nPick a point")(getstring "\nEnter text"))
  )

Im trying to figure out how to add a get function with either text or mtext. Take that value and place within the general label style.

I have an example that is similar in taking text to a MLeader that I have been messing with, but still trying to get the values to work. So I figured Id ask.

Code: [Select]
(defun c:mt2ml ( / oobj nobj nstrg)
  (vl-load-com)
(command ".cmleaderstyle" "L80 Leader Text Straight")
  (setq oobj (vlax-ename->vla-object (car (nentsel "\nSelect source text: "))))
  (if (= (vlax-get-property oobj 'ObjectName) "AcDbMText")
    (setq nstrg (vlax-get-property oobj 'TextString))
    (exit)    
    )
  (command "_MLEADER")
  (while (= 1 (logand (getvar "CMDACTIVE") 1)) (command PAUSE))
  (setq nobj (vlax-ename->vla-object (entlast)))
  (if (= (vlax-get-property nobj 'ObjectName) "AcDbMLeader")
    (vlax-put-property nobj 'TextString nstrg)
    (exit)    
    )
  (entdel (vlax-vla-object->ename oobj))
  (princ)
); defun


Thank you for any direction!
Autodesk Infrastructure Design Suite 2018

Rod

  • Newt
  • Posts: 106
Re: Adding a get function
« Reply #1 on: September 12, 2018, 06:42:39 PM »
My code shows that this can be done. It was a quick test only.

A couple of weeks ago I had some time to do some lisp writing and was working on an Object Data to Property Set Converter and some labelling functions.
Similar to some posts MSTG007 was asking about.

A rebuilt computer and compliance audit later my projects have pilled up again.

I hoping to get back my lisp projects soon. Hope someone can help you in the meantime.

Cheers, Rod
Standing on the toes of giants.

BIGAL

  • Bull Frog
  • Posts: 225
  • 30 + years of using Autocad
Re: Adding a get function
« Reply #2 on: September 13, 2018, 07:24:51 AM »
Try this note uses ssget with filter so can only pick  text or mtext

Code: [Select]
(setq ss (ssget (list (cons 0 "*text"))))
(if (/= ss nil)
    (setq nstrg (vlax-get-property (vlax-ename->vla-object (ssname ss 0)) 'TextString))
    (progn (alert "You did not pick a text element\npress ok program will exit") (exit)
)
A man who never made a mistake never made anything

BIGAL

  • Bull Frog
  • Posts: 225
  • 30 + years of using Autocad
Re: Adding a get function
« Reply #3 on: September 14, 2018, 06:16:51 PM »
You need to change the code

Code: [Select]
(setq oobj (vlax-ename->vla-object (car (nentsel "\nSelect source text: "))))
  (if (= (vlax-get-property oobj 'ObjectName) "AcDbMText")
    (setq nstrg (vlax-get-property oobj 'TextString))
    (exit)    
    )

(setq ss (ssget (list (cons 0 "*text"))))
(if (/= ss nil)
    (setq nstrg (vlax-get-property (vlax-ename->vla-object (ssname ss 0)) 'TextString))
    (exit)
)
A man who never made a mistake never made anything

Rod

  • Newt
  • Posts: 106
Re: Adding a get function
« Reply #4 on: January 09, 2019, 06:50:10 PM »
Had to convert some text to general notes today.
Made this
beware rough and ready
Code - Auto/Visual Lisp: [Select]
  1. (defun C:t2n (/ ss1 i pt str)
  2.  (setq ss1 (ssget (list (cons 0 "*TEXT"))))
  3.  (setq i 0)
  4.  (if ss1
  5.    (repeat (sslength ss1)
  6.      (setq en (ssname ss1 i))
  7.      (setq str (vlax-get-property (vlax-ename->vla-object en) 'TextString))
  8.      (setq pt (cdr (assoc 10 (entget en))))
  9.      (makeNote pt str)
  10.      (setq i (1+ i))
  11.    ) ;_ end of repeat
  12.  ) ;_ end of if
  13. ) ;_ end of defun
  14.  
  15. (defun makeNote (pt str / obj)
  16.  (command "addnotelabel" pt "")
  17.  (setq obj (vlax-ename->vla-object (entlast)))
  18.  (vlax-put-property obj 'LabelTextContent str)
  19. ) ;_ end of defun
Standing on the toes of giants.