TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jermjmm on October 24, 2008, 05:02:44 PM

Title: can't get lisp to work correctly
Post by: jermjmm 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.
Title: Re: can't get lisp to work correctly
Post by: ronjonp on October 24, 2008, 05:07:12 PM
Since it's a dynamic block, you should just add an alignment parameter.  :-)
Title: Re: can't get lisp to work correctly
Post by: jermjmm 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.
Title: Re: can't get lisp to work correctly
Post by: jermjmm 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.
Title: Re: can't get lisp to work correctly
Post by: Greg B on October 24, 2008, 05:40:18 PM
Code: [Select]
(cadr ent1)

What does "cadr" means as I see "cdr" elsewhere but no "cadr".
Title: Re: can't get lisp to work correctly
Post by: CAB 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)
)
Title: Re: can't get lisp to work correctly
Post by: CAB 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)
)
Title: Re: can't get lisp to work correctly
Post by: T.Willey 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
Title: Re: can't get lisp to work correctly
Post by: Alan Cullen 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.
Title: Re: can't get lisp to work correctly
Post by: ronjonp 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 "")