Author Topic: text move lisp in need of enhancement  (Read 14025 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
text move lisp in need of enhancement
« Reply #15 on: August 04, 2005, 02:07:50 PM »
daron i read through all of the funtions you told me to check out and think i get them all. i showed my boss what you pointed me to and she thought that simply creating a lisp to do vertical dimensions then trying to combine the two using if or cond would be a good exercise for me to try. she said the other functions are very powerful to know but i'm not quite on that level yet. i will give the vertical routine a shot then try to piece them together while i'm waiting for your response later.

daron

  • Guest
text move lisp in need of enhancement
« Reply #16 on: August 04, 2005, 02:13:29 PM »
No, that's vertical thingy would be way too much code, since you've already gathered everything you need, to do everything you need to do. The if or cond statements are going to decide from the condition which way to go. The code won't be much more than:
(if (minusp var)
   (using polar here with a negative angle)
   (using polar here with a positive angle)
)
That'll be a lot easier than plugging in a whole lot of unneccesary code.

ELOQUINTET

  • Guest
text move lisp in need of enhancement
« Reply #17 on: August 04, 2005, 03:29:25 PM »
i kind of understand where you are going but couldn't i acheive a similar result by introducing an if which compares the y values of pt1 and pt2 for the horizontal dimensions. the y value of pt1 would always be less than pt2? and the same goes for the z values for vertical dimensions?

daron

  • Guest
text move lisp in need of enhancement
« Reply #18 on: August 04, 2005, 03:44:16 PM »
Your vertical dimensions aren't in Z, they'd still be x and y. I see what you're saying though, which would work. Whatever you come up with, get it so it only returns a coordinate value. Don't add command to it. If you can do that, I'll give you the rest that'll make it work.

ELOQUINTET

  • Guest
text move lisp in need of enhancement
« Reply #19 on: August 04, 2005, 04:03:40 PM »
whoops i meant to type x values not z. two things i'm not sure how to branch the code and not quite sure how to not use command but i have some guesses. could i essentially move the entity by using the subst function to swap pt3 and pt1?

Code: [Select]
(defun c:MTO ( / txtentity txtlist dimentity dimlist txtxcoord txtycoord pt1 pt2 pt3)
 
  (setq osm (getvar 'osmode))
  (setvar "osmode" 0)
  (setq txtentity (car (entsel "\nSelect text: "))
txtlist  (entget txtentity)
pt1  (cdr (assoc 10 txtlist))
x1        (car (assoc 10 vtxtlist))
        y1        (cadr (assoc 10 txtlist))
  )  
  (setq dimentity (car (entsel "\nSelect dimension: "))
dimlist  (entget dimentity)
pt2  (cdr (assoc 11 dimlist))
x2        (car (assoc 11 vdimlist))
y2        (cadr (assoc 11 dimlist))

  (if (y1 < y2<<<<<<<<<<<<<not sure what to put here and below???
  (if (z1 < z2<<<<<<<<<<<<<


  )
  (setq txtxcoord (car pt2)
  )
  (setq txtycoord (cadr pt1)
  )
  (setq pt3 (list txtxcoord txtycoord 0)
  )
  (command "move" pt1 "" pt1 pt3)
  (setvar 'osmode osm)
  (princ)
)



    (setq vtxtxcoord (car pt1)
  )
    (setq vtxtycoord (cadr pt2)
  )
    (setq pt6 (list vtxtxcoord vtxtycoord 0)
  )
    (command "move" pt1 "" pt1 pt3)
    (setvar 'osmode osm)
  (princ)
)

daron

  • Guest
text move lisp in need of enhancement
« Reply #20 on: August 04, 2005, 04:26:54 PM »
Quote from: ELOQUINTET
could i essentially move the entity by using the subst function to swap pt3 and pt1?

Bingo. But that only substitutes one item for another. It still won't stick (read: MODify the ENTity), then when you do modify then entity, you'll still need to graphically UPDate the ENTity. Now, I wonder which two functions might do that? Hint: both start with ENT.
As far as returning a coordinate:
Code: [Select]
(defun c:MTO ( / txtentity txtlist dimentity dimlist txtxcoord txtycoord pt1 pt2 pt3)
  (setq   txtentity (car (entsel "\nSelect text: "))
   txtlist     (entget txtentity)
   pt1     (cdr (assoc 10 txtlist))
   x1        (car (assoc 10 vtxtlist))
        y1        (cadr (assoc 10 txtlist))
  )
  (setq   dimentity (car (entsel "\nSelect dimension: "))
   dimlist     (entget dimentity)
   pt2     (cdr (assoc 11 dimlist))
   x2        (car (assoc 11 vdimlist))
   y2        (cadr (assoc 11 dimlist))

  (if (y1 < y2<<<<<<<<<<<<<not sure what to put here and below???
  (if (z1 < z2<<<<<<<<<<<<<

   
  )
  (setq   txtxcoord (car pt2)
  )
  (setq   txtycoord (cadr pt1)
  )
  (setq   pt3 (list txtxcoord txtycoord 0)
  )
  (command "move" pt1 "" pt1 pt3)
  (setvar 'osmode osm)
  (princ)
)



    (setq   vtxtxcoord (car pt1)
  )
    (setq   vtxtycoord (cadr pt2)
  )
    (setq   pt6 (list vtxtxcoord vtxtycoord 0)
  )
)

That will return pt6, which should be a coordinate. I haven't checked the code. However,
Code: [Select]
 (if (y1 < y2<<<<<<<<<<<<<not sure what to put here and below???
  (if (z1 < z2<<<<<<<<<<<<<

That is closer to cond. If would look like:
Code: [Select]
(if (< y1 y2)
    (then do something here)
    (otherwise, do this instead)
)

What need to go in there is something to determine which direction we want to go.
Take a look at this code. It has a few bugs, but it was my first draft. I need to change my clause for if to look at from minusp to something more like (or (< inclangle 90) (> inclangle 270)). That's it in a nutshell. It's still buggy and we MUST do some error trapping. For starters, what if you miss when selecting or select something non-text or dimension, or select in reverse order even?
Code: [Select]
;;pick the text using the node as the point
;;then move the text to the midpoint of the dimension line
;;   We need to keep GC71 in mind. We might need it in the future.
;;then move the text down 3-1/2
(defun c:MoveTextObject   (/          txtentity     txtlist
          txtassoc10    dimentity     dimlist
          dimassoc10    dimassoc11    dimassoc13
          dimassoc14    dimassoc42
         )
     (setq txtentity  (car (entsel "\nSelect text: "))
      txtlist    (entget txtentity)
      txtassoc10 (cdr (assoc 10 txtlist))
     )
     (setq dimentity  (car (entsel "\nSelect dimension: "))
      dimlist    (entget dimentity)
      dimassoc10 (cdr (assoc 10 dimlist))
      dimassoc11 (cdr (assoc 11 dimlist))
      dimassoc13 (cdr (assoc 13 dimlist))
      dimassoc14 (cdr (assoc 14 dimlist))
      dimassoc42 (cdr (assoc 42 dimlist))
     )
     (setq txt2dimang (angle dimassoc10 dimassoc14)
      dimlen     (/ dimassoc42 2.0)
     )
     (setq constangle (angle dimassoc14 dimassoc10)
      varangle   (angle dimassoc14 dimassoc13)
      inclangle  (- constangle varangle)
     )
 ;determines whether we go 90 or 180 degrees.
     (if (minusp inclangle)
     (setq point (polar dimassoc10 (- txt2dimang (/ pi 2)) dimlen))
     (setq point (polar dimassoc10 (+ txt2dimang (/ pi 2)) dimlen))
     )
 ;gets midpoint of dimline
     (setq setpt (polar point txt2dimang 3.5))
 ;point needed to subst for text entity
     (entmod (subst (cons 10 setpt) (cons 10 txtassoc10) txtlist))
     (entupd txtentity)
)

ELOQUINTET

  • Guest
text move lisp in need of enhancement
« Reply #21 on: August 04, 2005, 05:14:32 PM »
i can see what you mean daron yours is much cleaner. i read through all of the functions you told me to and i has a loose understanding of the method you are trying to get me to try, subst, entmod, entupd. the thing is when i have showed these methods to my boss she has nearly had a heart attack. saying i'm in effect standing at the bottom of the grand canyon and you are at the top saying "come on up the climb is easy". i will try to play around with it when i go home tonight. here's my code as of now. i get malformed list upon loading  :cry: but i'm NOT giving up  :lol:


Code: [Select]
(defun c:MTO3 ( / txtentity txtlist dimentity dimlist txtxcoord txtycoord pt1 pt2 pt3 pt4)
 
  (setq osm (getvar 'osmode))
  (setvar "osmode" 0)
  (setq txtentity (car (entsel "\nSelect text: "))
txtlist  (entget txtentity)
pt1  (cdr (assoc 10 txtlist))
x1        (car (assoc 10 txtlist))
        y1        (cadr (assoc 10 txtlist))
  )  
  (setq dimentity (car (entsel "\nSelect dimension: "))
dimlist  (entget dimentity)
pt2  (cdr (assoc 11 dimlist))
x2        (car (assoc 11 dimlist))
y2        (cadr (assoc 11 dimlist))
  (if (< y1 y2)
    (setq txtxcoord (car pt2)
  )
    (setq txtycoord (cadr pt1)
  )
    (setq pt3 (list txtxcoord txtycoord 0)
  )
  (command "move" pt1 "" pt1 pt3)
  )    
  (if (< x1 x2)
    (setq txtxcoord (car pt1)
  )
    (setq txtycoord (cadr pt2)
  )
    (setq pt4 (list vtxtxcoord vtxtycoord 0)
  )
  (command "move" pt1 "" pt1 pt4)
    (setvar 'osmode osm)
  (princ)
)

daron

  • Guest
text move lisp in need of enhancement
« Reply #22 on: August 05, 2005, 07:30:34 AM »
This:
Code: [Select]
(setq   dimentity (car (entsel "\nSelect dimension: "))
   dimlist     (entget dimentity)
   pt2     (cdr (assoc 11 dimlist))
   x2        (car (assoc 11 dimlist))
   y2        (cadr (assoc 11 dimlist))

is why you get a malformed list.
I think you understand cond better than if.
If you want to use if with a bunch of items, you need to lump everything into one condition or function and call that function externally. If only looks at two things unless you use progn. However, cond is more flexible and that's how your code is set up. Check this out:
Code: [Select]

(cond ((< y1 y2)
    (setq txtxcoord (car pt2))
    (setq txtycoord (cadr pt1))
    (setq pt3 (list txtxcoord txtycoord 0))
  (command "move" pt1 "" pt1 pt3))
  );This set of parens wraps your code and acts like progn, exept you always use it to separate your conditions.
  ((< x1 x2)
    (setq txtxcoord (car pt1))
    (setq txtycoord (cadr pt2))
    (setq pt4 (list vtxtxcoord vtxtycoord 0))
  (command "move" pt1 "" pt1 pt4)
  );Same goes here.
)

As an if statement:
Code: [Select]
(if (< y1 y2)
  (progn
    (setq txtxcoord (car pt2))
    (setq txtycoord (cadr pt1))
    (setq pt3 (list txtxcoord txtycoord 0))
  (command "move" pt1 "" pt1 pt3)
  )
 )  
  (if (< x1 x2)
   (progn
    (setq txtxcoord (car pt1))
    (setq txtycoord (cadr pt2))
    (setq pt4 (list vtxtxcoord vtxtycoord 0))
  (command "move" pt1 "" pt1 pt4)
  )
)

The reason I didn't have you look into progn is because I wasn't seeing a need for finding what you are looking at here. As far as the Grand Canyon idea goes, maybe I am, but I really thought what I gave you yesterday was like throwing you a rope with a harness attached. It may seem like a lot now, but just work with me. Really, I'm not at the top, I feel more like I've been your belayer. I can't climb it for you but I can tell you where your next best foothold or handgrip is. Seriously, check out my code and see what errors you can find. There are many.

ELOQUINTET

  • Guest
text move lisp in need of enhancement
« Reply #23 on: August 05, 2005, 10:06:01 AM »
daron didn't see your post until now. i was actually looking at progn and tried to include it in my if but kept getting malformed list and extra paren errors. the first routine is what i had. then i saw your post and swapped cond for if and did a little tweaking and it is working so far. the second one is a success but how do we deal with the justification problem. i will also save this as another routine and try the entmod route and see if i can get that.

Code: [Select]
(defun c:MTO3 ( / txtentity txtlist dimentity dimlist txtxcoord txtycoord pt1 pt2 pt3 pt4)
 
  (setq osm (getvar 'osmode))
  (setvar "osmode" 0)
    (setq   txtentity (car (entsel "\nSelect text: "))
   txtlist   (entget txtentity)
   pt1      (cdr (assoc 10 txtlist))
   x1        (car (assoc 10 txtlist))
            y1        (cadr (assoc 10 txtlist))
  )  
    (setq   dimentity (car (entsel "\nSelect dimension: "))
   dimlist   (entget dimentity)
   pt2      (cdr (assoc 11 dimlist))
   x2        (car (assoc 11 dimlist))
   y2        (cadr (assoc 11 dimlist))
  )
  (if (< y1 y2)
    (progn
      (setq txtxcoord (car pt2)
            txtycoord (cadr pt1)
            pt3 (list txtxcoord txtycoord 0))
    )  
  (if (< x1 x2)
    (progn
      (setq txtxcoord (car pt1)
            txtycoord (cadr pt2)
            pt3 (list txtxcoord txtycoord 0))
    )
  (command "move" pt1 "" pt1 pt3)
    (setvar 'osmode osm)
    )
  (princ)
)





Code: [Select]
(defun c:MTO3 ( / txtentity txtlist dimentity dimlist txtxcoord txtycoord pt1 pt2 pt3 pt4 osm)
 
  (setq osm (getvar 'osmode))
  (setvar "osmode" 0)
    (setq   txtentity (car (entsel "\nSelect text: "))
   txtlist   (entget txtentity)
   pt1      (cdr (assoc 10 txtlist))
   x1        (car (assoc 10 txtlist))
            y1        (cadr (assoc 10 txtlist))
  )  
    (setq   dimentity (car (entsel "\nSelect dimension: "))
   dimlist   (entget dimentity)
   pt2      (cdr (assoc 11 dimlist))
   x2        (car (assoc 11 dimlist))
   y2        (cadr (assoc 11 dimlist))
  )
  (cond ((< y1 y2)
    (setq txtxcoord (car pt2))
    (setq txtycoord (cadr pt1))
    (setq pt3 (list txtxcoord txtycoord 0))
  (command "move" pt1 "" pt1 pt3))
  );This set of parens wraps your code and acts like progn, exept you always use it to separate your conditions.
  ((< x1 x2)
    (setq txtxcoord (car pt1))
    (setq txtycoord (cadr pt2))
    (setq pt3 (list txtxcoord txtycoord 0))
  (command "move" pt1 "" pt1 pt3)
  );Same goes here.
    (setvar 'osmode osm)
    (princ)
  )



it works  :shock:  :D  8)

ELOQUINTET

  • Guest
text move lisp in need of enhancement
« Reply #24 on: August 05, 2005, 10:25:54 AM »
daron i showed the cond version to my boss and now we got the if version to work too. here it is:

Code: [Select]
(defun c:MTOIF ( / txtentity txtlist dimentity dimlist txtxcoord txtycoord pt1 pt2 pt3 pt4 osm)
 
  (setq osm (getvar 'osmode))
  (setvar "osmode" 0)
    (setq   txtentity (car (entsel "\nSelect text: "))
   txtlist   (entget txtentity)
   pt1      (cdr (assoc 10 txtlist))
   x1        (car (assoc 10 txtlist))
            y1        (cadr (assoc 10 txtlist))
  )  
    (setq   dimentity (car (entsel "\nSelect dimension: "))
   dimlist   (entget dimentity)
   pt2      (cdr (assoc 11 dimlist))
   x2        (car (assoc 11 dimlist))
   y2        (cadr (assoc 11 dimlist))
  )
  (if (< y1 y2)
      (setq txtxcoord (car pt2)
            txtycoord (cadr pt1)
            pt3 (list txtxcoord txtycoord 0))
      (setq txtxcoord (car pt1)
            txtycoord (cadr pt2)
            pt3 (list txtxcoord txtycoord 0))
    )
  (command "move" pt1 "" pt1 pt3)
    (setvar 'osmode osm)
    (princ)
  )

daron

  • Guest
text move lisp in need of enhancement
« Reply #25 on: August 05, 2005, 11:12:52 AM »
Okay Dan. I have looked at your code. You don't only have a text justification problem, but a text placement problem too. Check it out on rotated dimensions. Also, I don't see how yours is working when it gets to command. "What?" you ask? Answer this: The move command moves what? Multiple choice.
A) A coordinate
B) An object (entity)
C) Corned beef
Then answer this:
What are you moving in your routine?

Here's what yours would look like with subst et al in place of command
Code: [Select]
(defun c:MTOIF (/  txtentity txtlist   dimentity dimlist
txtxcoord txtycoord pt1      pt2 pt3
pt4  osm
      )
     (setq osm (getvar 'osmode))
     (setvar "osmode" 0)
     (setq txtentity (car (entsel "\nSelect text: "))
  txtlist   (entget txtentity)
  pt1     (cdr (assoc 10 txtlist))
  x1     (car (assoc 10 txtlist))
  y1     (cadr (assoc 10 txtlist))
     )
     (setq dimentity (car (entsel "\nSelect dimension: "))
  dimlist   (entget dimentity)
  pt2     (cdr (assoc 11 dimlist))
  x2     (car (assoc 11 dimlist))
  y2     (cadr (assoc 11 dimlist))
     )
     (if (< y1 y2)
 (setq txtxcoord (car pt2)
txtycoord (cadr pt1)
pt3  (list txtxcoord txtycoord 0.0)
 )
 (setq txtxcoord (car pt1)
txtycoord (cadr pt2)
pt3  (list txtxcoord txtycoord 0.0)
 )
     )
     (entmod (subst (cons 10 pt3) (cons 10 pt1) txtlist))
     (entupd txtentity)
     (setvar 'osmode osm)
     (princ)
)

Here's a challenge for you. Make your command line work, then save your drawing. Next, load both the above routine and yours. Draw a line on your screen.
Now, run your routine. If it works, undo.
Now, run the above code. It should do the exact same thing as yours. Undo.

Did something happen to that line I had you draw when you started this? If so, please explain it and why? Now, that question is a little more difficult to answer and that would be where I'm standing at the top of the GC and telling you it's not hard to climb. When you answer it, I'll throw you that rope once again.

ELOQUINTET

  • Guest
text move lisp in need of enhancement
« Reply #26 on: August 05, 2005, 12:20:36 PM »
daron i know it doesn't work for rotated dimensions. when my boss told me she was going to incorporate this text into our dimension style i abandoned writing it for rotated dimensions. it is just and exercise. as for the challenge i'm not sure what you are asking me to do. you say draw a line but this routine doesn't work on lines, dimension line yes but lines no. i don't see much happen if i do an undo. the text just goes back to where it was? i see what you mean when you ask what is getting moved but obviously it is moving the entity which resides at pt1 to pt3.

ELOQUINTET

  • Guest
text move lisp in need of enhancement
« Reply #27 on: August 05, 2005, 01:00:04 PM »
i am more interested in incorporating a while function into this so the user can select multiple items in one shot so that's what i'm looking into now.

daron

  • Guest
text move lisp in need of enhancement
« Reply #28 on: August 05, 2005, 01:05:23 PM »
Okay. The line is just an entity. You're not supposed to do anything with it, except watch it. When you run your routine, and undo, the text should move back, but when you run the one I changed from command to subst and undo, the text should move back and the line should disappear. That's what you're supposed to see. The real question is why does the line disappear?

Also, in your command line, your first argument is pt1. It's my understanding that pt1 is a coordinate. The move command requires as its first argument an entity. coordinates and entities are independent of each other and you can't move coordinates. What should be there is txtentity. Does that make sense.

As far as it being just a challenge for you to learn lisp, GOOD. I'm relieved at that. So, in moving on, what say you we figure out how subst, entmod and entupd will work for you? Honestly, I see this as a good step. Then, how are you doing with understanding IF and COND statements? After that, how about we tackle the issue of what happens if you miss your entities or if the wrong entities are selected?

daron

  • Guest
text move lisp in need of enhancement
« Reply #29 on: August 05, 2005, 01:20:17 PM »
Quote from: ELOQUINTET
i am more interested in incorporating a while function into this so the user can select multiple items in one shot so that's what i'm looking into now.

We'll get to that. I was originally wanting to do that, but let's take the steps we need before you get there. "While" will have its own challenges that require us making sure the user doesn't miss or select the wrong object. Let's be sequential about this and not get ahead of ourselves. Deal?

I'm trying to not only give you a knowledge of how to do this, but show you how to write decent code from the beginning. This all takes time. You can't be expected to run when you haven't learned to walk. I'm teaching you how to walk, but I want you to see what happens when things don't work quite as expected. IOW, I want to put some roadblocks in your way to trip you and teach you how to walk better, faster.