Request to modify the lisp

Request to modify the lisp

smallƑish
Advocate Advocate
821 Views
13 Replies
Message 1 of 14

Request to modify the lisp

smallƑish
Advocate
Advocate

I found this amazing lisp on the Internet. please, anyone, help me to modify it.

The Lisp working to draft AC duct

How its works now ;

  • HDD (to activate)
  • Pipe diameter/duct width < 1000.0 >?: ( Typing by value or Click and drag with reference to the length)
  • Inner bend radius < 250.0 >?: ( Typing by value or Click and drag with reference to the length)
  • Start point: (Start Drawing)

Please modify to ;

  • HDD (to activate)
  • Enter Duct width < 1000.0 >?: ( Disable Click and drag Feature (limited to only Manuel typing))
  • Inner bend radius < 250.0 >?:  Automate the Step (inner radius value always should be ¼ of duct width)
  • Start point: (Start Drawing)

 

 

; Draws continuous pipe (or duct) of any size 
; with user defined inner bend radius (default = 0.0)

(defun c:HDD (/ d1 d p1 p2 p3 rd1 rd2 lu1 lu2 u1	u2 u3 u5 erd elu erd2
	     elu2 ofr)
  (setq oerr *error*)
  (defun *error* (msg)
    (setvar "filletrad" ofr)
    (setvar "osmode" osn)
    (princ
      "Function cancelled by user, or radius is too large  "
    )
    (setq *error* oerr)
    (command)
    (princ)
  )
  (setq osn (getvar "osmode"))
  (setq ofr (getvar "filletrad"))
  (setvar "cmdecho" 0)
  (if (= d2 nil)
    (setq d2 1.0)
  )
  (princ "\n Pipe diameter / duct width < ")
  (princ d2)
  (princ " >?:")
  (setq d1 (getdist))
  (if (= d1 nil)
    (setq d1 d2)
  )
  (setq d2 d1)
  (if (= r1 nil)
    (setq r1 0.0)
  )
  (princ "\n Inner bend radius < ")
  (princ r1)
  (princ " >?:")
  (setq r (getdist))
  (if (= r nil)
    (setq r r1)
  )
  (setq r1 r)
  (setq d (/ d1 2))
  (setq p1 (getpoint "\n Start point: "))
  (setq p2 (getpoint p1 "\n Next point: "))
  (setq u1 (angle p1 p2))

  (setq rd1 (polar p1 (- u1 (* pi 0.5)) d)) ; rd = right
  (setq rd2 (polar rd1 u1 (distance p1 p2)))
  (setq lu1 (polar p1 (+ u1 (* pi 0.5)) d)) ; lu = left
  (setq lu2 (polar lu1 u1 (distance p1 p2)))
  (setvar "osmode" 0)
  (command "line" rd1 rd2 "")
  (setq erd (entlast))
  (command "line" lu1 lu2 "")
  (setq elu (entlast))
  (setvar "osmode" osn)
  (setq p3 (getpoint p2 "\n Next"))
  (setvar "osmode" 0)
  (setq u2 (angle p2 p3))

  (setq u5 (+ (- pi u1) u2))
  (if (> u5 (* pi 2))
    (setq u5 (- u5 (* pi 2)))
  )
  (if (< u5 0)
    (setq u5 (+ (* pi 2) u5))
  )

  (while p3
    (setq p1 p2)
    (setq p2 p3)
    (setq u1 (angle p1 p2))

    (setq rd1 (polar p1 (- u1 (* pi 0.5)) d)) ; rd = right/down
    (setq rd2 (polar rd1 u1 (distance p1 p2)))
    (setq lu1 (polar p1 (+ u1 (* pi 0.5)) d)) ; lu = left/up
    (setq lu2 (polar lu1 u1 (distance p1 p2)))
    (command "line" rd1 rd2 "")
    (setq erd2 (entlast))
    (command "line" lu1 lu2 "")
    (setq elu2 (entlast))

    (if	(< u5 pi)
      (progn
	(setvar "filletrad" r)
	(command "fillet" erd erd2)
	(setvar "filletrad" (+ d1 r))
	(command "fillet" elu elu2)
      )
    )
    (if	(> u5 pi)
      (progn
	(setvar "filletrad" (+ d1 r))
	(command "fillet" erd erd2)
	(setvar "filletrad" r)
	(command "fillet" elu elu2)
      )
    )

    (setq erd erd2)
    (setq elu elu2)
    (setvar "osmode" osn)
    (setq p3 (getpoint p2 "\n Next:"))
    (setvar "osmode" 0)
    (if	(= p3 nil)
      ()
      (setq u2 (angle p2 p3))
    )

    (setq u5 (+ (- pi u1) u2))
    (if	(> u5 (* pi 2))
      (setq u5 (- u5 (* pi 2)))
    )
    (if	(< u5 0)
      (setq u5 (+ (* pi 2) u5))
    )


  )
  (setvar "osmode" osn)
  (setvar "filletrad" ofr)
  (princ)
)

 

 

