lisp for sanitary branch line

lisp for sanitary branch line

LDShaw
Collaborator Collaborator
1,315 Views
6 Replies
Message 1 of 7

lisp for sanitary branch line

LDShaw
Collaborator
Collaborator

I am having trouble with a simple routine that asks for main line, branch line then intersection.

Basically it's going to put an 8' 45° angle between two lines ask for a rotation then trim the branch.

Once that's done it's going to copy said line at the intersection of the next branch  keep the rotation and ask for a trim.


Trouble are in order of importance.

1. I can't get the repeat (I took the repeat out in the example.) of the branch line command  to work right. 

 

2. I can't figure out how to do an apparent intersection that works well. This one is not real important as a tracking to intersection seems to do the trick.

 

As a side not it would be a nice but not a have to have if this would also to a 45° branch line.

 

Any help would be appreciated. 
Thank you.

(defun c:Sanitary ()
;sets main and branch lines
(setq a (entsel "\nSelect main line")
      b (entsel "\nselect branch line")
	  e (getpoint"\nChoose intersection of branch and main line")
)

;branch lines will be made same layer as main line.
(command "LAYMCUR" a)
(command "MATCHPROP" a b "")

;draws connection and places it at intersection of branch and main line.
(command "line" "0,0" "@8<45" "")
(setq c (entlast))
(command "copy" c "" "5.65625,0" e)
(setq d (entlast))
(command "erase" c "")
(command "rotate" d "" "@" pause)
;trims  branch line
(command "trim" d "" pause "") 

;repeats bracnh line.
(setq  f (getpoint"\nChoose intersection of branch and main line"))
(command "copy" d "" e  f)
(setq d (entlast))
(command "trim" d "" pause)
)

 

0 Likes
Accepted solutions (1)
1,316 Views
6 Replies
Replies (6)
Message 2 of 7

CodeDing
Advisor
Advisor
Accepted solution

@LDShaw ,

 

I actually do not fully understand what your end state is supposed to look like? Can you post a before / after of how your dwg WOULD look?

 

Here is a fresh take on what I'm interpreting from your code. You can definitely use "COMMAND" references like you do, but I mixed in some more-advanced items to help get new ideas into your mind.

 

If you have questions, don't hesitate to ask.

(defun c:SANITARY ( / main bran iPt lyr e)
;get selections from user
(if (not (and (setq main (car (entsel "\nSelect Main Line: ")))
	      (setq bran (car (entsel "\nSelect Branch Line: ")))
	      (setq iPt (getpoint "\nSelect Intersection of Main and Branch line: "))))
  (progn (prompt "\n...Cannot skip selections. Try again.") (exit))
);if
;set branch layer to same as main
(setq lyr (cdr (assoc 8 (entget main))))
(setpropertyvalue bran "LayerId" (tblobjname "LAYER" lyr))
(while iPt
  ;create connection line
  ;assumes base direction is EAST & angle direction is COUNTERCLOCKWISE
  (setq e (entmakex (list '(0 . "LINE") (cons 8 lyr) (cons 10 (polar iPt pi 5.65685))
  			(cons 11 (polar iPt (* 0.5 pi) 5.65685)))))
  ;let user rotate & trim
  (command "_.ROTATE" e "" iPt pause)
  (command "_.TRIM" e "" pause "")
  ;repeat branch line
  (setq iPt (getpoint "\nSelect Intersection of Main and Branch line: "))
);while
;finish up
(prompt "\nSANITARY Complete...")
(princ)
);defun

Best,

~DD

Message 3 of 7

LDShaw
Collaborator
Collaborator

I was looking for the advanced way to do it and your example shows it to me. Thank you!
Here is what I am trying to accomplish. Your example is more than sufficient for me to figure out where I went wrong. It was a great help.EXAMPLE.PNG

0 Likes
Message 4 of 7

Sea-Haven
Mentor
Mentor

An alternative method suggestion

 

pick main near end this defines direction of 45 line not in a "and"

use "while" then pick verticals 

use intersectionwith to work out inters point then adjust back towards start, 8' point on main 8/1.414 etc

draw 45 line 

using fillet do just that picked line and new 45 line this avoids working out trims etc fillet obj1 (entlast)

obviously do layer stuff.

 

0 Likes
Message 5 of 7

ronjonp
Mentor
Mentor

Could you not use a dynamic block with an alignment parameter and visibility for the different circles at the ends?

0 Likes
Message 6 of 7

LDShaw
Collaborator
Collaborator

Sometimes a dynamic block would work others times it would not. Saying that I would be open to hearing how others put in their sanitary systems. Lisp and standards are always an interesting talk. 

0 Likes
Message 7 of 7

_Tharwat
Advisor
Advisor

Hi,

Here is a very advanced Drainage Program: Drainage Program 

 

Drainage.PNG

0 Likes