Mohammed Tambasho Posted November 2, 2020 Posted November 2, 2020 Hi guys am actually rookie in autolisp and I need to develop a program to check fo bends, tees and reducers in a pipe system Quote
ronjonp Posted November 2, 2020 Posted November 2, 2020 10 hours ago, Mohammed Tambasho said: Hi guys am actually rookie in autolisp and I need to develop a program to check fo bends, tees and reducers in a pipe system You have to start somewhere ... post your code and a sample drawing and maybe you'll get some help. Quote
BIGAL Posted November 2, 2020 Posted November 2, 2020 Like ronjonp are you using plain Autocad or mep etc. Quote
Mohammed Tambasho Posted November 4, 2020 Author Posted November 4, 2020 (edited) (defun c:pipes ( / ss i a o l) (if (setq ss (ssget '((0 . "3DSOLID")))) (progn (repeat (setq i (sslength ss)) (if (setq a (pipe_geom (ssname ss (setq i (1- i))))) ; this function checks the geometry of each part to see if it is cylindrical (if (setq o (vl-some '(lambda (x) (if (equal (car a) (car x) 1e-5) x)) l)) (setq l (subst (list (car a) (+ (cadr o) (cadr a))) o l)) (setq l (cons a l)) ) ) ) (if (setq l (vl-sort l '(lambda (a b) (< (car a) (car b))))) ; sorts all the cylindrical solids found by order of increasing diameter (ins_table_pipescounting l) ) ) ) (princ) ) (defun pipe_geom (e / i v r l) (setq e (vlax-ename->vla-object e) v (vlax-get e 'Volume) i ((lambda (x) (if (equal (car x) (cadr x) (* 0.001 (car x))) (list (caddr x) (car x)) (if (equal (car x) (caddr x) (* 0.001 (car x))) (list (cadr x) (car x)) (if (equal (cadr x) (caddr x) (* 0.001 (cadr x))) (list (car x) (cadr x)) ) ) ) ) (vlax-get e 'PrincipalMoments) ) ) (if i (progn (setq r (sqrt (/ (* 2.0 (car i)) v)) l (/ v (* pi r r))) (if (equal (/ (cadr i) (/ (* v (+ (* 3.0 r r) (* l l))) 12.0)) 1.0 1e-5) (list (* 2.0 r) l) ) ) ) ) (defun ins_table_pipescounting (l / acobj acdoc space ht o tab i row col) (setq acObj (vlax-get-acad-object) acDoc (vla-get-activedocument acObj) space (vlax-get acDoc (if (= 1 (getvar 'cvport)) 'PaperSpace 'ModelSpace)) ht (/ 2.2 (cond ((getvar 'cannoscalevalue)) (1.0))) ) (if (setq o (getpoint "\nSpecify table insertion point: ")) (progn (setq tab (vla-addtable space (vlax-3d-point (trans o 1 0)) (+ 2 (length l)) 2 (* 2.5 ht) ht)) (vlax-put tab 'direction (trans '(1 0 0) 1 0 T)) (mapcar (function (lambda (rowType) (vla-SetTextStyle tab rowType (getvar 'textstyle)) (vla-SetTextHeight tab rowType ht) ) ) '(2 4 1) ) (vla-put-HorzCellMargin tab (* 0.14 ht)) (vla-put-VertCellMargin tab (* 0.14 ht)) (setq l (cons (list "Diameter" "Length") l)) (setq i 0) (foreach col (apply 'mapcar (cons 'list l)) (vla-SetColumnWidth tab i (apply 'max (mapcar '(lambda (x) ((lambda (txb) (+ (abs (- (caadr txb) (caar txb))) (* 2.0 ht))) (textbox (list (cons 1 (vl-princ-to-string x)) (cons 7 (getvar 'textstyle)) (cons 40 ht) ) ) ) ) col ) ) ) (setq i (1+ i)) ) (setq l (cons '("PIPES COUNTING") l)) (setq row 0) (foreach r l (setq col 0) (vla-SetRowHeight tab row (* 1.5 ht)) (foreach c r (vla-SetText tab row col (vl-princ-to-string c)) (setq col (1+ col)) ) (setq row (1+ row)) ) ) ) ) here is a sample drawing and the code. Am using Autocad mech. the code recognizes only full pipes but i need it to recognize hollow pipes. pipe.dwg Edited November 4, 2020 by rkmcswain add [CODE] tags Quote
Jonathan Handojo Posted November 5, 2020 Posted November 5, 2020 I'm working in the hydraulic industry as well, so I'm familiar with these terms. First off, what material are they? Copper? PVC? HDPE? Do you need to separate the materials Also, when you say "hollow", what's the thickness of the pipe/pex you're using? If it was me, I just place blocks on corner points and then count them. And as for pipes, I work using multiline and then I segregate them depending on multiline size. Quote
Mohammed Tambasho Posted December 8, 2020 Author Posted December 8, 2020 hi guys, I am actually writing an autolisp program to calculate head loss in 3D hydraulic networks in Autocad mech but my code apparently has some issues. I will like some help. It either returns the error "bad function : TAutocad variable setting rejected: CMDecho nil" or an empty table Here is the code (defun c:pipes ( / ss i a o l w b c d) (setq w (getreal "\n Specify fluid velocity (m/s): ")) (setq b (getreal "\n Specify fluid kinematic viscosity (m2/s): ")) (setq c (getreal "\n Specify duct relative roughness: ")) (setq d (getreal "\n Specify fluid density (Kg/m3): ")) (if (setq ss (ssget '((0 . "3DSOLID")))) (progn (repeat (setq i (sslength ss)) (if (setq a (pipe_geom (ssname ss (setq i (1- i))))) (if (setq o (vl-some '(lambda (x) (if (equal (car a) (car x) 1e-5) x)) l)) (setq l (subst (list (car a) (+ (cadr o) (cadr a))) o l)) (setq l (cons a l)) ) ) ) (if (setq l (vl-sort l '(lambda (a b) (< (car a) (car b))))) (ins_table_pipescounting l) ) ) ) (princ) ) (defun pipe_geom (e / i v r l f Re HL) (setq e (vlax-ename->vla-object e) v (vlax-get e 'Volume) i ((lambda (x) (if (equal (car x) (cadr x) (* 0.001 (car x))) (list (caddr x) (car x)) (if (equal (car x) (caddr x) (* 0.001 (car x))) (list (cadr x) (car x)) (if (equal (cadr x) (caddr x) (* 0.001 (cadr x))) (list (car x) (cadr x)) ) ) ) ) (vlax-get e 'PrincipalMoments) ) ) (if i (progn (setq r (sqrt (/ (* 2.0 (car i)) v)) l (/ v (* pi r r))) (setq Re (/ (* (* 2.0 r) w) b)) (cond ((< Re 2000.0) (setq f (/ 64 Re))) (and ((> Re 2000.0) (< Re 4000.0)) (alert "\nFluid flow is transitional. \nFriction factor can not be calculated")) ((> Re 4000.0) (setq f (/ 0.25 (expt (log (+ (/ c (* 3.7 (* 2.0 r))) (/ 5.74 (expt Re 0.9)))) 2.0)))) ) (setq HL (/ (* f d l (expt w 2)) (* 2 2 r))) (if (equal (/ (cadr i) (/ (* v (+ (* 3.0 r r) (* l l))) 12.0)) 1.0 1e-5) (list (* 2.0 r) l HL) ) ) ) ) (defun ins_table_pipescounting (l / acobj acdoc space ht o tab i row col) (setq acObj (vlax-get-acad-object) acDoc (vla-get-activedocument acObj) space (vlax-get acDoc (if (= 1 (getvar 'cvport)) 'PaperSpace 'ModelSpace)) ht (/ 2.2 (cond ((getvar 'cannoscalevalue)) (1.0))) ) (if (setq o (getpoint "\nSpecify table insertion point: ")) (progn (setq tab (vla-addtable space (vlax-3d-point (trans o 1 0)) (+ 2 (length l)) 2 (* 2.5 ht) ht)) (vlax-put tab 'direction (trans '(1 0 0) 1 0 T)) (mapcar (function (lambda (rowType) (vla-SetTextStyle tab rowType (getvar 'textstyle)) (vla-SetTextHeight tab rowType ht) ) ) '(2 4 1) ) (vla-put-HorzCellMargin tab (* 0.14 ht)) (vla-put-VertCellMargin tab (* 0.14 ht)) (setq l (cons (list "Diameter" "Length" "head loss") l)) (setq i 0) (foreach col (apply 'mapcar (cons 'list l)) (vla-SetColumnWidth tab i (apply 'max (mapcar '(lambda (x) ((lambda (txb) (+ (abs (- (caadr txb) (caar txb))) (* 2.0 ht))) (textbox (list (cons 1 (vl-princ-to-string x)) (cons 7 (getvar 'textstyle)) (cons 40 ht) ) ) ) ) col ) ) ) (setq i (1+ i)) ) (setq l (cons '("CALCULATION OF PRESSURE DROP") l)) (setq row 0) (foreach r l (setq col 0) (vla-SetRowHeight tab row (* 1.5 ht)) (foreach c r (vla-SetText tab row col (vl-princ-to-string c)) (setq col (1+ col)) ) (setq row (1+ row)) ) ) ) ) PIPES.LSP Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.