0 Likes
Accepted solutions (2)
822 Views
13 Replies
Replies (13)
Message 2 of 14

paullimapa
Mentor
Mentor
Accepted solution

Replace this

(setq d1 (getdist))

with this

(setq d1 (getreal))

As for radius replace this section 

(if (= r1 nil)
    (setq r1 0.0)
  )
  (princ "\n Inner bend radius < ")
  (princ r1)
  (princ " >?:")
  (setq r (getdist))
  (if (= r nil)
    (setq r r1)
  )
  (setq r1 r)

with this

(setq r1(/ d1 4.0))

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 14

smallƑish
Advocate
Advocate

Thank you so much, its work for me.

0 Likes
Message 4 of 14

paullimapa
Mentor
Mentor

Glad to have helped… cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 14

smallƑish
Advocate
Advocate
Just one more question, is there any chance to add the Duct width (Example "1000" here) to the middle of the duct as Text, middle center justification 150 text size?
0 Likes
Message 6 of 14

paullimapa
Mentor
Mentor

try this which should place text of duct size on the first duct segment assuming current Text Style does NOT have height defined.

Replace the first occurrence of this code:

  (setq elu (entlast))
  (setvar "osmode" osn)

with this:

  (setq elu (entlast))
  (setq p0 (mapcar '(lambda (x y) (/ (+ x y) 2)) rd1 lu2)) ; get midpoint
  (command "_.Text" "_J" "_MC" p0 150 (* 180.0 (/ u1 pi)) d1) ; place text assumes current text style has height set at 0
  (setvar "osmode" osn)

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 14

smallƑish
Advocate
Advocate

Wow, Worked perfectly,

What we have to do is add the text in each segment, 

 

In addition ;

Text into a dedicated layer called "DUCT SIZE"

TEXT style always "EP TEXT"

TEXT Height  "150"

0 Likes
Message 8 of 14

paullimapa
Mentor
Mentor

Questions:

1) So we have to assume there isn’t a Text style called EP TEXT created yet?

2) Should this Text Style EP TEXT be Annotative?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 9 of 14

paullimapa
Mentor
Mentor

One more question:

What color should the dedicated layer DUCT SIZE be?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 10 of 14

smallƑish
Advocate
Advocate

YES EP TEXT is my regular Text style i always use.

Not an annotative text. 

0 Likes
Message 11 of 14

smallƑish
Advocate
Advocate

I m use the layer color (set be layer) always. 

It's a Color 4 Cyan now Depending situation may change it. 

0 Likes
Message 12 of 14

paullimapa
Mentor
Mentor
Accepted solution

here's the revised version:

