2D Flex Lisp

2D Flex Lisp

marlon.lam
Explorer Explorer
4,468 Views
5 Replies
Message 1 of 6

2D Flex Lisp

marlon.lam
Explorer
Explorer

I am pretty green when it comes to AutoLisp. I mostly take lisps routines and make modifications when absolutely necessary, however, recently and acquaintance of mine was trying to help me out when I asked if he had anything which would help create flexible ductwork in 2D. He provided a lisp routine which apparently worked in older versions of AutoCAD (2011, etc.), but it no longer works with AutoCAD 2015.

 

After spending the last week trying to get it to work, I just could not figure out what was happening. If anyone could help me out, I would greatly appreciate it. Any help at all!

 

 

(defun c:dflex ()
  (if (null startgroup)(load "makegroup"))
  (setq DD sf)
  (initget 1 "Y y N n")
  (setq DROP (strcase(getkword "\Do you want a DROP at the end of the flex <y/n>: ")))
  (setq C-PT (getvar "VIEWCTR"))
  (command "insert" "FlexDuct" C-PT "" "" "")
  (command "erase" "l" "")
  (if dd (progn (initget (+ 2 4))
  (setq newdd (getdist (strcat "\nEnter size of duct in inches <"(rtos dd)">:")))
  (if (= newdd nil)
  (setq newdd dd)
  (setq dd newdd)))
  (progn (initget (+ 1 2 4))
  (setq dd (getdist "\nEnter size of duct in inches:"))
  (setq DD DRW-WDTH FS-PT S-PT)
  (setq SS2 (ssadd))
  (setq(setq fs-pt (getpoint "\nPick start point of flex")))
  (setq startpt fs-pt) ;save for later
  (setq FN-PT (getpoint FS-PT "\n\nPick next point of flex branch: "))
  (command "pline" FS-PT FN-PT "")
  (ssadd (entlast) SS2)
  (setq PT-SAV FS-PT FS-PT  FN-PT FN-PT (getpoint FS-PT "\n\nPick next point of flex branch <or RETURN>:"))
  ;;setq
  (while FN-PT (command "pline" FS-PT FN-PT "")
  (ssadd (entlast) SS2)
  (setq PT-SAV FS-PT FS-PT FN-PT FN-PT (getpoint FS-PT	"\n\nPick next point of flex branch <or RETURN to End>:"))
  ;;setq)
  ;;while
  (setq LST-ANG (angle PT-SAV FS-PT))
  (command "pedit" SS2 "j" SS2 "" "s" "")
  (command "fillet" "r" (* 1.5 dd))
  (command "fillet" "p" FS-PT)
  (setq FLX-LN (entlast))
  (startgroup flx-ln)
  (command "measure" (list flx-ln FS-PT) "b" "FlexDuct" "y" (* 0.25 dd))
  (setq SS3 (ssget "P"))
  (command "erase" FLX-LN "")
  (setq C 0 SSL (sslength SS3))
  ;scale up all the blocks
  (while (< C SSL))
  (setq ENT (entget (ssname SS3 C)))
  (setq ENT (subst (cons 41 DD) (assoc 41 ENT) ENT))
  (setq ENT (subst (cons 42 DD) (assoc 42 ENT) ENT))
  (setq ENT (subst (cons 43 DD) (assoc 43 ENT) ENT))
  (entmod ENT)
  (setq C (+ C 1))
  (setq en (ssname ss3 0)) ;get first entity
  (setq enl (entget en))
  (setq pt1 (get 10 enl)) ;store insertion point
  (Command "copy" en "" pt1 startpt) ;copy the item because measure doesn't do the first point
  (endgroup)
  ;;while;;;
  (if (= DROP "Y")
  ;;;
  (command "insert" "FlexDrop" FS-PT DD ""(* LST-ANG (/ 360.0 (* PI 2.0))))
  (setq OPT-1 "Q")
;;flex

The above is the lisp I received. I tried cleaning it up from what I received, but it looks like I've failed somewhere. I've also attached the two drawing files it requires and an image of what it's supposed to accomplish.

 

 

T.I.A.

 

 

0 Likes
4,469 Views
5 Replies
Replies (5)
Message 2 of 6

Ranjit_Singh
Advisor
Advisor

marlon.lam wrote:..........
(defun c:dflex ()
  (if (null startgroup)(load "makegroup")) ;these 2 functions are needed to test
  ............

.............. I tried cleaning it up ....... Maybe provide the unaltered version

T.I.A.


Quite a few parantheses are missing. TBH, I am not sure where to add them, since I don't understand the working of the lisp. You will have a better chance if you provided the unaltered LISP. Also I can see that two functions are missing

 

0 Likes
Message 3 of 6

marlon.lam
Explorer
Explorer

Mr. Singh,

 

Really appreciate you looking into this. The following is the unaltered code and I've also attached the original Lisp File.

 

(defun c:dflex ()
  (if (null startgroup)(load "makegroup"))

					;(setq DD sf)
  ;(initget 1 "Y y N n")
  ;(setq
  ;  DROP (strcase
	   ;(getkword
;	     "\Do you want a DROP at the end of the flex <y/n>: "
;	   )
;	 )
 ; )
  (setq C-PT (getvar "VIEWCTR"))
  (command "insert" "FlexDuct" C-PT "" "" "")
  (command "erase" "l" "")
  (if dd
    (progn
      (initget (+ 2 4))
      (setq
	newdd (getdist
		(strcat "\nEnter size of duct in inches <" (rtos dd) ">: ")
	      )
      )
      (if (= newdd nil)
	(setq newdd dd)
	(setq dd newdd)
      )
    )
    (progn
      (initget (+ 1 2 4))
      (setq dd (getdist "\nEnter size of duct in inches:"))
    )
  )
					;(setq DD	DRW-WDTH
					;	  FS-PT	S-PT
  (setq SS2 (ssadd))
  ;;setq
  (setq fs-pt (getpoint "\nPick start point of flex"))
  (setq startpt fs-pt) ;save for later
  (setq FN-PT (getpoint FS-PT "\n\nPick next point of flex branch: "))
  (command "pline" FS-PT FN-PT "")
  (ssadd (entlast) SS2)
  (setq	PT-SAV FS-PT
	FS-PT  FN-PT
	FN-PT  (getpoint FS-PT
			 "\n\nPick next point of flex branch <or RETURN>: "
	       )
  )
  ;;setq
  (while FN-PT
    (command "pline" FS-PT FN-PT "")
    (ssadd (entlast) SS2)
    (setq PT-SAV FS-PT
	  FS-PT	 FN-PT
	  FN-PT	 (getpoint
		   FS-PT
		   "\n\nPick next point of flex branch <or RETURN to End>: "
		 )
    )
    ;;setq
  )
  ;;while
  (setq LST-ANG (angle PT-SAV FS-PT))
  (command "pedit" SS2 "j" SS2 "" "s" "")
  ;(command "fillet" "r" (* 1.5 dd))
  ;(command "fillet" "p" FS-PT)
  
  (setq FLX-LN (entlast))
  (startgroup flx-ln)
  (command "measure" (list flx-ln FS-PT) "b" "FlexDuct" "y" (* 0.25 dd))
  (setq SS3 (ssget "P"))
  (command "erase" FLX-LN "")
  (setq	C   0
	SSL (sslength SS3)
  )
  ;scale up all the blocks
  (while (< C SSL)
    (setq ENT (entget (ssname SS3 C)))
    (setq ENT (subst (cons 41 DD) (assoc 41 ENT) ENT))
    (setq ENT (subst (cons 42 DD) (assoc 42 ENT) ENT))
    (setq ENT (subst (cons 43 DD) (assoc 43 ENT) ENT))
    (entmod ENT)
    (setq C (+ C 1))
  )
  (setq en (ssname ss3 0)) ;get first entity
  (setq enl (entget en))
  (setq pt1 (get 10 enl)) ;store insertion point
  (Command "copy" en "" pt1 startpt) ;copy the item because measure doesn't do the first point
  (endgroup)
  ;;while
;;;  (if (= DROP "Y")
;;;    (command "insert"
;;;	     "FlexDrop"
;;;	     FS-PT
;;;	     DD
;;;	     ""
;;;	     (* LST-ANG (/ 360.0 (* PI 2.0)))
;;;    )
;;;  )
					;  (setq OPT-1 "Q")
)
;;flex

Thank you,

0 Likes
Message 4 of 6

Ranjit_Singh
Advisor
Advisor

Like I said before there are some functions that are missing. I don't see how I can help. Maybe there is something obvious I am missing. I am sure other community members are reviewing this as well and hope they find a solution. Meanwhile see if you can contact your source and get the startgroup and makegroup functions.

Command: DFLEX
; error: LOAD failed: "makegroup"
Command:
0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant

@Ranjit_Singh wrote:

Like I said before there are some functions that are missing. .... see if you can contact your source and get the startgroup and makegroup functions.

Command: DFLEX
; error: LOAD failed: "makegroup"
Command:

But I can guess what they do -- makegroup.lsp [or makegroup.vlx or something] contains the definitions of the (startgroup) and (endgroup) functions, (startgroup) sets the last object [the supplied argument] as the starting reference, and (endgroup) finds everything newer than that reference and puts it into a group.

 

But @marlon.lam, it would help a lot to know what about it doesn't work in Acad2015, to narrow down what to look for to update the code.  Are you simply getting that same load error message, meaning you don't have the makegroup .lsp or .vlx or whatever file?  Or does it load [meaning you have the makegroup code], but does AutoCAD not recognize the command name when you enter it?  Does it recognize it, but it doesn't do what you expect?  What's different than you expect?  Does it do something you don't expect?  Are there other error messages?  Etc., etc., etc.

 

EDIT:  And by the way, if you can do with something other than that specific Measure-with-Block approach, put wording like Flex Duct into the Search window, and you'll find a variety of different approaches, in varying degrees of "literalness" of imagery, etc.

Kent Cooper, AIA
0 Likes
Message 6 of 6

_Tharwat
Advisor
Advisor

Hi,

 

I did not open any of your attached drawings but I am posting this based on the title of your thread, so you may find this program of any interest.

https://autolispprograms.wordpress.com/hvac-flexible-duct/

0 Likes