Author Topic: Entmod not updating to new text location...  (Read 3185 times)

0 Members and 1 Guest are viewing this topic.

BrainStain

  • Guest
Entmod not updating to new text location...
« on: December 14, 2015, 02:54:01 PM »
I'm learning more about Lisp, and for practice developed one that lets a user pick the starting text as the first sentence for notes, then lets user pick another text line anywhere on the dwg, and it matches the first sentence's justification, ht, sz... and places it at a distance the user specifies at the prompt, below the first sentence.

This is so a cluster of notes can be randomly around the dwg, and a user can go around picking which they want for the next line, while matching all the originals properties.

Everything works well. I can pick Any justification to start with, and any justification I pick next, changes and uses the the assoc 11 to locate the next line.

The only group that doesnt work is when the first pick is ANY JUSTIFICATION BUT the Standard Left justification, and the second IS the Standard Left justification, it throws the second sentence down to 0,0.

When I use the Visual Lisp Editor, and Step my way thru the program, watching all the variable involved, the numbers match to what theyre supposed to be, but it still throws the second sentence (when its Left Justified (assoc 11 at 0 0 0)) down to 0,0.

I use !t2tnewloc11 and its showing the values are correct, even try to (entmod second) at the command prompt, or Regen to wake it up, but it won't move back to where its supposed to be, right below the first sentence.

It also works ok if I remove the assoc 72 and 73 out of the routine, but then my justification wont change in case I want to move them orderly later by snaps.

I also tried to save the original location it gets set to to another variable, to reset it to the location its supposed to be at, and entmod it as the very last program line, in case its loosing its value at the last minute for some reason, but it still wont go to the correct spot, still at 0,0.

It always works if I start with Left justified, and pick any other Justification, or start with any other justification, and pick any justification other than Left.

I also print the list associated with that entity name to the screen, and it shows the values have changed, but it doesnt move it to the X,Y (11 . X Y Z) that the variable is holding. Of course listing the text list itself shows that the assoc 11 values changed back to 0 0 0.

Why might my (entmod) not be keeping the changes it says the values are for that variable?

Here is the code, remember, Im new to the deeper coding, even tho Ive been dabbling for years, so my
coding is not high tech, its my first program on my own, and just used the text placement to learn something.

