how to get this lsp to work?

Discussion in 'AutoCAD' started by stephen4444, Dec 23, 2003.

  1. stephen4444

    stephen4444 Guest

    (command "LINE" P1 P2 "")(setq MV1 (ENTLAST))
    (command "LINE" P3 P4 "")(setq MV2 (ENTLAST))
    (command "LINE" P5 P6 "")(setq MV3 (ENTLAST))
    (if (= MV1 nil)(null MV1))
    (if (= MV2 nil)(null MV2))
    (if (= MV3 nil)(null MV3))
    (if (/= nil)(command "MOVE" MV1 "" P1 P7))
    (if (/= nil)(command "MOVE" MV2 "" P3 P7))
    (if (/= nil)(command "MOVE" MV3 "" P5 P7))

    What I am trying to do is:
    If a line is drawn from P1 to P2 then move MV1 from P1 to P7.
    If a line is NOT drawn from P1 to P2 then DONT move MV1 from P1 to P7. (same for MV2 & MV3)

    But the problem I am having is:
    After I run the command like line from P1 to P2 it moves fine to MV1.
    Then if I run the command again like line from P3 to P4 it moves to MV2, but entity MV1 move again!

    Even though MV1, MV2, & MV3 entities are defined,
    how can I only move MV2 but not the others? or undefine entities MV1 & MV3? or rewrites so it does the same thing.

    Hope I'm making sense.

    TIA
     
    stephen4444, Dec 23, 2003
    #1
  2. If you are going to draw the line via lisp, then why not draw it in
    the correct location to begin with?

    To answer your question though, your if statements are a bit out of
    sorts.

    Again, without seeing all that you are trying to accomplish, given
    what you are showing there is no need to evaluate MV1, 2, and 3
    because they're always going to be set to a line entity.

    Below shows what your if statements should look like given your
    example.

    (command "LINE" P1 P2 "")
    (setq MV1 (ENTLAST))
    (command "LINE" P3 P4 "")
    (setq MV2 (ENTLAST))
    (command "LINE" P5 P6 "")
    (setq MV3 (ENTLAST))
    (if MV1
    (command "MOVE" MV1 "" P1 P7)
    )
    (if MV2
    (command "MOVE" MV2 "" P3 P7)
    )
    (if MV3
    (command "MOVE" MV3 "" P5 P7)
    )
    --
    Ken Alexander
    Acad2000
    Windows2000 Prof.

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein

    to MV2, but entity MV1 move again!
    MV1 & MV3? or rewrites so it does the same thing.
     
    Ken Alexander, Dec 23, 2003
    #2
  3. stephen4444

    stephen4444 Guest

    thx for the reply.
    (that wasn't what I was looking for)
    well, let me try ask the question differently.

    (setq MV1 (entlast))
    How do you undefine MV1? or is possible in lsp?
     
    stephen4444, Dec 23, 2003
    #3
  4. (setq MV1 nil) also make the variables local.
    --
    Ken Alexander
    Acad2000
    Windows2000 Prof.

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Dec 23, 2003
    #4
  5. stephen4444

    stephen4444 Guest

    I try that already, but was not working.

    finally I got it to work..!!
    I just have to redefine MV2:
    (setq MV2 MVV) instead (setq MV2 nil)
    MVV (new function but just not been used anywhere)

    thanks for the help.
     
    stephen4444, Dec 23, 2003
    #5
  6. stephen4444

    Paul Turvill Guest

    But...but...If MVV hasn't been "used before," then its value is nil; so
    (setq MV2 MVV)
    is equivalent to
    (setq MV2 nil)
    ___
     
    Paul Turvill, Dec 23, 2003
    #6
  7. I'm not sure what isn't working, but in the following code MV1 and
    MV2 will move. MV3 will not.

    (command "LINE" P1 P2 "")
    (setq MV1 (ENTLAST))
    (command "LINE" P3 P4 "")
    (setq MV2 (ENTLAST))
    (command "LINE" P5 P6 "")
    (setq MV3 (ENTLAST))

    (setq MV3 nil)

    (if MV1
    (command "MOVE" MV1 "" P1 P7)
    )
    (if MV2
    (command "MOVE" MV2 "" P3 P7)
    )
    (if MV3
    (command "MOVE" MV3 "" P5 P7)
    )
    --
    Ken Alexander
    Acad2000
    Windows2000 Prof.

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Dec 23, 2003
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.