Author Topic: Calling 2 Lisps in sequnce via macro  (Read 3342 times)

0 Members and 1 Guest are viewing this topic.

steve.carson

  • Newt
  • Posts: 108
Re: Calling 2 Lisps in sequnce via macro
« Reply #15 on: October 05, 2016, 11:49:07 AM »
You added the (setq oobj) again. You don't need that.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Calling 2 Lisps in sequnce via macro
« Reply #16 on: October 05, 2016, 11:54:31 AM »
Sorry for the frustrations...

Code: [Select]

(defun C:NewFunc ( / )

;;;;https://www.theswamp.org/index.php?topic=52095.0


(mt2ml (t2mt))

)


(defun mt2ml (oobj / nobj nstrg)

;;;;https://autocadtips1.com/2012/03/12/add-leader-to-text-make-multileader/

  (vl-load-com)

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



;;; AUTHOR
;;; Copyright© 2010 Ron Perez (ronperez@gmail.com)
;;; 11.02.2010 added grouping text by X values
;;;; http://www.theswamp.org/index.php?topic=35382.msg407916#msg407916
(defun t2mt (/   rjp-removextraspaces rjp-ent2obj       rjp-getbbwdth
       rjp-getbbtlc      rjp-dxf d    doc       elst hgt
       i   n      nxt obj    otxt       out pt
       ss   txt      w x    x_sort     y
      )
  (defun rjp-removextraspaces (txt)
    (while (vl-string-search "  " txt) (setq txt (vl-string-subst " " "  " txt)))
    txt
  )
  (defun rjp-ent2obj (ent)
    (if (= (type ent) 'ename)
      (vlax-ename->vla-object ent)
      ent
    )
  )
  (defun rjp-dxf (code ent)
    (if (and ent (= (type ent) 'ename))
      (cdr (assoc code (entget ent)))
    )
  )
  (defun rjp-getbb (ent / ll ur)
    (vla-getboundingbox (rjp-ent2obj ent) 'll 'ur)
    (mapcar 'vlax-safearray->list (list ll ur))
  )
  (defun rjp-getbbwdth (ent / out)
    (setq out (mapcar 'car (rjp-getbb (rjp-ent2obj ent))))
    (abs (- (car out) (cadr out)))
  )
  (defun rjp-getbbtlc (ent / out)
    (setq out (rjp-getbb (rjp-ent2obj ent)))
    (list (caar out) (cadr (last out)) 0.0)
  )
  (if (and (setq ss (ssget ":L" (list '(0 . "text"))))
   (setq doc (vla-get-activedocument (vlax-get-acad-object)))
   ;;list as X Y TEXT ENAME
   (setq elst (mapcar '(lambda (x)
(list (car (rjp-dxf 10 x))
       (cadr (rjp-dxf 10 x))
       (strcat (rjp-removextraspaces (rjp-dxf 1 x)) " ")
       x
)
       )
      (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      )
   )
      )
    (progn
      ;;Sort top to bottom
      (setq elst (vl-sort elst '(lambda (y1 y2) (> (cadr y1) (cadr y2)))))
      ;;Group by x values using text height as fuzz value
      (while (setq i (car elst))
(setq y (vl-remove-if-not '(lambda (x) (equal (car i) (car x) (rjp-dxf 40 (last i)))) elst))
(mapcar '(lambda (x) (setq elst (vl-remove x elst))) y)
(setq x_sort (cons y x_sort))
      )
      (foreach item x_sort
(setq ;;Get widest piece of text to set mtext width
      w    (* 1.0125 (car (vl-sort (mapcar 'rjp-getbbwdth (mapcar 'last item)) '>)))
      hgt  (rjp-dxf 40 (last (car item)))
      pt   (rjp-getbbtlc (last (car item)))
      ;;Grab top text to pull properties from
      otxt (vlax-ename->vla-object (last (car item)))
)
;;Puts hard returns for text spaced greater than (* 2. hgt)
(setq n 0)
(foreach x item
  (if (setq nxt (nth (setq n (1+ n)) item))
    (if (>= (setq d (abs (- (cadr x) (cadr nxt)))) (* 2. hgt))
      (setq out (cons (strcat (caddr x) "\\P\\P") out))
      (setq out (cons (caddr x) out))
    )
    (setq out (cons (caddr x) out))
  )
)
;;Join the text into one string
(setq txt (apply 'strcat (reverse out)))
;;Insert mtext
(setq obj (vla-addmtext
    (if (= (getvar 'cvport) 1)
      (vla-get-paperspace doc)
      (vla-get-modelspace doc)
    )
    (vlax-3d-point pt)
    w
    txt
  )
      txt nil
      out nil
)
;;Match properties from top text object
(vla-put-height obj (vla-get-height otxt))
(vla-put-attachmentpoint obj actopleft)
(vlax-put obj 'insertionpoint pt)
(vla-put-rotation obj 0.0)
(vla-put-layer obj (vla-get-layer otxt))
(vla-put-stylename obj (vla-get-stylename otxt))
;;Delete selected single line text
(mapcar 'entdel (mapcar 'last item))
      )
    )
  )
  obj
)

Civil3D 2020

steve.carson

  • Newt
  • Posts: 108
Re: Calling 2 Lisps in sequnce via macro
« Reply #17 on: October 05, 2016, 11:56:51 AM »
No worries. Is it working the way you want it to?

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Calling 2 Lisps in sequnce via macro
« Reply #18 on: October 05, 2016, 12:00:49 PM »
WOO HOOO! I did it! well, with your help.
Civil3D 2020

steve.carson

  • Newt
  • Posts: 108
Re: Calling 2 Lisps in sequnce via macro
« Reply #19 on: October 05, 2016, 12:01:51 PM »
That's great! Glad to help!

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Calling 2 Lisps in sequnce via macro
« Reply #20 on: October 05, 2016, 12:03:25 PM »
I might have some others in the future. But at least I have a better idea how to tie these together.
Civil3D 2020