(defun c:txtjust ()
     (prompt "Builds a notes list by selecting from existing notes, ")(terpri)
     (prompt "Std spcg. for .1875 text, about .32, ")
   (prompt "Spcg. for notes with boxes, about .50 ")(terpri)
;   (prompt "Current spacing is: ")(princ tspg)
   (setq ds (getvar "dimscale"))                  ; dimscale to match spacing
   (prompt "Program factors dimscale with user input, ")         ; helping user to enter correct input
     (setq tspg (getreal "Enter text spacing: "))
   (setq t1ipL (entget (car (entsel "Select text guide: "))))(terpri)
   (setq t1as10 (assoc 10 t1ipL))
   (setq t1as11 (assoc 11 t1ipL))
     (setq t1as40 (assoc 40 t1ipL))
   (setq t1as7 (assoc 7 t1ipL))
     (setq t1as72 (assoc 72 t1ipL))
     (setq t1as73 (assoc 73 t1ipL))
     (setq t1ht (cdr t1as40))
   (setq t1jpx (cadr t1as10))                  ; gets x for 10 for t1
     (setq t1jpy (caddr t1as10))                  ; gets y for 10 for t1
   (if (and (= (cdr t1as72) 0)(= (cadr t1as11) 0))      ; of both, its left just. and sets 11 for 10 since 11 is 0.
   (setq t1as11 t1as10))
   (setq t1ipx (cadr t1as11))                  ; gets x for 11 for t1
   (setq t1ipy (caddr t1as11))                  ; gets y for 11 for t1

     (setq t2ipL (entget (car (entsel "Select next line: "))))
     (setq t2as10 (assoc 10 t2ipL))
   (setq t2as11 (assoc 11 t2ipL))
   (setq t2as72 (assoc 72 t2ipL))
   (setq t2as40 (assoc 40 t2ipL))
   (setq t2as7  (assoc 7 t2ipL))
     (setq t2as73 (assoc 73 t2ipL))
     (setq t2jpx (cadr t2as10))                  ; gets x for 10 for t2
     (setq t2jpy (caddr t2as10))                  ; gets y for 10 for t2
   (if (and (= (cdr t2as72) 0)(= (cadr t2as11) 0))
   (setq t2as11 t2as10))
     (setq t2as40 (assoc 40 t2ipL))

   (setq t2ipy (- t1ipy (* tspg ds)))               ; sets spacing from t1 for 11 of t2
   (setq t2jpy (- t1jpy (* tspg ds)))               ; sets spacing from t1 for 10 of t2
     (setq t2ipx t1ipx)                     ; grabs x from t1
   (setq t2ipL (subst t1as40 t2as40 t2ipL))            ; replaces text size
   (entmod t2ipL)
   (setq t2ipL (subst t1as7 t2as7 t2ipL))               ; replaces text style
   (entmod t2ipL)            
   (setq t2newloc10 (list 10 t2ipx t2jpy 0.0))            ; creates 10's list for t2
   (setq t2ipL (subst t2newloc10 t2as10 t2ipL))            ; substitutes the new 10 value
    (entmod t2ipL)                        ; mods the entity t2ipL
   (setq t2ipL (subst t1as72 t2as72 t2ipL))            ; creates 72's list for t2
     (entmod t2ipL)
   (setq t2newloc11 (list 11 t2ipx t2ipy 0.0))            ; creates 11's list for t2
   (setq t2tnewloc11 t2newloc11)
     (setq t2ipL (subst t2newloc11 t2as11 t2ipL))
     (entmod t2ipL)
         (setq t2ipL (subst t1as73 t2as73 t2ipL))            ; creates 73's list for t2
     (entmod t2ipL)
;       (setq t2ipL (subst t2tnewloc11 t2as11 t2ipL))         ; tried just retrieving orig new saved new loc. value
;       (entmod t2ipL)                                                         ; and replacing back into the entity name, but noooo
   (setq t2tnewloc11 (list 11 t2ipx t2ipy 0.0))
     (setq t2ipL (subst t2tnewloc11 t2as11 t2ipL))
   (entmod t2ipL)
     (princ)                           ; prog was listing value for t2ipL, this cleaned it up
  )

Thanks for any ideas on helping with the magic jumping bean!


ronjonp

  • Needs a day job
  • Posts: 7531
Re: Entmod not updating to new text location...
« Reply #1 on: December 14, 2015, 03:43:51 PM »
Not a direct answer but perhaps some simplification is in order :)

