Nudge command via entmod

Nudge command via entmod

ryanatkins49056
Contributor Contributor
506 Views
4 Replies
Message 1 of 5

Nudge command via entmod

ryanatkins49056
Contributor
Contributor

Hello,

 

In one of the many exercises to understand entmod better I have created a nudge command for CIRCLE, TEXT & MTEXT. The basic premise is to modify the coordinates in the 10 list. This is due to them being common coordinates across all three entities. They each mean the following

CIRCLE - centrepoint coordinates

MTEXT - justification point

TEXT - first alignment point

 

The code works for CIRCLE and MTEXT entities but only on TEXT entities that have Left justification. (ie a number 0 in fields 72 and 73, and the 11 list reads (11 0 0 0). Is there a reason as to why the TEXT entities which have a justification point will not move when I modify the 10 list?

 

I have posted the code below. (Please note the variable nudgefactor is set separately when I set up a drawing each time)

 

(defun c:nuntest ( / nudgenorthstuffssget nudgenorthstufflist txtdtxtormtxt);nudge an object north by the stated nudgefactor (nudgfactor)
  (princ "\n Select the objects you wish to NUDGE north: ")
  (setq nudgenorthstuffssget (ssget (list '(-4 . "<OR") '(0 . "*TEXT") '(0 . "CIRCLE") '(-4 . "OR>"))));creates the selection set using standard autocad selection procedures
  (command "UNDO" "BEGIN")
    (if nudgenorthstuffssget
      (repeat (setq xyxy (sslength nudgenorthstuffssget))
        (setq nudgenorthstufflist (cons (ssname nudgenorthstuffssget (setq xyxy (1- xyxy))) nudgenorthstufflist))
      );(repeat)
    );(if) Lee Mac create a list for processing from the selection set
  (foreach nudgenorthstuffpos nudgenorthstufflist ;for each north position (nudgenorthstuffpos) of each entity in the selection set list (nudgenorthstufflist)
    (progn
      (setq nudgenorthinfo (entget nudgenorthstuffpos));get the entity data as a list
      (setq txtdtxtormtxt (assoc 0 nudgenorthinfo));set variable to entity database type (ie TEXT, MTEXT, CIRCLE, ARC and so on)
      (setq nudgenorthxy (assoc 10 nudgenorthinfo));get the current x and y coords of alignment point
      (setq nudgenorthxcoor (nth 1 nudgenorthxy));gets the current x coordinate for the text
      (setq nudgenorthycoorold (nth 2 nudgenorthxy));gets the current y coordinate for the text
      (setq nudgenorthycoor (+ nudgefactor nudgenorthycoorold));calculates new x coordinate for the text
      (setq nudgenorthxynew (list 10 nudgenorthxcoor nudgenorthycoor 0.0));builds new coordinate list
      (entmod (subst nudgenorthxynew nudgenorthxy nudgenorthinfo));replace the current coords with new coords (modified x & y)
    );entity data processing (progn)
  );each item to be processed (foreach)
  (command "UNDO" "END")
  (princ)
)
0 Likes
Accepted solutions (1)
507 Views
4 Replies
Replies (4)
Message 2 of 5

Sea-Haven
Mentor
Mentor

One hint dont need Or

 

 (setq nudgenorthstuffssget (ssget '((0 . "*TEXT,CIRCLE"))))

 

I would do (entget (car (entsel))) on the text objects and see the differences as you change say justification, start with normal left bottom. You may see extra dxf codes starting to be added, when you get all the dxf codes often some are not there till you change something like justification then they are added. 

Look at various differences here.

normal text
PICK((-1 . <Entity name: 6e5ddcd0>) (0 . "TEXT") (5 . "96") (330 . <Entity name: 952348c0>) (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (370 . -1) (100 . "AcDbText") (10 9080.0 2480.0 0.0) (40 . 58.5359622422548) (1 . "ASDF") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "Standard") (71 . 0) (72 . 0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbText") (73 . 0))
: 
changed text justification to centre
PICK((-1 . <Entity name: 6e5ddcd0>) (0 . "TEXT") (5 . "96") (330 . <Entity name: 952348c0>) (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (370 . -1) (100 . "AcDbText") (10 8974.xxx-xxxxxxxx 2450.xxx-xxxxxxxx 0.0) (40 . 58.5359622422548) (1 . "ASDF") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "Standard") (71 . 0) (72 . 1) (11 9080.0 2480.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbText") (73 . 2))

 

0 Likes
Message 3 of 5

Kent1Cooper
Consultant
Consultant

You need to use 11 instead of 10 if the justification is not Left.  10 is always the left end of the baseline, but that's not the insertion point at other justifications.  Check the 72 and 73 entries for the justification -- if both are 0, it's left-justified, so use the 10 entry; if not, use 11.

Kent Cooper, AIA
0 Likes
Message 4 of 5

ryanatkins49056
Contributor
Contributor

Hi @Kent1Cooper ,

 

I'm more curious as to why it will not move when the 72 and 73 entries are present. I have a feeling that when those two flags are set the 10 entry becomes read only but am curious if anyone has some answers.

 

I have other commands where when those flags are set where I modify the 11 entry.

0 Likes
Message 5 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

@ryanatkins49056 wrote:

....

I'm more curious as to why it will not move when the 72 and 73 entries are present. I have a feeling that when those two flags are set the 10 entry becomes read only but am curious if anyone has some answers.

I have other commands where when those flags are set where I modify the 11 entry.


Those two [72 & 73] entries are always present.  It's when they're both set to 0 that the Text is left-justified, and the 10 value is the insertion point, you can move the Text by changing the 10 value, and the 11 value is always 0,0,0.  If they are not both set to 0, then the justification is something else, the 11 value is the insertion point, which you can move it by, and the 10 value, being always the left end of the baseline, is only a result from the relationship between the insertion point and particular justification and text content and height and width factor and font and rotation and who knows what-all else, and you can't move it by way of, nor change, the 10 value.

Kent Cooper, AIA