TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ELOQUINTET on August 02, 2005, 01:57:03 PM

Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 02, 2005, 01:57:03 PM
i was working on this lisp with daron but had to take a little break. now i am ready to give it some enhancements and need some hints. here is a list of things which need improving:

1 the text is left justified so it first needs to be converted to center so when it is moved it is centered

2 this routine currently only works on horizontal dimensions but also needs to work on vertical and aligned.

that's all i can come up with right away. can daron or anyone help me continue this exercise.

Code: [Select]
;;pick the text using the node as the point
;;then move the text to the midpoint of the dimension line
;;then move the text down 3-1/2
(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))
  )
  (setq   dimentity (car (entsel "\nSelect dimension: "))
   dimlist     (entget dimentity)
   pt2     (cdr (assoc 11 dimlist))
  )
  (setq   txtxcoord (car pt2)
  )
  (setq   txtycoord (cadr pt1)
  )
  (setq   pt3 (list txtxcoord txtycoord 0)
  )
  (command "move" pt1 "" pt1 pt3)
  (setvar 'osmode osm)
  (princ)
)
Title: text move lisp in need of enhancement
Post by: daron on August 02, 2005, 01:58:56 PM
Dan, if we could get back to where we left off, you'd have what you need, except the text justification portion, all of which, I've been waiting to continue with.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 02, 2005, 02:27:49 PM
i thought we touched on the angle and polar functions in order to be able to do other dim types but never really applied them. i will read over them now to try to make sense of them. should i look at how testing is done using if and then or cond or is it too early to explore that. i'm not sure about the structuring of that so i may have a peak. thanks for returning to help me finish this off by the way.
Title: text move lisp in need of enhancement
Post by: daron on August 02, 2005, 03:16:55 PM
I just went through a discourse on all we have left, but closed that tab accidentally. I don't have time to rewrite it, but will later. In the mean time, I'd like to get this discussion back on the previous lesson, so as to keep everything in one place. We are going to be getting into constant, variable and included angles. I believe the word theta comes to play. To see what I mean, look at >this< (http://www.smadsen.com/tech1002.htm#3.7) taken from Stig's website (http://www.smadsen.com).
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 02, 2005, 04:17:25 PM
ok i've read through it and duplicated his drawing but i get lost when i reach the math part as i didn't get very far in math. my problem with all of this is that i have trouble interpretting named data without having to go back and see what the values are and then when i get back to the summarized part i forget what i was looking at and why. i guess the more code i look at the easier it will be to process (somethings are already easier) but right now that's too much for me to process. i think i understand the need for it in my routine. the line in this example would be my dimension line and selecting that line would apply pt1 and pt2 to its endpoints and extract the angle whatever it maybe. am i close???
Title: text move lisp in need of enhancement
Post by: daron on August 02, 2005, 04:33:04 PM
Very. However, I didn't expect you to duplicate what he had. I'm not to familiar with theta myself, but the word is in there and implies your included angle which I mean angle (GC14 GC13) from (GC14 GC10). All we then have to do is find out whether or not the included angle is positive or negative and we know which direction to go. When we finish, you'll see that it's far easier than it sounds and Stig's example I sent you to will look like MAJOR overkill, but then we're only taking a very small portion of it.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 02, 2005, 04:36:40 PM
i notice that pt1 and pt2 are interpreted differently depending on which end i choose to draw the line from and the same for the dimension. if i start from the bottom it interprets the bottom point as pt1 and the top as pt2 but if i draw the line from top to bottom it does the reverse. and how does the circle play into my routine because if the dimension doesn't cross the circle it picks the point on the dimension line just below the text. is this so if the dimension text is out of the default position it will still put the text below it?
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 02, 2005, 04:41:47 PM
it wasn't hard to duplicate and seeing it in action and playing with it helped me better analyze why we would need it. i need all the visual aids i can get  :)
Title: text move lisp in need of enhancement
Post by: daron on August 02, 2005, 04:51:17 PM
You're taking too much of his example into it. All you need from his example, besides the fact that everything comes down to angles and circles is the theta or included angle. Chew on this for a bit and explain it:
Code: [Select]

     (setq constangle (angle dimassoc14 dimassoc10)
      varangle   (angle dimassoc14 dimassoc13)
      inclangle  (- constangle varangle)
     )

As well, this portion that we already have:
Code: [Select]
(setq txt2dimang (angle dimassoc10 dimassoc14)
So, you see, you're right, we do need GC10 and 14 going both ways? Why? I'll answer: 14 to 10 allows you to get the included angle when you subtract GC14 and 13 from it. 10 to 14 gives you the angle we need and the point from which to go from.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 02, 2005, 07:59:36 PM
i knew not all of it applied but wasn't sure which did and which didn't but believe your hint will help me. i need to look at that and then look back to see what 10 13 and 14 refer to then apply it. i'll be chewin that tonight (and hopefully not gagging) and will give my interpretation tomorrow.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 03, 2005, 09:44:57 AM
ok daron i've digested those bits. so essentially we will be aquiring 3 point which can be used to determine the angle of the dimension. we will determine constangle. then varangle then subtract varangle to get the inclangle. correct?
Title: text move lisp in need of enhancement
Post by: daron on August 03, 2005, 02:28:22 PM
Yes. I'm not ignoring you today. I just have something that's not working, so sometimes it's best to get away from it.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 03, 2005, 02:33:36 PM
it's alright daron i kinda felt like i was ignoring you because my boss is not in today so i have been developing some dynamic blocks. i'm trying to figure out what keeps triggering this fatal error i get after adding a stretch param when my blocks get complicated. anyway no worries do whatcha gotta do.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 04, 2005, 09:40:24 AM
daron i tried to plug in the info you gave me but i dont think i got it quite right. the lisp loads fine but when i select the dimension it returns this message:

Select dimension: ; error: bad argument type: 2D/3D point: nil

Code: [Select]
;;pick the text using the node as the point
;;then move the text to the midpoint of the dimension line
;;then move the text down 3-1/2
(defun c:MTO2 ( / txtentity txtlist dimentity dimlist txtxcoord txtycoord txt2dimang constangle varangle inclangle pt1 pt2 pt3)
 
    (setq osm (getvar 'osmode))
    (setvar "osmode" 0)
    (setq txtentity (car (entsel "\nSelect text: "))
  txtlist  (entget txtentity)
pt1  (cdr (assoc 10 txtlist))
  )
    (setq dimentity (car (entsel "\nSelect dimension: "))
dimlist  (entget dimentity)
pt2  (cdr (assoc 11 dimlist))
  )
    (setq txtxcoord (car pt2)
  )
    (setq txtycoord (cadr pt1)
  )
    (setq pt3 (list txtxcoord txtycoord 0)
  )
    (setq txt2dimang (angle dimassoc10 dimassoc14)
  )
    (setq constangle (angle dimassoc14 dimassoc10)
  )
    (setq varangle   (angle dimassoc14 dimassoc13)
  )
    (setq inclangle  (- constangle varangle)
  )
    (command "move" pt1 "" pt1 pt3)
    (setvar 'osmode osm)
  (princ)
)
Title: text move lisp in need of enhancement
Post by: daron on August 04, 2005, 09:52:45 AM
Well, it will be somewhat flawed still, but when issuing the command "Move", your first variable should be an ename, not an elist and definately not a sublist within that list, which is what you've supplied. By the end of the day, I should have something to take us to the next level. I think you're starting to get the idea here though. Have you looked at Entmod, Subst and Entupd? Please do and post your understandings. Also, read up on if and cond. Again, post your findings.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET 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.
Title: text move lisp in need of enhancement
Post by: daron 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.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET 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?
Title: text move lisp in need of enhancement
Post by: daron 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.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET 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)
)
Title: text move lisp in need of enhancement
Post by: daron 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)
)
Title: text move lisp in need of enhancement
Post by: ELOQUINTET 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)
)
Title: text move lisp in need of enhancement
Post by: daron 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.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET 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)
Title: text move lisp in need of enhancement
Post by: ELOQUINTET 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)
  )
