PDA

View Full Version : Match text coordinate and rotation



Arterius
2015-02-06, 10:15 AM
Dear all,

I would like to ask for your help. I would like to match text by X or Y coordinates and text rotation.
I have a lot of texts (not mtext) in autocad drawing with differernt rotation and coordinates, I need to match one text with proper another texts, another text with another proper textes and so on... It's not like selecting all and typing rotation angle and X or Y coordinate in properties for all... I wish...

I imagine it works like this: run lisp (for eg. command: 'maX' for X coordinate and 'maY' for Y), select sourse text and select target text.
Routine matches by one coordinate and rotation.

Thanks in advane for any help...

Regards.

Tom Beauford
2015-02-06, 11:34 AM
Are you looking for a text stacking routine where you select the first text the all other selections are placed on lines below it?

peter
2015-02-06, 05:48 PM
I would like to understand your question better...

Can you write a flow chart list (series of steps) for your routine?

Like...

Flow Chart List
Select source text object
Get insertion point and rotation
Select target text object
Change X or Y coordinate of target text to match source text
(Q: How do you decide which coordinate to match?)
(Q:Is this to align text with other text objects?)
Change rotation of target text to match source

P=

Arterius
2015-02-09, 10:02 AM
Hi,

sorry for my not clear english :)

(Q: How do you decide which coordinate to match?)
different commands

(Q:Is this to align text with other text objects?)
yes, it is.

Change rotation of target text to match source
That's right.

Steps:
1) type command to run lisp: eg. MAX ('MA' - match, 'X' - x coordinate)
2) select source text (information needed: text rotation, X cordinate)
3) select target texts
4) ENTER (as finish :) )

Result:
1. Source text - stays as was.
2. Target texts - the same text rotation and X (or Y - according to selectect option "MAX" or "MAY" commands) coordinate as source text.

The same steps for Y coordinates, about different command, eg. MAY.

Thanks in advance.

Arterius
2015-02-09, 10:05 AM
Are you looking for a text stacking routine where you select the first text the all other selections are placed on lines below it?

Something like this, but my target texts are placed not only below, but also over, on right or left, depends which coordinate I want to match... for X cordinate, all target texts will be over or below, for Y - on the right or left...

peter
2015-02-17, 11:38 PM
Something like this?

P=


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

Arterius
2015-02-18, 09:42 AM
Almost...
this lisp is looking for maximum X value, I would like to have X value from source text...

peter
2015-02-18, 04:43 PM
Ok I changed the code to use the X coordinate of the source text.

See Above.

P=

Arterius
2015-02-19, 10:34 AM
Brilliant, thanks!
Can you advise how to convert it into y coodinate. I tryied to do it, but faild... I am to even weak in lisp... I change x -> y in routine but I think it is not enough...

peter
2015-02-19, 03:55 PM
Change this line



(setq sngMax (car lstInsertion)); <-First Item in list is the X coordinate


to



(setq sngMax (cadr lstInsertion)); <-Second Item in list is the Y coordinate


change



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


to



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


and of course change the name.

Arterius
2015-02-20, 08:04 AM
Thanks! Works super!