Code - Auto/Visual Lisp: [Select]
  1. (defun c:txtjust (/ txt txt2)
  2.   (if (and (setq txt (car (entsel "\nSelect text guide: ")))
  3.            (= "AcDbText" (vla-get-objectname (setq txt (vlax-ename->vla-object txt))))
  4.       )
  5.     (while (and (setq txt2 (car (entsel "\nSelect next line: ")))
  6.                 (= "TEXT" (cdr (assoc 0 (entget txt2))))
  7.                 (setq txt (vla-copy txt))
  8.            )
  9.       (vla-put-textstring txt (vla-get-textstring (vlax-ename->vla-object txt2)))
  10.       (vlax-invoke
  11.         txt
  12.         'move
  13.         '(0.0 0.0 0.0)
  14.         (polar '(0 0 0) (- (vla-get-rotation txt) (/ pi 2)) (* 1.25 (vla-get-height txt)))
  15.       )
  16.     )
  17.   )
  18.   (princ)
  19. )
« Last Edit: December 15, 2015, 08:54:32 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Entmod not updating to new text location...
« Reply #2 on: December 14, 2015, 04:11:03 PM »
Maybe the code below will help you understand your problem.
Note: The code does not work properly for the 'Aligned' and 'Fit' justifications.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test ( / scl spc elstBase elstNext ptBase ptNext)
  2.   (setq scl (getvar 'dimscale))
  3.   (setq spc (getreal "\nText spacing: "))
  4.   (setq elstBase (entget (car (entsel "\nSelect text guide: "))))
  5.   (setq elstNext (entget (car (entsel "\nSelect next line: "))))
  6.   (if
  7.     ;; check if 'text guide' is left aligned:
  8.     (and
  9.       (zerop (cdr (assoc 72 elstBase)))
  10.       (zerop (cdr (assoc 73 elstBase)))
  11.     )
  12.     ;; If the text is left aligned group code 10 is the insertion point:
  13.     (progn
  14.       (setq ptBase (cdr (assoc 10 elstBase)))
  15.       (setq ptNext (list (car ptBase) (- (cadr ptBase) (* scl spc)) 0.0))
  16.       (setq elstNext (subst (cons 10 ptNext) (assoc 10 elstNext) elstNext))
  17.     )
  18.     ;; Else group code 11 is the insertion point:
  19.     (progn
  20.       (setq ptBase (cdr (assoc 11 elstBase)))
  21.       (setq ptNext (list (car ptBase) (- (cadr ptBase) (* scl spc)) 0.0))
  22.       (setq elstNext (subst (cons 11 ptNext) (assoc 11 elstNext) elstNext))
  23.     )
  24.   )
  25.   (setq elstNext (subst (assoc 72 elstBase) (assoc 72 elstNext) elstNext))
  26.   (setq elstNext (subst (assoc 73 elstBase) (assoc 73 elstNext) elstNext))
  27.   (entmod elstNext)
  28.   (princ)
  29. )

BrainStain

  • Guest
Re: Entmod not updating to new text location...
« Reply #3 on: December 14, 2015, 04:21:04 PM »
Very nicely done. I can see there is much learning ahead of me.

I will be going thru this option variable-by-variable, line-by-line to learn.

Thanks Ron for the gift.

If you ever hear why the entmod isnt updating my method, or why the Left Justification
responded differently, I'd love to learn that next baby-step too.

Have a good New Year.

BrainStain

  • Guest
Re: Entmod not updating to new text location...
« Reply #4 on: December 14, 2015, 04:22:45 PM »
Roy,

I had just posted a reply when yours came in, I will give it a try now.

Thanks for the code where I can learn more, as I need it.

You have a great New Year too.

BrainStain

  • Guest
Re: Entmod not updating to new text location...
« Reply #5 on: December 14, 2015, 04:29:53 PM »
Roy,

Smooth as Silk, thank you.

Im looking forward to doing more than just taking existing code and tweaking it,
now I can be more creative I hope.

Thanks for the lesson.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Entmod not updating to new text location...
« Reply #6 on: December 14, 2015, 04:34:46 PM »
Very nicely done. I can see there is much learning ahead of me.

I will be going thru this option variable-by-variable, line-by-line to learn.

Thanks Ron for the gift.

If you ever hear why the entmod isnt updating my method, or why the Left Justification
responded differently, I'd love to learn that next baby-step too.

Have a good New Year.
Glad to help out .. happy learning !  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Entmod not updating to new text location...
« Reply #7 on: December 15, 2015, 08:39:55 AM »
The issue with the alignment is with the way AutoCAD interprets the group codes.
DXF 10 is used ONLY if both group codes 72 and 73 are zero or non-existant. If DXF 72 and 73 are used and have non-zero values, AutoCAD uses DXF 11 for alignment.

Basically, if you want to use anything except left aligned, base aligned text, you must use DXF 11 and fill in values for DXF 72 and 73, if you want left aligned, base aligned text, you must NOT use DXF 72  and 73 or you must set them to 0. 
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Entmod not updating to new text location...
« Reply #8 on: December 15, 2015, 09:03:33 AM »
I updated the code above to allow for multiple selection.


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BrainStain

  • Guest
Re: Entmod not updating to new text location...
« Reply #9 on: December 15, 2015, 09:17:23 AM »
Thanks Keith for helping with the Justification issue. I really appreciate your focus on the alignment problem.

Forgive me for not understanding some of your terminology you used, since Im somewhat a beginner at these terms.
My only understanding of DXF (dwg exchange file) was for when you were converting a file from one format to another, so I hadnt thought of it in reference to Lisp coding, so I had trouble following you there. Im assuming it is referencing assoc? so I may be missing your point, sorry.

I had made a sheet (for my own ref) as to what the assoc. values were for each of the 13 different text justifications and insert points, so I could try to see what was causing any shifting.

In my program I did a check to see if both the assoc 72 value was 0, and if assoc 11 was 0, then set assoc 11 to assoc 10 for left to at least have a value there for later use.

I also set the assoc 72 and 73 from the first text selected to be the values for the second text selected, so the justification of both would be the same.

When I 'watched' if the variables would change to match the first text selected, they did, so I thought I had covered getting the second text to match the first's values.

But for some odd reason, at the last nano-second, the assoc 11 value changed back to 0 0 0, even though the 72 and 73 were still matching the first text's values, which moved the second text down to 0,0 since I was using assoc 11 to locate its position. (11 did get changed inside the program since it was one of the values I was watching change.)

I will go back to let what you said soak in, I just wanted to respond as quick as I saw your reply to thank you for the focus on my early learning question.

BrainStain

  • Guest
Re: Entmod not updating to new text location...
« Reply #10 on: December 15, 2015, 09:26:51 AM »
Ron, thanks, that makes a lot of sense instead of back and forth.

I think I was at the most very basic level just trying to develop my first full code and 'watch' the variables change to see the genius of me in action, lol.

Your original code was so simple, I couldnt understand how it could work so well. Now Im going back to see what all the vla and vlax stuff is about,(and Im probably stepping on my own feet referring to it in that way, but I'll learn)

I was originally trying to save the user input for spacing so it wouldnt have to be re-entered each time, but couldnt figure out how that was done, but your way of keeping the value for multiple selections on the matching text solves that, much better, thanks.

Thanks for the animation, graphics help simple minded.

Back to variable-land.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Entmod not updating to new text location...
« Reply #11 on: December 15, 2015, 09:33:23 AM »
Ron, thanks, that makes a lot of sense instead of back and forth.

I think I was at the most very basic level just trying to develop my first full code and 'watch' the variables change to see the genius of me in action, lol.

Your original code was so simple, I couldnt understand how it could work so well. Now Im going back to see what all the vla and vlax stuff is about,(and Im probably stepping on my own feet referring to it in that way, but I'll learn)

I was originally trying to save the user input for spacing so it wouldnt have to be re-entered each time, but couldnt figure out how that was done, but your way of keeping the value for multiple selections on the matching text solves that, much better, thanks.

Thanks for the animation, graphics help simple minded.

Back to variable-land.
If you have any questions don't hesitate to ask.  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Entmod not updating to new text location...
« Reply #12 on: December 15, 2015, 09:46:48 AM »
DXF group codes are what you refer to as assoc codes.

When you ENTMOD an object, you are in effect editing the values of the DXF group codes of the object. ASSOC is simply the function that gets you access to the values of those group codes from a list of group codes. Assoc is essentially "Association" ... meaning to get the association of a particular group ... i.e. (assoc 10 eList) returns the DXF group code 10, if it exists, in the list of group codes and values contained in eList.

Don't worry too much about terminology .. you will get there if you stay with it long enough.

I should also add that ASSOC also works on lists that are not DXF group codes. ASSOC can use pretty much any dotted pair list.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

BrainStain

  • Guest
Re: Entmod not updating to new text location...
« Reply #13 on: December 15, 2015, 09:59:02 AM »
Thanks Keith for Upgrading my understanding of how all that is linked. Understanding allows progress.