Author Topic: LISP help  (Read 2881 times)

0 Members and 1 Guest are viewing this topic.

aswin

  • Mosquito
  • Posts: 12
LISP help
« on: June 14, 2016, 01:09:38 AM »
Hi every one,
i have got a lisp from my friend.. this lisp is used to align objects in an even spacing.. the problem is.. we can't give a minimum spacing distance between objects and there is no option for align to a polyline ... because the osnap mode is not working when the command is active... please help.. the Lisp is given below

Code: [Select]
(defun _bboxandmid (obj / a b l)
  (vla-getboundingbox obj 'a 'b)
  (list (car (setq l (mapcar 'vlax-safearray->list (list a b))))
        (apply '(lambda (a b) (mapcar '(lambda (a b) (/ (+ a b) 2.)) a b)) l)
        (cadr l)
  )
)

(defun ss->lst (ss / i l)
  (if (eq (type ss) 'pickset)
    (repeat (setq i (sslength ss))
      (setq l (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) l))
    )
  )
)




(defun c:spb (/ lst p1 g p2 a d)
  (if (and (setq lst (ss->lst (ssget "_:L")))
           (setq p1 (getpoint "\nSpecify first point: "))
      )

    (while (eq 5 (car (setq g (grread t 15 0))))
      (redraw)
      (grdraw p1 (polar (setq p2 (cadr g)) (angle p1 p2) 10000000.) 1 -1)

      (setq p1 (trans p1 1 0)
            p2 (trans p2 1 0)
            a  (angle p1 p2)
            d  (/ (distance p1 p2) (float (length lst)))
      )

      (vla-move (car lst) (vlax-3d-point (cadr (_bboxandmid (car lst)))) (vlax-3d-point p1))

      (mapcar
        '(lambda (o1 o2 / l)
           (vla-move o2
                     (vlax-3d-point (cadr (_bboxandmid o2)))
                     (vlax-3d-point
                       (polar (cadr (setq l (_bboxandmid o1)))
                              a
                              (+ d (distance (car l) (caddr l)))
                       )
                     )
           )
         )
        lst
        (cdr lst)
      )
    )
  )
  (redraw)
  (princ)
)
« Last Edit: June 14, 2016, 08:48:18 AM by CAB »
Abu Dhabi

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: LISP help
« Reply #1 on: June 14, 2016, 03:57:04 AM »
It's not an answer to your request, but small remark...
I'd replace this value : 10000000.
with (distance p1 p2) syntax...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
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.

aswin

  • Mosquito
  • Posts: 12
Re: LISP help
« Reply #3 on: June 15, 2016, 05:08:03 AM »
@CAB  Thanks dude... for showing me the person who created this LISP   
Abu Dhabi

didier

  • Newt
  • Posts: 48
  • expatrié
Re: LISP help
« Reply #4 on: June 15, 2016, 05:34:44 AM »
Coucou

If you want to learn, you should not copy and paste but to understand and thus learn you should begin with the base.  :idea:

"big coders" on the site one made active the osnap with grread ... :idiot2:

amicalement
eternal beginner ...
my english is not fluent ...

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: LISP help
« Reply #5 on: June 15, 2016, 08:10:02 AM »
Is it time to start another beginners thread?
TheSwamp.org  (serving the CAD community since 2003)

didier

  • Newt
  • Posts: 48
  • expatrié
Re: LISP help
« Reply #6 on: June 15, 2016, 09:05:03 AM »
Coucou

I think so because a lot of people "copy-paste" the code and then asks questions why it does not work.
but this site is not really a beginner site...
eternal beginner ...
my english is not fluent ...

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: LISP help
« Reply #7 on: June 15, 2016, 10:14:53 AM »
This is very much a beginner site - lots of help to understand the common practices and algorithms of coding as they apply to LISP but also in general.  But copy'n'paste isn't the starting point of learning any more than taking a photo of the Mona Lisa makes someone the next Davinci.  So yeah, I think a beginners thread would be a good addition.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: LISP help
« Reply #8 on: June 15, 2016, 02:45:45 PM »
I'll bring in my book; AutoLISP Programming: Principles and Techniques tomorrow for reference. :)
TheSwamp.org  (serving the CAD community since 2003)

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: LISP help
« Reply #10 on: June 16, 2016, 07:57:46 AM »
I'll bring in my book; AutoLISP Programming: Principles and Techniques tomorrow for reference. :)
Forgot the damn book! *sigh* Sorry.
TheSwamp.org  (serving the CAD community since 2003)

