Author Topic: Help to make this lisp work in other ucs than world  (Read 911 times)

0 Members and 1 Guest are viewing this topic.

satdog200

  • Mosquito
  • Posts: 10
Help to make this lisp work in other ucs than world
« on: November 22, 2013, 11:21:52 AM »
Hello !

I have a old lisp file that makes a wavy line, I have tried to make this work in other UCS with "trans" but failed, could somone give me a hint to manage this ?

Code: [Select]
;Draw wavy line

(defun c:wavy (/ DivideDistance EntList Blg Pt nPt cnt Dist)
   
    (defun DivideDistance ( sPt ePt dist / Ang tempDist SpDist Amnt )
       
        (setq Ang (angle sPt ePt))
        (setq tempDist (distance sPt ePt))
        (setq SpDist (/ tempDist (setq Amnt (fix (/ tempDist dist)))))
        (setq Amnt (1+ Amnt))
        (setq cnt (+ Amnt cnt))
        (repeat Amnt
            (setq EntList
                (cons
                    (cons 42 (setq Blg (- Blg)))
                    (cons
                        (cons 41 0.)
                        (cons
                            (cons 40 0.)
                            (cons
                                (cons 10 (list (car sPt) (cadr sPt)))
                                EntList
                            )
                        )
                    )
                )
            )
            (setq sPt (polar sPt Ang SpDist))
        )
        EntList
    )
    ;-------------------------------------------------
    (setq Dist 125)
    (setq EntList
        (list
            (cons 90 2)
            (cons 100 "AcDbPolyline")
            (cons 100 "AcDbEntity")
            (cons 0 "LWPOLYLINE")
        )
    )
    (setq Blg 0.5)
    (setq cnt 0)
    (if (setq Pt (getpoint "\n Select first point: "))
        (progn
            (while (setq nPt (getpoint Pt "\n Select next point: "))
                (setq EntList (DivideDistance Pt nPt (* Dist 1)))
                (setq Pt nPt)
                (setq cnt (1+ cnt))
            )
            (entmake (subst (cons 90 cnt) '(90 . 2) (reverse EntList)))
        )
    )
    (princ)
)

With kind regards
Anders Tengbom
Sweden


ribarm

  • Water Moccasin
  • Posts: 2253
  • Marko Ribar, architect
Re: Help to make this lisp work in other ucs than world
« Reply #1 on: November 22, 2013, 12:16:46 PM »
This should do it... (tested few times)

Code: [Select]
;Draw wavy line

(defun c:wavy (/ DivideDistance EntList Blg Pt nPt cnt Dist)
   
    (defun DivideDistance ( sPt ePt dist / Ang tempDist SpDist Amnt )
       
        (setq Ang (angle sPt ePt))
        (setq tempDist (distance sPt ePt))
        (setq SpDist (/ tempDist (setq Amnt (fix (/ tempDist dist)))))
        (setq Amnt (1+ Amnt))
        (setq cnt (+ Amnt cnt))
        (repeat Amnt
            (setq EntList
                (cons
                    (cons 42 (setq Blg (- Blg)))
                    (cons
                        (cons 41 0.)
                        (cons
                            (cons 40 0.)
                            (cons
                                (cons 10 (list (car sPt) (cadr sPt)))
                                EntList
                            )
                        )
                    )
                )
            )
            (setq sPt (polar sPt Ang SpDist))
        )
        EntList
    )
    ;-------------------------------------------------
    (setq Dist 1.0)
    (setq EntList
        (list
            (cons 90 2)
            (cons 100 "AcDbPolyline")
            (cons 100 "AcDbEntity")
            (cons 0 "LWPOLYLINE")
        )
    )
    (setq Blg 0.5)
    (setq cnt 0)
    (if (setq Pt (getpoint "\n Select first point: "))
        (progn
            (while (setq nPt (getpoint Pt "\n Select next point: "))
                (setq Pt (trans Pt 1 (trans '(0.0 0.0 1.0) 1 0 t)))
                (setq nPt (trans nPt 1 (trans '(0.0 0.0 1.0) 1 0 t)))
                (setq EntList (DivideDistance Pt nPt (* Dist 1)))
                (setq Pt (trans nPt (trans '(0.0 0.0 1.0) 1 0 t) 1))
                (setq cnt (1+ cnt))
            )
            (setq EntList (cons (cons 38 (caddr Pt)) EntList))
            (setq EntList (cons (cons 210 (trans '(0.0 0.0 1.0) 1 0 t)) EntList))
            (entmake (subst (cons 90 cnt) '(90 . 2) (reverse EntList)))
        )
    )
    (princ)
)

BTW. I've changed Dist variable to 1.0 - did get with starting 125 value divide by zero error...

HTH,
M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12353
  • London, England
Re: Help to make this lisp work in other ucs than world
« Reply #2 on: November 23, 2013, 08:54:52 AM »
I would write it this way:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:wavy ( / dividedistance blg cnt dis lst ocs pt1 pt2 )
  2.  
  3.     (defun dividedistance ( pt1 pt2 dis / ang len num rtn seg )
  4.         (setq ang (angle pt1 pt2)
  5.               len (distance pt1 pt2)
  6.               num (fix (/ len dis))
  7.               seg (/ len num)
  8.         )
  9.         (repeat (1+ num)
  10.             (setq rtn
  11.                 (vl-list*
  12.                     (cons 42 (setq blg (- blg)))
  13.                     (cons 10 (trans pt1 1 ocs))
  14.                     rtn
  15.                 )
  16.             )
  17.             (setq pt1 (polar pt1 ang seg))
  18.         )
  19.         rtn
  20.     )
  21.    
  22.     (setq ocs (trans '(0.0 0.0 1.0) 1 0 t)
  23.           blg 0.5
  24.           dis 10.0
  25.           cnt 0
  26.     )    
  27.     (if (setq pt1 (getpoint "\nPick 1st point: "))
  28.         (progn
  29.             (while (setq pt2 (getpoint "\nPick next point: " pt1))
  30.                 (if (< (distance pt1 pt2) dis)
  31.                     (princ "\nPoints too close together.")
  32.                     (setq lst (append (dividedistance pt1 pt2 dis) (cddr lst))
  33.                           pt1 pt2
  34.                           blg (- blg)
  35.                     )
  36.                 )
  37.             )
  38.             (if lst
  39.                 (entmake
  40.                     (append
  41.                         (list
  42.                            '(000 . "LWPOLYLINE")
  43.                            '(100 . "AcDbEntity")
  44.                            '(100 . "AcDbPolyline")
  45.                             (cons 90 (/ (length lst) 2))
  46.                            '(70 . 0)
  47.                             (cons 38 (caddr (cdadr lst)))
  48.                         )
  49.                         (reverse lst)
  50.                         (list (cons 210 ocs))
  51.                     )
  52.                 )
  53.             )
  54.         )
  55.     )
  56.     (princ)
  57. )

satdog200

  • Mosquito
  • Posts: 10
Re: Help to make this lisp work in other ucs than world
« Reply #3 on: November 25, 2013, 05:01:45 AM »
Thank you, both codes worked fine.

I was almost right with my own code and now I think I got a clue on how it works.

(Dist=125 because I use Autocad MEP and MSLTSCALE=1 and the code earlier read the LTSCALE value which now always is set to 1, tried to change the code to read the annoative scale CANNOSCALE but it did not work)

Sincerely
Anders

Lee Mac

  • Seagull
  • Posts: 12353
  • London, England
Re: Help to make this lisp work in other ucs than world
« Reply #4 on: November 25, 2013, 09:06:27 AM »
You're welcome Anders  :-)