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

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
text move lisp in need of enhancement
« Reply #45 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?

daron

  • Guest
text move lisp in need of enhancement
« Reply #46 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:

ELOQUINTET

  • Guest
text move lisp in need of enhancement
« Reply #47 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)
)

daron

  • Guest
text move lisp in need of enhancement
« Reply #48 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.

ELOQUINTET

  • Guest
text move lisp in need of enhancement
« Reply #49 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

ELOQUINTET

  • Guest
text move lisp in need of enhancement
« Reply #50 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:

ELOQUINTET

  • Guest
text move lisp in need of enhancement
« Reply #51 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?

ELOQUINTET

  • Guest
text move lisp in need of enhancement
« Reply #52 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?

daron

  • Guest
text move lisp in need of enhancement
« Reply #53 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.