aswin

  • Mosquito
  • Posts: 12
Re: LISP help
« Reply #11 on: June 19, 2016, 01:14:59 AM »
so , no help??  :-(
Abu Dhabi

ur_naz

  • Newt
  • Posts: 68
  • Made in Ukraine
Re: LISP help
« Reply #12 on: June 19, 2016, 02:29:55 AM »
maybe try to use vlax-curve-getClosestPointTo

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: LISP help
« Reply #13 on: June 19, 2016, 07:13:20 AM »
@ aswin:
Maybe you will like this version better.
Change:
Code: [Select]
((osnap p2 "_END,_MID"))to suit your needs.

Code:
Code - Auto/Visual Lisp: [Select]
  1. (defun _bboxandmid (obj / a b l)
  2.   (vla-getboundingbox obj 'a 'b)
  3.   (list (car (setq l (mapcar 'vlax-safearray->list (list a b))))
  4.         (apply '(lambda (a b) (mapcar '(lambda (a b) (/ (+ a b) 2.)) a b)) l)
  5.         (cadr l)
  6.   )
  7. )
  8.  
  9. (defun ss->lst (ss / i l)
  10.   (if (eq (type ss) 'pickset)
  11.     (repeat (setq i (sslength ss))
  12.       (setq l (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) l))
  13.     )
  14.   )
  15. )
  16.  
  17. (defun c:spb (/ doc fac g lst p1 p2 vec)
  18.   (if
  19.     (and
  20.       (setq lst (ss->lst (ssget "_:L")))
  21.       (or
  22.         (< 1 (length lst))
  23.         (prompt "\nSelection set must contain at least 2 entities ")
  24.       )
  25.       (or
  26.         (setq fixDist (getdist "\nFixed distance or Enter: "))
  27.         T
  28.       )
  29.       (setq p1 (getpoint "\nSpecify first point: "))
  30.     )
  31.     (progn
  32.       (vla-endundomark doc) ; End open undo group.
  33.       (vla-startundomark doc)
  34.       (princ "\nSpecify second point: ")
  35.       (while (eq 5 (car (setq g (grread t 15 0))))
  36.         (redraw)
  37.         (setq p2 (cadr g))
  38.         (setq p2
  39.           (cond
  40.             ((osnap p2 "_END,_MID")) ; Change to suit your needs.
  41.             (p2)
  42.           )
  43.         )
  44.         (if (not (equal p1 p2 1e-4))
  45.           (progn
  46.             (grdraw p1 p2 1 -1)
  47.             (setq fac
  48.               (cond
  49.                 (fixDist (/ (distance p1 p2) fixDist))
  50.                 ((1- (length lst)))
  51.               )
  52.             )
  53.             (setq vec (trans (mapcar '(lambda (crd1 crd2) (/ (- crd2 crd1) fac)) p1 p2) 1 0 T))
  54.             (vlax-invoke (car lst) 'move (cadr (_bboxandmid (car lst))) (trans p1 1 0))
  55.             (mapcar
  56.               '(lambda (o1 o2 / l)
  57.                  (vlax-invoke o2 'move (cadr (_bboxandmid o2)) (mapcar '+ (cadr (_bboxandmid o1)) vec))
  58.                )
  59.               lst
  60.               (cdr lst)
  61.             )
  62.           )
  63.         )
  64.       )
  65.       (vla-endundomark doc)
  66.     )
  67.   )
  68.   (redraw)
  69.   (princ)
  70. )

aswin

  • Mosquito
  • Posts: 12
Re: LISP help
« Reply #14 on: June 20, 2016, 01:20:47 AM »
@roy_043:
   PERFECT!!!! Sir, this is what i was looking for.... thank you soo much... :yes:
Abu Dhabi