Title: text move lisp in need of enhancement
Post by: daron 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.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET 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.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET 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.
Title: text move lisp in need of enhancement
Post by: daron 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?
Title: text move lisp in need of enhancement
Post by: daron 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.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 05, 2005, 02:09:37 PM
i know i won't learn this overnight and i side with you for the most part. i just wish i could convince my boss that this is the logical next step rather than while. i will look through the routines i have to make sure i grasp if and cond. then like i said i will try taking command out. by the way when tried your challenge drawing a line saving then running the routine it moved the text to the end of the line. when i hit undo it moved the text back but left the line? maybe i'm missing something ?? i understand what you were saying about moving txtentity not pt1.
Title: text move lisp in need of enhancement
Post by: daron on August 05, 2005, 02:14:28 PM
It sounds like you saved AFTER you drew the line. Save BEFORE you draw the line, THEN draw the line, then run each command, undoing them before proceeding to the next. If that doesn't work, just draw a line and run my version. You will see the line disappear eventually.

As far as your boss goes: Who's learning this stuff here, you or her? If she wants to learn it, get her in here. I don't have a problem with that, but you are going to learn things differently than she will and you both will learn things differently than anybody else.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 05, 2005, 03:46:31 PM
ok i tried it. when i try mine when i select dimension it appears to mirro the line. then when i try your it appears to delete the line and leave a point on the right end of where the line used to be. i gotta tell ya i'm pretty lost right about now and getting kind of frustrated by the whole thing. it might have something to do with it being friday and me wanting a beer anyway  :P not sure what you're trying to show me???
Title: text move lisp in need of enhancement
Post by: daron on August 08, 2005, 07:39:03 AM
I don't know why it would mirror yours, unless you mirrored the line before you ran your command. It shouldn't do anything to the line on your routine. On my version of it however, the deletion of the line is supposed to happen. I don't know where the point is coming from, unless you have blip-mode on. Sooo, what I'm trying to show you is this: Your code has a command line in it and mine does not. Therefore, Autocad does not recognize mine as a command and when you undo mine, it undoes that routine and the command before it. So, you saw nothing happen to the line the first time you ran my version. I believe that's because you saved the drawing after drawing the line OR before calling the routine. Just like making sure OSMODE is set to 0 before running the routine, we can make sure autocad views this as a command. We have a couple of options here. At the beginning of the routine we can add this (command ".undo" "be") and at the end add (command ".undo" "e") or if we want to leave the transparent functionality of my version, we could give you your first taste of ActiveX.

Before we do, another test. Without the command lines in place draw a line. This time pick the first point, but not the second. At this time invoke my version transparently (with an apostrophe in front of it), then when you've finished moving the text to the dimension, while cad is still waiting for the next point, try invoking your version transparently. What you should be understanding here is that if ever you desire a command to be able to be used transparently, you cannot have command in the code. ActiveX will give us the ability to set the undo flags without using command. Why would we want this to be able to be transparent? No reason, just thought I'd show that it's possible and try to explain how, just in case you ever have code where you'd want that functionality. Be back shortly with more info.
Title: text move lisp in need of enhancement
Post by: daron on August 08, 2005, 10:08:54 AM
alright Dan. Here're some old posts you might read a bit.

Object/Entity race (http://www.theswamp.org/phpBB2/viewtopic.php?t=55&postdays=0&postorder=asc&highlight=command&start=0)
Similar to above. (http://www.theswamp.org/phpBB2/viewtopic.php?t=164&postdays=0&postorder=asc&highlight=command&start=0) Look for a grain of salt in that one.

This one you'll want to pay attention to. 12,450 Layers (http://theswamp.org/phpBB2/viewtopic.php?p=439&sid=464a5f199ef076fad538e11570e947c6#439) What Ted's talking about there, if you read that entire thread is the code I used had command in it as it's main layer creation function and it couldn't get past 30 layers. What I'm then saying is that often times it's okay to use command, but you need to beware that it A) tends to not be as quick as other functions like entmake or entmod and B) if put to a real memory crunch will just fail, like in the last link.

