Author Topic: can't get lisp to work correctly  (Read 2357 times)

0 Members and 1 Guest are viewing this topic.

jermjmm

  • Guest
can't get lisp to work correctly
« on: October 24, 2008, 05:02:44 PM »
Hey all,
I've been working on this lisp for a while but I just can't seem to get it to work perferctly.  it's supposed to insert a block on a line, but it doesn't always put it exactly on the line and I don't have a clue as to why its not.
In the zip file I've included the lisp, a pic of what it's doin and the block.

Any help would be greatly appreciated.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: can't get lisp to work correctly
« Reply #1 on: October 24, 2008, 05:07:12 PM »
Since it's a dynamic block, you should just add an alignment parameter.  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jermjmm

  • Guest
Re: can't get lisp to work correctly
« Reply #2 on: October 24, 2008, 05:15:06 PM »
yes, I like that Idea (and have just added that to the block), but that still doesn't solve the problem of it not being put on the line correctly, that just makes it easier to fix.

jermjmm

  • Guest
Re: can't get lisp to work correctly
« Reply #3 on: October 24, 2008, 05:29:23 PM »
i just had an idea presented to me that seems to work.  changing the line (command "-insert" "ball valve" "s" x1 pt3 ang) to (command "-insert" "ball valve" "s" x1 "nea" pt3 ang)

don't know if this is the correct way to fix it, but it seems to work.

Greg B

  • Seagull
  • Posts: 12417
  • Tell me a Joke!
Re: can't get lisp to work correctly
« Reply #4 on: October 24, 2008, 05:40:18 PM »
Code: [Select]
(cadr ent1)

What does "cadr" means as I see "cdr" elsewhere but no "cadr".

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: can't get lisp to work correctly
« Reply #5 on: October 24, 2008, 05:48:40 PM »
See if this works:
Code: [Select]
(DEFUN C:VA (/ old x1 ent1 p1 p2 pt3 ang)
  (vl-load-com)
  (SETQ OLD    (GETVAR "OSMODE")
        oldlay (getvar "clayer")
  )
  (SETVAR "OSMODE" 512)
  (COMMAND "CMDECHO" 0)
  (SETQ x1   (GETVAR "DIMSCALE")
        ent1 (entsel "\nPick Insertion point")
        el1  (entget (car ent1))
        p1   (cdr (assoc 10 el1))
        p2   (cdr (assoc 11 el1))
        pt3  (vlax-curve-getClosestPointTo (car ent1) (cadr ent1))
        ang  (* 180.0 (/ (angle p1 p2) PI))
  )
  (if pt3
    (progn
      (setvar "clayer" (cdr (assoc 8 (entget (car ent1)))))
      (command "-insert" "ball valve" "s" x1 pt3 ang)
      (command "osmode" old "clayer" oldlay "CMDECHO" 1
              )
    )
  )
  (princ)
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: can't get lisp to work correctly
« Reply #6 on: October 24, 2008, 05:50:18 PM »
Using snaps:
Code: [Select]
(DEFUN C:VA (/ old x1 ent1 p1 p2 pt3 ang)
  (SETQ OLD    (GETVAR "OSMODE")
        oldlay (getvar "clayer")
  )
  (SETVAR "OSMODE" 512)
  (COMMAND "CMDECHO" 0)
  (SETQ x1   (GETVAR "DIMSCALE")
        ent1 (entsel "\nPick Insertion point")
        el1  (entget (car ent1))
        p1   (cdr (assoc 10 el1))
        p2   (cdr (assoc 11 el1))
        pt3  (osnap (cadr ent1) "_nea")
        ang  (* 180.0 (/ (angle p1 p2) PI))
  )
  (if pt3
    (progn
      (setvar "clayer" (cdr (assoc 8 (entget (car ent1)))))
      (command "-insert" "ball valve" "s" x1 pt3 ang)
      (command "osmode" old "clayer" oldlay "CMDECHO" 1
              )
    )
  )
  (princ)
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: can't get lisp to work correctly
« Reply #7 on: October 24, 2008, 06:04:08 PM »
Code: [Select]
(cadr ent1)

What does "cadr" means as I see "cdr" elsewhere but no "cadr".
cadr = car cdr

So you are taking the first item of the rest of the list besides the first item.

Example:
list = (1 2 3 4 5)
cadr list = 2
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Alan Cullen

  • Guest
Re: can't get lisp to work correctly
« Reply #8 on: October 24, 2008, 06:47:25 PM »
following on from ^^^^

cdr = 1
caadr = 3
caaadr = 4
etc.

putting it all together is a bit different.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: can't get lisp to work correctly
« Reply #9 on: October 25, 2008, 12:07:00 AM »
yes, I like that Idea (and have just added that to the block), but that still doesn't solve the problem of it not being put on the line correctly, that just makes it easier to fix.

From my tests, it place the block exactly on the object selected?

(command ".-insert" "ball valve" pause 1 1 "")
« Last Edit: October 25, 2008, 12:16:53 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC