Happy Hobbit Posted October 7, 2015 Posted October 7, 2015 (edited) Hello all I decided to write my own code to put the selected middle centred text at it's insertion point at the middle centre of two points.. It works great using entsel (semi-coloned off), but errors with ssget as it says it would on Lee Mac's tutorial on ssget I'd be happy with entsel, but I'd prefer a filter to only select *text (0 . "TEXT,MTEXT") My attempt is: (defun c:test ( / ang ent insp midp obj p1 p2) (setvar "osmode" 51);; osnap to endpoint, midpoint, quadrant & intersection (setq obj (ssget "\nSelect text or mtext: " '("_+.:E:S" ((0 . "TEXT,MTEXT"))))) ;(setq obj (entsel "\nSelect text or mtext: ")) (command "justifytext" obj "" "MC") (setq ent (cdr(assoc 0 (entget (car obj))))) ;(princ (strcat "The type of entity is " ent)); Testing purposes only (setq p1 (getpoint "\nPick Point 1: ")) (setq p2 (getpoint "\nPick Point 2: ")) (setq ang (angle p1 p2)) (setq midp (polar p1 ang (* (distance p1 p2) 0.5))) (cond ((= ent "TEXT") ;(princ "\nThis is Text at: "); Testing purposes only ;(princ insp); Prints coordinates of mtext entity - Testing purposes only (setq insp (cdr (assoc 11 (entget (car obj)))));; coordinates of text entity (command "_move" obj "" "_none" insp "_none" midp) ) ((= ent "MTEXT") ;(princ "\nThis is MText at"); Testing purposes only ;(princ insp); Prints coordinates of mtext entity - Testing purposes only (setq insp (cdr (assoc 10 (entget (car obj)))));; coordinates of mtext entity (command "_move" obj "" "_none" insp "_none" midp) ) ) (setvar "osmode" 0); turns off all osnaps (princ) ) Forgive all the semi colons, I'm still testing it P.S. Please don't re-write, please point out where I'm going wrong Edited October 7, 2015 by Happy Hobbit typo Quote
Lee Mac Posted October 7, 2015 Posted October 7, 2015 After a quick glance, (setq obj (ssget "\nSelect text or mtext: " '("_+.:E:S" ((0 . "TEXT,MTEXT"))))) Should be: (setq obj (ssget "_+.:E:S" '((0 . "TEXT,MTEXT")))) You cannot issue a user prompt using the standard ssget function. Quote
Happy Hobbit Posted October 8, 2015 Posted October 8, 2015 (edited) Thank you for that Lee & thank you for not taking the p Unfortunately without the entget it's now crashing on: (setq ent (cdr(assoc 0 (entget (car obj))))) :-/ Edited October 8, 2015 by Happy Hobbit Quote
Lee Mac Posted October 8, 2015 Posted October 8, 2015 Yes, you will need to retrieve the entity name from the selection set acquired by ssget using the ssname function - since there is only one object selected, this entity will reside at index 0. Quote
Happy Hobbit Posted October 8, 2015 Posted October 8, 2015 using this for mtext? (setq insp (cdr (assoc 10 (entget (ssname obj 0))))) And this for text (setq insp (cdr (assoc 11 (entget (ssname obj 0))))) I actually think it's sorted thanks to you Lee & your website Ta much Quote
Lee Mac Posted October 8, 2015 Posted October 8, 2015 Excellent to hear Happy Hobbit, you're welcome. Quote
Happy Hobbit Posted October 8, 2015 Posted October 8, 2015 (edited) Just in case anyone else can use my humble finished code: (defun c:Move2MC ( / ang ent insp mc obj oso p1 p2 ) (setq oso (getvar "osmode")) (setvar "osmode" 51);; osnap to endpoint, midpoint, quadrant & intersection (princ "\nSelect text or mtext: ") (if (setq obj (ssget "_+.:E:S" '((0 . "TEXT,MTEXT")))) (progn (command "justifytext" obj "" "MC") (setq ent (cdr (assoc 0 (entget (ssname obj 0))))) (setq p1 (getpoint "\nPick Point 1: ")) (setq p2 (getpoint "\nPick Point 2: ")) (setq ang (angle p1 p2)) (setq mc (polar p1 ang (* (distance p1 p2) 0.5))) (cond ((= ent "TEXT") (setq insp (cdr (assoc 11 (entget (ssname obj 0))))) ) ((= ent "MTEXT") (setq insp (cdr (assoc 10 (entget (ssname obj 0))))) ) ) ) (princ "\n** Missed, Try again **") ) (command "_move" obj "" "_none" insp "_none" mc) (setvar "osmode" oso); returns to previous osmode setting (princ) ) Edited October 11, 2015 by Happy Hobbit Simplified it a little Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.