Forgot to add this:
Code: [Select]
;;;===================================================================;
;;; UNDO GORUPING FUNCTIONS                                           ;
;;;===================================================================;
(defun vl-UndoBegin ()
  (vla-StartUndoMark
    (vla-get-activedocument
      (vlax-get-acad-object)
    )
  )
)
(defun vl-UndoEnd ()
  (vla-EndUndoMark
    (vla-get-activedocument
      (vlax-get-acad-object)
    )
  )
)

Don't know who wrote that, but anybody could. What you do is put that like (vl-UndoBegin) somewhere in the beginning of the code and (vl-UndoEnd) somewhere in the end of the code. You can put the code blocks either within the routine we're creating or outside it as long as they can be loaded. These, I'd put outside the main code, so other code can call them.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 08, 2005, 12:08:42 PM
daron first thing i think you need to understand is that this elevtion is completely drawn by a custom app. i just put in the info into a dialogue and it's completely drawn. i don't want to perform the test you were asking me to perform because these dimensions are not being created one by one anyway. but i do understand the value of not using command in a routine unless absolutely neccesary. i am honestly feeling buried with information and not sure in what order i should be trying to absorb all of this. to maintain some kind of structure i have mostly been following stigs tutorial. i appreciate you and my boss trying to push me but i don't feel like i have the ability to absorb things this fast or maybe i need to learn this in a more structured manner. all i know is this isn't exactly working  :?:
Title: text move lisp in need of enhancement
Post by: daron on August 08, 2005, 12:51:14 PM
Dan, I'm going to have to fully DISagree with you, that you're not getting this. Look what you've done so far:
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)
  )

This is good code. compare this to some of my early work.
Code: [Select]
(defun c:blocktypedel ()
     (setq ent (car (entsel "\nSelect block to delete: "))
  elist (entget ent)
  bname (assoc 2 elist)
     ) ;_ end of setq
     (setq ss  (ssget "x" (list bname))
  cnt 0
     ) ;_ end of setq
     (repeat (sslength ss)
 (setq ename (ssname ss cnt)
cnt   (1+ cnt)
 ) ;_ end of setq
 (command "_erase" ename "")
     ) ;_ end of repeat
     (princ)
) ;_ end of defun

and that's NOT my first code. Look what's missing, all variables are global. That's bad. If the user misses, the code errors out and I'd have to start the command again. I'm using command. This would most likely take more time than if I were to use entdel. I'd probably also make better use of functions by converting the pickset (from ssget) to list entities and using foreach or mapcar lambda functions. There's virtually no error trapping done on this code. It works, but it's not good code. Your code is much more complex and you've already got a good start. The only way to start retaining any of what I or anybody else says, including Stig's tutorial's is to apply it. Not just once, but repeatedly.

I have an idea and feel that we should probably take it to a private forum?
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 08, 2005, 01:52:30 PM
yeah well i've been hangin around here for long enough that i have a vague idea how to do this but when many things are thrown at me at once i have a hard time because i'm not sure what to digest first and not sure how to apply it to this example. i was trying to use while in between picking pt1 and pt2 to make sure a point was picked then trying to loop it (both without success) as i am reading the end of lesson 4 of stigs tutorial. what do you mean by taking it to a private forum?
Title: text move lisp in need of enhancement
Post by: daron on August 08, 2005, 02:24:34 PM
I've sent a PM to Mark to see if I could resurrect the LispCourse and maybe build some code with it, but it seems that the examples in the end of each lesson should be well enough.

