Jump to content

Center Text in Box - From ENTSEL to SSGET?


ILoveMadoka

Recommended Posts

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 by Happy Hobbit
typo
Link to comment
Share on other sites

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    10

  • Happy Hobbit

    8

  • ILoveMadoka

    6

  • yathishkumar

    2

Top Posters In This Topic

Posted Images

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.

Link to comment
Share on other sites

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 by Happy Hobbit
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by Happy Hobbit
Simplified it a little
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...