LISP to match x cordinates of two objects (usually mtext) / Help me to turn this code from "text" to "mtext"

LISP to match x cordinates of two objects (usually mtext) / Help me to turn this code from "text" to "mtext"

anton.chmidtMDYV8
Participant Participant
452 Views
4 Replies
Message 1 of 5

LISP to match x cordinates of two objects (usually mtext) / Help me to turn this code from "text" to "mtext"

anton.chmidtMDYV8
Participant
Participant
; Function to transfer the rotation of a selected text and the maximum x value to selected text

(defun C:Max (/ lstAreas 
                lstInsertion
                lstInsertions
                lstObjects 
                lstSelections 
                objSource 
                sngMax 
                sngRotation 
                ssSelections)
 (if (and
      (print "Select Source Text first and text to change after: ")
      (setq ssSelections  (ssget  (list (cons 0 "text"))))
      (setq lstSelections (SelectionSetToList ssSelections))
      (setq lstObjects    (mapcar 'vlax-ename->vla-object lstSelections))
      (setq objSource     (car lstObjects))
      (setq sngRotation   (vla-get-rotation objSource))
      (setq lstObjects    (cdr lstObjects))
      (setq lstInsertions (mapcar '(lambda (X)(vlax-get X "insertionpoint")) lstObjects))
      (print (length lstObjects))
      (setq lstInsertion  (vlax-get objSource "insertionpoint"))
      (setq sngMax        (car lstInsertion))
      ;(setq sngMax       (apply 'max (mapcar 'car lstInsertions)))

     )
  (apply 'and (mapcar '(lambda (X)(textfix X sngRotation (list sngMax nil nil))) lstObjects))
 )
)

; Function to change the rotation and set the x coordinate to be a specified value

(defun TextFix (objText sngRotation lstMaximas / lstInsertion)
 (and
  (errortrap (quote (vla-put-rotation objText sngRotation))) 
  (setq lstInsertion (vlax-get objText "insertionpoint"))
  (setq lstInsertion (mapcar 'OrValue lstMaximas lstInsertion))
  (errortrap (quote (vlax-put objText "insertionpoint" lstInsertion)))
 )
)

; Function for substituting a value for a nil in a pair of lists

(defun OrValue (sngValue1 sngValue2)
 (if sngValue1 sngValue1 sngValue2)
)

;Function to convert a lisp selection set into a list of entities

(defun SelectionSetToList (ssSelections / intCount entSelection lstSelections)
 (repeat (setq intCount (sslength ssSelections))
  (and
   (setq intCount      (1- intCount))  
   (setq entSelection  (ssname ssSelections intCount))
   (setq lstSelections (cons entSelection lstSelections))  
  )
 )
 lstSelections
)

; Function to trap lisp errors

(defun ErrorTrap (symFunction / objError result)
 (if (vl-catch-all-error-p
      (setq objError (vl-catch-all-apply
                     '(lambda (X)(set X (eval symFunction)))
                      (list 'result))))
  nil
  (if result result 'T)
 )
)


(vl-load-com)

 

I found a list from AUGI forum that matches x cordinates of two texts, is it possible at least to also work with mtext? if it would work with things like blocks, circles, etc. would be great too. 

Also next I would need a MAY lisp to do the same for Y cordinates. 

 

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

calderg1000
Mentor
Mentor
Accepted solution

Regards @anton.chmidtMDYV8 

To align text and mtext, change text to *text

 

(if (and
      (print "Select Source Text first and text to change after: ")
      (setq ssSelections  (ssget  (list (cons 0 "*text"))));;On this line, include the indicated change.
      (setq lstSelections (SelectionSetToList ssSelections))

 

 


Carlos Calderon G
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.

0 Likes
Message 3 of 5

anton.chmidtMDYV8
Participant
Participant

Thank you, working perfectly. 

How hard this would be to change to y-axel?

0 Likes
Message 4 of 5

Sea-Haven
Mentor
Mentor

Looking at code if you get a insertionpoint the (car is X & (cadr is Y

0 Likes
Message 5 of 5

anton.chmidtMDYV8
Participant
Participant

Coundt get it to work just yet, what about set?

 

(setq lstObjects (cdr lstObjects))

0 Likes