As far as the while loop goes, you're going to not have success at this time. There are a few things you need to do before you get to that point and a few things you need to know in order to make the while loop work for what you're doing. You can't just wrap the working code in a while function and call it good. You need to know what while will accept and how to get out of a while loop.

Quote
1) i am honestly feeling buried with information and not sure in what order i should be trying to absorb all of this. 2) to maintain some kind of structure i have mostly been following stigs tutorial. 3)i appreciate you and my boss trying to push me but i don't feel like i have the ability to absorb things this fast or maybe i need to learn this in a more structured manner. 4) all i know is this isn't exactly working

1) You will feel buried, but you will rise to the top as we (<-that is plural) work through this. I and everyone else, I'm sure, knows what you're going through. My original intention is to get you doing things repeatedly on different routines. This will help.
2) I realize that and they are great tutorials. I too am trying to follow some kind of structure. It's just not as clear to you and a couple of times you've gotten out ahead of me. Stay with me and do your best to answer the questions and try the challenges I put to you. If you want, here's a bit of a guide I've been trying to follow:
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 09, 2005, 10:48:08 AM
daron here's what i have right now but not sure where to go with it now. i don't know if i added the undo functions correctly or not and before that it wasn't working using entmod. if i remember correctly it allowed me to select both text and dimension but did not move the text? anyway i'm just wondering where to go from here?

Code: [Select]
;;;===================================================================;
;;; UNDO GROUPING FUNCTIONS                                           ;
;;;===================================================================;
(defun vl-UndoBegin ()
  (vla-StartUndoMark
    (vla-get-activedocument
      (vlax-get-acad-object)
    )
  )
)
(defun c:MTOD ( / txtentity txtlist dimentity dimlist txtxcoord txtycoord pt1 pt2 pt3 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)
)
(defun vl-UndoEnd ()
  (vla-EndUndoMark
    (vla-get-activedocument
      (vlax-get-acad-object)
    )
  )
)
Title: text move lisp in need of enhancement
Post by: daron on August 09, 2005, 11:47:40 AM
In giving you that code, we need to skip around a bit. Here's where were at with the undo functions:
Quote
discuss and apply reusable code without required arguments

Think of every program written as a function. Here's (http://en.wikipedia.org/wiki/Function_(programming)) a wiki on functions and subroutines. Then look at the end of pg. 6 and beginning of page 7 on lesson 1. You can CALL these functions at any point, but they do need to be called. I've taken care of it for you, but you could put them in a different place.
Code: [Select]
;;;===================================================================;
;;; UNDO GROUPING FUNCTIONS                                           ;
;;;===================================================================;
(defun vl-UndoBegin ()
  (vla-StartUndoMark
    (vla-get-activedocument
      (vlax-get-acad-object)
    )
  )
)

(defun vl-UndoEnd ()
  (vla-EndUndoMark
    (vla-get-activedocument
      (vlax-get-acad-object)
    )
  )
)
(defun c:MTOD ( / txtentity txtlist dimentity dimlist txtxcoord txtycoord pt1 pt2 pt3 osm)
    (vl-UndoBegin);calling the external function here
     (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)
     )
     )
   ;we could however, call the (vl-undobegin) function here.
     (entmod (subst (cons 10 pt3) (cons 10 pt1) txtlist))
     (entupd txtentity)
  ;and call (vl-undoend) here
     (setvar 'osmode osm)
     (vl-UndoEnd) ;but I thought this was a fine placement for it
     (princ)
)