; HDD function Draws continuous pipe (or duct) of any size 
; with defined inner bend radius set to quarter size of duct
; and duct size shown at center of pipe
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/request-to-modify-the-lisp/m-p/12173784#M453194
(defun c:HDD
  (/ d1 d p1 p2 p3 rd1 rd2 lu1 lu2 u1
     u2 u3 u5 erd elu erd2 elu2 ofr
     add_text ; localize function
  )
  (setq oerr *error*)
  (defun *error* (msg)
    (setvar "filletrad" ofr)
    (setvar "osmode" osn)
    (princ
      "Function cancelled by user, or radius is too large  "
    )
    (setq *error* oerr)
    (command)
    (princ)
  )
  ; function to add text showing duct size
  (defun add_text (/ clayer textstyle p0)
   (setq clayer(getvar"clayer"))
   (setq textstyle(getvar"textstyle"))
   (if(not(tblsearch "LAYER" "DUCT SIZE"))(command "_.Layer" "_M" "DUCT SIZE" "_C" 4 "" ""))
   (if(not(tblsearch "Style""EP TEXT"))(command "_.Style""EP TEXT""txt.shx" 0 1 0 "_No" "_No" "_No"))
   (setvar"clayer""DUCT SIZE")
   (setvar"Textstyle""EP TEXT")
   (setq p0 (mapcar '(lambda (x y) (/ (+ x y) 2)) rd1 lu2)) ; get midpoint
   (command "_.Text" "_J" "_MC" p0 150 (* 180.0 (/ u1 pi)) d1) ; place text assumes current text style has height set at 0
   (setvar"clayer"clayer)
   (setvar"textstyle"textstyle)
  ) ; defun
  
  (setq osn (getvar "osmode"))
  (setq ofr (getvar "filletrad"))
  (setvar "cmdecho" 0)
  (if (= d2 nil)
    (setq d2 1.0)
  )
  (princ "\n Pipe diameter / duct width < ")
  (princ d2)
  (princ " >?:")
 ; (setq d1 (getdist))
  (setq d1 (getreal))
  (if (= d1 nil)
    (setq d1 d2)
  )
  (setq d2 d1)
 ; (if (= r1 nil)
 ;   (setq r1 0.0)
 ; )
 ; (princ "\n Inner bend radius < ")
 ; (princ r1)
 ; (princ " >?:")
 ; (setq r (getdist))
 ; (if (= r nil)
 ;   (setq r r1)
 ; )
 ; (setq r1 r)
  (setq r1(/ d1 4.0) r r1)
  (setq d (/ d1 2))
  (setq p1 (getpoint "\n Start point: "))
  (setq p2 (getpoint p1 "\n Next point: "))
  (setq u1 (angle p1 p2))
  (setq rd1 (polar p1 (- u1 (* pi 0.5)) d)) ; rd = right
  (setq rd2 (polar rd1 u1 (distance p1 p2)))
  (setq lu1 (polar p1 (+ u1 (* pi 0.5)) d)) ; lu = left
  (setq lu2 (polar lu1 u1 (distance p1 p2)))
  (setvar "osmode" 0)
  (command "line" rd1 rd2 "")
  (setq erd (entlast))
  (command "line" lu1 lu2 "")
  (setq elu (entlast)) 
  (add_text) ; run subroutine to add duct size  
  (setvar "osmode" osn)
  (setq p3 (getpoint p2 "\n Next"))
  (setvar "osmode" 0)
  (setq u2 (angle p2 p3))
  (setq u5 (+ (- pi u1) u2))
  (if (> u5 (* pi 2))
    (setq u5 (- u5 (* pi 2)))
  )
  (if (< u5 0)
    (setq u5 (+ (* pi 2) u5))
  )
  (while p3
    (setq p1 p2)
    (setq p2 p3)
    (setq u1 (angle p1 p2))
    (setq rd1 (polar p1 (- u1 (* pi 0.5)) d)) ; rd = right/down
    (setq rd2 (polar rd1 u1 (distance p1 p2)))
    (setq lu1 (polar p1 (+ u1 (* pi 0.5)) d)) ; lu = left/up
    (setq lu2 (polar lu1 u1 (distance p1 p2)))
    (command "line" rd1 rd2 "")
    (setq erd2 (entlast))
    (command "line" lu1 lu2 "")
    (setq elu2 (entlast))  
    (add_text) ; run subroutine to add duct size
    (if	(< u5 pi)
     (progn
	  (setvar "filletrad" r)
      (command "fillet" erd erd2)
      (setvar "filletrad" (+ d1 r))
      (command "fillet" elu elu2)
     )
    )
    (if	(> u5 pi)
     (progn
      (setvar "filletrad" (+ d1 r))
      (command "fillet" erd erd2)
      (setvar "filletrad" r)
      (command "fillet" elu elu2)
     )
    )
    (setq erd erd2)
    (setq elu elu2)
    (setvar "osmode" osn)
    (setq p3 (getpoint p2 "\n Next:"))
    (setvar "osmode" 0)
    (if	(= p3 nil)
      ()
      (setq u2 (angle p2 p3))
    )
    (setq u5 (+ (- pi u1) u2))
    (if	(> u5 (* pi 2))
      (setq u5 (- u5 (* pi 2)))
    )
    (if	(< u5 0)
      (setq u5 (+ (* pi 2) u5))
    )
  ) ; while
  (setvar "osmode" osn)
  (setvar "filletrad" ofr)
  (princ)
) ; defun

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 13 of 14

smallƑish
Advocate
Advocate

This is what I was dreaming of, And  Its works perfectly. 

Thank you so much. 

 

0 Likes
Message 14 of 14

paullimapa
Mentor
Mentor

Very good and once again…cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos