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

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

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

daron

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

ELOQUINTET

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

daron

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

daron

  • Guest
text move lisp in need of enhancement
« Reply #34 on: August 08, 2005, 10:08:54 AM »
alright Dan. Here're some old posts you might read a bit.

Object/Entity race
Similar to above. Look for a grain of salt in that one.

This one you'll want to pay attention to. 12,450 Layers 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.

ELOQUINTET

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

daron

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

ELOQUINTET

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

daron

  • Guest
text move lisp in need of enhancement
« Reply #38 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:
    create a function that works
    figure out the difference between local and global variables.
    dive into the function and show where errors are likely to occur and discuss ways to overcome them.
    work looping into code where necessary
    discuss and apply different iteration techniques
    discuss and apply reusable code without required arguments
    discuss and apply reusable code with required arguments
    [/list:u]
    3) Absorbtion comes from repetition. You stick with it and you'll start to get it. This is at your pace. You can't be taught faster than you have the ability to learn. That is of course why I ask you to look up things and put an answer to them in your own words. I realize they won't be accurate and maybe you won't even understand it from the help files. I know I didn't. In my first year, I was still asking quesitons about things that I couldn't make sense of from the help file. It's not until it was shown to me and I tried it out in a FEW ways that I really got it. Don't worry about your absorbtion ability. You are getting this. I still have to ask questions on different functions. You will too, always.
    4)You're wrong. It is working. I see in you exactly as I remember myself when I started learning. It all seemed so overwhelming. The way we've gone about this task is complex. I wish I knew what the first piece of code I wrote was. It was nothing like this. You're doing well.

ELOQUINTET

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

daron

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

ELOQUINTET

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

daron

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

ELOQUINTET

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

daron

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