Let me know if you still don't understand it after looking into this: I'll give you more. I know these can be confusing at first. It get's harder before it gets easier, but don't despair, it does get easier.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 10, 2005, 09:23:31 AM
hey daron sorry i haven't been contributing much the past couple days i have been busy trying to get to a good stopping point on some dynamic blocks i had started developing. so now i'm ready to jump back into this i think. i was reading through the code and reading the link. so are we inserting these vl-undo markers so if the user decides to undo it will do so in increments. i was looking in help but couldn't find info about this?
Title: text move lisp in need of enhancement
Post by: daron on August 10, 2005, 09:33:26 AM
Remeber the test about the line and the removal of that line when you thought you were just undoing this function? The vl-undo functions keep us from removing items inadvertently. Yes, they are like markers, but you only should need them in two places. It's up to you to determine where in any code.

So, are you all clear as to how to call external functions?
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 10, 2005, 09:49:08 AM
the method seems pretty clear but an explaination of why we place them externally would be nice. i see that one use is so the writer can reuse the code without arguments. hey now i get what you mean  :wink: but what are some other benefits?
Title: text move lisp in need of enhancement
Post by: daron on August 10, 2005, 10:13:00 AM
Wrong use of the word "argument", but good try. Funny. To place the code "externally" does allow you to call them from other functions as well. It's like making it a Global function, meaning ever-present. Of course, it has to be loaded for that to work too. There can be a big debate on whether or not you should create them externally or internally (globally or locally), but I'm going to let you be your own guide on that one. Just keep this in mind: The more things you make global, the more things you load, the more memory suffers because of it. Be careful of what you decide is global. If you think it'll always be getting called/used, then it probably good to make it global, otherwise localize it. By localizing it, making it internal, you don't load it until you call the routine that contains it. I believe it'll clear it from memory once it's done too. To localize it, just put the undo defuns just under the calling defun and before any other code that would need to use it. Now, why do we use functions? Let's say you have a piece of code you keep writing over and over in the same block and there are few or no variations? I would be easier to create a function and call that function each time than to keep writing the same code. Plus, it will shrink the main code down considerably. Let's make sure you've got some understanding of this before you move into adding arguments. I think we need to step back a bit though. Keep all that in mind. We'll get back to it a bit later. Right now let's focus on this:
Quote
dive into the function and show where errors are likely to occur and discuss ways to overcome them.

Where's the first place you might see the function stop working prematurely? Hint: It usually happens when we allow the user to do anything.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 10, 2005, 10:41:33 AM
ok i think i think i follow that. i think the first point the function would fail is if the user misses the text selection. i was trying to insert something after that at some point which looked for the value of assoc 10 but couldn't get that to work. what would be the best way of checking to see what the user selected and how do you let the user reselect as you wouldn't want it to simply exit?
Title: text move lisp in need of enhancement
Post by: daron on August 10, 2005, 11:05:45 AM
Quote
as you wouldn't want it to simply exit?
unless they hit escape, which we'll get to another time.
Glad you asked otherwise. There are a number of ways. First I'm going to show you a simple one.
Code: [Select]

(while (not (setq txtentity (car (entsel "\nSelect text: "))))
   (princ "\nYou missed. Try again.")
)
(setq txtlist... etc.)

Try that out a bit.
Quote from: While Help
Evaluates a test expression, and if it is NOT nil, evaluates other expressions; repeats this process until the test expression evaluates to nil
IOW, taking the above example, while txtentity is not true (or returns nil) let the user know and repeat this test until the user picks an object. Does that help?

Now, test this out a bit. It still has a bug. Entsel has this problem where it allows you to pick any object and there seems to be no way of letting it know you want to force your user to only select a certain type of object. We'll tackle that one when we get a bit further down the road okay. As for now, have you noticed, we're taking on two birds with one stone.
Quote
dive into the function and show where errors are likely to occur and discuss ways to overcome them.
work looping into code where necessary

There are three places we'll do some iterating/looping. I want you to make the next move on making sure a user doesn't miss. Post your code. Test out each block. Miss on purpose, just to see it in action. That will help it all click. After you do that, we'll see what we can do to make the whole thing get real loopy :horror:
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 10, 2005, 11:32:28 AM
daron below is my revised code but i have a couple questions. i see a few problems. first, like you say it allows me to select whatever entities i want it doesn't check to make sure it is the text. second problem if i completely miss i get the message but also an error and it closes. the last problem is the code doesn't even work even if i select everything correctly using entmod. anyway here's my attempt

