First step is to define function. (defun valve (). Subroutine entsel asks you to select an entity, which is line in this case. Syntax of entsel is (entsel "string"). in this case it is (entsel "\nSelect PipeLine : ").
Once you select an entity, you can save it as entity1. (setq entity1 (entsel "\nSelect PipeLine : "). entsel returns a value as list with two elements. First is entity name and second is point you select on screen.
Save these two values as two variables, using car and cadr. entity_name (car entity1). p1 (cadr entity1)
Subroutine entget returns database of the entity. Its syntax is (entget entity_name). In this case it retuns value as a list ((-1 .
) (0 . "LINE") (330 . ) (5 . "96") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbLine") (10 23.98 17.6331 0.0) (11 34.3707 26.1624 0.0) (210 0.0 0.0 1.0))
The returned list has a number of Dotted pairs. These are two elements separated by point. Important in this case are pairs with 0. 8. 10. and 11. We will these one by one. 0 is associated with entity type. 8 is associated with layer. 10 is associated with starting point in case of line. 11 is associated with ending point in case of line.
Assoc is used to get the value associated with first number of dotted pair from the data base returned for the entity. (setq p101 (cdr (assoc 10 (entget entity_name))) p102 (cdr (assoc 11 (entget entity_name)))). Subroutine cdr removes first element of the list and selects second element, which is used for assoc. Hence p101 is starting point of line and p102 is end point of line.
Subroutine angle accepts two points and returns angle in radians, with respect to current ucs. Angle is in counter clockwise direction with 3'o clock position as 0 radian. Subroutine getangle is similar. It accepts two points on screen, (getangle “string”) and returns angle in radians.
Subroutine distance accepts two points, (distance point1 point2) and returns distance between those two points.
Subroutine get distance is similar. It accepts two points on screen, (get distance “string”) and returns distance between those two points.
Earlier point p1 selected by entsel may not lie on line. Now we redefine it using polar function. (polar start_point angle distance). It will now pick a point p1 on the line.
Now set other points, considering length of valves as 10 and widith as 6.
First use break command to break the line. Break command asks first to select entity and uses that point as first point. However you can select first point by "f" and select p2 as first point and p3 as second point. Then use line command to draw the valve.
Program