error message i get:

Select text:
You missed the text, Try again.; error: bad argument type: lentityp nil


Code: [Select]
;;;===================================================================;
;;; UNDO GROUPING FUNCTIONS                                           ;
;;;===================================================================;
(defun vl-UndoBegin ()
  (vla-StartUndoMark
    (vla-get-activedocument
      (vlax-get-acad-object)
    )
  )
)

(defun vl-UndoEnd ()
  (vla-EndUndoMark
    (vla-get-activedocument
      (vlax-get-acad-object)
    )
  )
)
(defun c:MTOD ( / txtentity txtlist dimentity dimlist txtxcoord txtycoord pt1 pt2 pt3 osm)
    (vl-UndoBegin);calling the external function here
     (setq osm (getvar 'osmode))
     (setvar "osmode" 0)
  (while (not (setq txtentity (car (entsel "\nSelect text: "))))
   (princ "\nYou missed the text, Try again.")
      txtlist   (entget txtentity)
      pt1        (cdr (assoc 10 txtlist))
      x1        (car (assoc 10 txtlist))
      y1        (cadr (assoc 10 txtlist))
     )
  (while (not (setq dimentity (car (entsel "\nSelect Dimension: "))))
   (princ "\nYou missed the dimension, Try again.")
      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)
     )
     )
   ;we could however, call the (vl-undobegin) function here.
     (entmod (subst (cons 10 pt3) (cons 10 pt1) txtlist))
     (entupd txtentity)
  ;and call (vl-undoend) here
     (setvar 'osmode osm)
     (vl-UndoEnd) ;but I thought this was a fine placement for it
     (princ)
)
Title: text move lisp in need of enhancement
Post by: daron on August 10, 2005, 11:52:47 AM
Okay, slow down pardner.
Let's look at this real quick like.
Code: [Select]

  (while (not (setq txtentity (car (entsel "\nSelect text: "))))
   (princ "\nYou missed the text, Try again.")
      txtlist   (entget txtentity)
      pt1        (cdr (assoc 10 txtlist))
      x1        (car (assoc 10 txtlist))
      y1        (cadr (assoc 10 txtlist))
     )

Code: [Select]
(while (not (setq txtentity (car (entsel "\nSelect text: "))))
   (princ "\nYou missed. Try again.")
)
(setq txtlist... etc.)

Do you see a difference there. The only thing you want in the while code is the expression to evaluate, then the princ function. Nothing else. Study the differences between code blocks here and fix yours to work.
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 10, 2005, 12:43:55 PM
daron i was trying to fully comment this to make sure i understood what each part was doing and now i'm getting malformed list. the only bit i don't get is the entmod line. i know cons adds an item to the beginning of a list or creates a dotted pair. i guess we are doing the latter. then substituting one for the other using subst. then modifying the entity using entmod. i think my problem is i'm not sure what the result of the cons functions are so i'm lost on what exactly i'm substituting here? just wanna figure this out. i checked all of my parens but can't fing my problem. is there something wrong with the way i commented other than overkill  :lol: i just want to print it out to review if i get lost or to refer to later on down the road. anyway here's my code:

Code: [Select]
;;;===================================================================;
;;; UNDO GROUPING FUNCTIONS                                           ;
;;;===================================================================;
(defun vl-UndoBegin ()
  (vla-StartUndoMark
    (vla-get-activedocument
      (vlax-get-acad-object)
    ) ; closes vla-get-activedocument
  ) ; vla-StartUndoMark
) ; closes defun vl-UndoBegin ()

(defun vl-UndoEnd ()
  (vla-EndUndoMark
    (vla-get-activedocument
      (vlax-get-acad-object)
    ) ; vla-get-activedocument
  ) ; vla-EndUndoMark
) ; closes defun vl-UndoEnd ()
(defun c:MTOD ( / txtentity txtlist dimentity dimlist txtxcoord txtycoord pt1 pt2 pt3 osm) ; declare locals
    (vl-UndoBegin) ; calling the external function here
     (setq osm (getvar 'osmode)) ; saving current osnaps
     (setvar "osmode" 0) ; setting osnaps to 0
  (while (not (setq txtentity (car (entsel "\nSelect text: ")))) ; prompt user to select text until proper selection is made
   (princ "\nYou missed the text, Try again.") ; alert if wrong entity is selected
    ) ; closes while
   (setq txtlist   (entget txtentity) ; making a list of entities properties "txtlist"
      pt1        (cdr (assoc 10 txtlist)) ; take out first item in list leaving only coordinates "pt1"
      x1        (car (assoc 10 txtlist)) ; extract first value "x coordinate" from pt1  
      y1        (cadr (assoc 10 txtlist)) ; extract second value "y coordinate" from pt1
     ) ; closes setq
  (while (not (setq dimentity (car (entsel "\nSelect Dimension: ")))) ; prompt user to select dimension until proper selection is made  
   (princ "\nYou missed the dimension, Try again.") ; alert if wrong entity is selected  
    ) ; closes while
   (setq dimlist   (entget dimentity) ; making a list of entities properties "dimlist"
      pt2        (cdr (assoc 11 dimlist)) ; take out first item in list leaving only coordinates "pt2"
      x2        (car (assoc 11 dimlist)) ; extract first value "x coordinate" from pt2  
      y2        (cadr (assoc 11 dimlist)) ; extract second value "y coordinate" from pt2
     ) ; closes setq
     (if (< y1 y2); if statement
     (setq   txtxcoord (car pt2) ; beginning of then statement: extract first value "x coordinate" from pt2  
      txtycoord (cadr pt1) ; extract second value "y coordinate" from pt1  
      pt3     (list txtxcoord txtycoord 0.0) ; create a list "pt3" from the values for txtxcoord and txtycoord
     (setq   txtxcoord (car pt1) ; beginning of else statement: extract first value "x coordinate" from pt1
      txtycoord (cadr pt2) ; extract second value "y coordinate" from pt2  
      pt3     (list txtxcoord txtycoord 0.0) ; create a list "pt3" from the values for txtxcoord and txtycoord
     ) ; closes else statement
     ) ; closes if statement
   ;we could however, call the (vl-undobegin) function here.
     (entmod (subst (cons 10 pt3) (cons 10 pt1) txtlist)) ; i don't understand this line
     (entupd txtentity) ; updates properties of txtentity
  ;and call (vl-undoend) here
     (setvar 'osmode osm) ; resets osnaps
     (vl-UndoEnd) ; but I thought this was a fine placement for it
     (princ) ; silent exit
) ; closes defun
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 10, 2005, 12:49:58 PM
hmmm got rid of all the comments and still malformed. my brain is beginning to become malformed  :shock:
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 10, 2005, 12:58:03 PM
aha found it i didn't close my then statement. now the while is working but it is still not moving the text. should i examine those lines or do we need to feed it more info before it knows what we're asking it to do?
Title: text move lisp in need of enhancement
Post by: ELOQUINTET on August 15, 2005, 10:00:55 AM
hey daron haven't seen you around here. are you still willing to help me finish this lisp off? i was never able to figure out why entmod wasn't working but would like to use that method. i would also like the code to loop but not sure how to do that. how do you make it so the user can select as many text objects as they want. what would be the best method to be able to select as much text as needed then dimensions or just have it repeat after a dimension is selected?
Title: text move lisp in need of enhancement
Post by: daron on August 21, 2005, 11:38:11 PM
Sorry, been awol this past week. Doesn't look like it'll pick up any time soon. It seems you've got other threads started and I'm glad others have been helping.