### Author Topic: how to get two points and fix angle?  (Read 800 times)

0 Members and 1 Guest are viewing this topic.

#### masao

• Newt
• Posts: 65 ##### how to get two points and fix angle?
« on: October 28, 2023, 10:18:16 AM »
hi~

if i want draw a center line on cad2012 , how to get farthest 2 points draw the center line?

and if two lines angle are different but two lines are parallel. how to fix it? ex.0 and 360 or 90 and 270.

Code: [Select]
`(defun c:test()   (setvar "cmdecho" 0)   (setq en1 (entsel"firstline:"))   (setq en2 (entsel "secondline:"))   (setq p1a (cdr (assoc 10(entget (car en1)))))   (setq p1b (cdr (assoc 11 (entget (car en1)))))  (setq p2a (cdr (assoc 10 (entget (car en2)))))  (setq p2b (cdr (assoc 11(entget (car en2)))))  (setq ang1 (angle p1a p1b)        ang2 (angle p2a p2b)     )(if (or (equal (abs (- ang1 ang2)) pi 0.0001)         (= (- ang1 ang2) 0)         )  (command "line" (midpt p1a p2b) (midpt p1b p2a) "")  (command "line" (midpt p1a p2a) (midpt p1b p2b) "")  )  (command "chprop" "L" "" "lt" "center" "c" 2 "")  (prin1))(defun midpt(1% 2%)(polar 1% (angle 1% 2%) (*(distance 1% 2%)0.5)))`
« Last Edit: November 04, 2023, 10:26:39 PM by masao »

#### masao

• Newt
• Posts: 65 ##### Re: how to get two points and fix angle?
« Reply #1 on: November 04, 2023, 10:33:22 PM »
hi~

if i want draw a center line on cad2012 , how to get farthest 2 points draw the center line?

and if two lines angle are different but two lines are parallel. how to fix it? ex.0 and 360 or 90 and 270.

Code: [Select]
`(defun c:test()   (setvar "cmdecho" 0)   (setq en1 (entsel"firstline:"))   (setq en2 (entsel "secondline:"))   (setq p1a (cdr (assoc 10(entget (car en1)))))   (setq p1b (cdr (assoc 11 (entget (car en1)))))  (setq p2a (cdr (assoc 10 (entget (car en2)))))  (setq p2b (cdr (assoc 11(entget (car en2)))))  (setq ang1 (angle p1a p1b)        ang2 (angle p2a p2b)     )(if (or (equal (abs (- ang1 ang2)) pi 0.0001)         (= (- ang1 ang2) 0)         )  (command "line" (midpt p1a p2b) (midpt p1b p2a) "")  (command "line" (midpt p1a p2a) (midpt p1b p2b) "")  )  (command "chprop" "L" "" "lt" "center" "c" 2 "")  (prin1))(defun midpt(1% 2%)(polar 1% (angle 1% 2%) (*(distance 1% 2%)0.5)))`

• Newt
• Posts: 139 ##### Re: how to get two points and fix angle?
« Reply #2 on: November 19, 2023, 07:42:51 PM »
Heres a tip, you dont have to consider the angles of those lines.
You make a bounding box surrounding two parallel lines,

Then your problem will be solved

The bounding box is parallel to the direction of your line, and the middle line is the center line you want including the farthest point.

The code I wrote uses XDRX-API，which can be downloaded from github.com and is updated at any time.
===================================
[XDrx-Sub Forum]
https://www.theswamp.org/index.php?board=78.0

• Newt
• Posts: 139 ##### Re: how to get two points and fix angle?
« Reply #3 on: November 19, 2023, 09:19:12 PM »
Code - Auto/Visual Lisp: [Select]
1. ;|
2. Draw two straight center lines
3. |;
4. (defun c:tt (/ ss e1 e2 xdir box p1 p2)
5.     (and (setq ss (xdrx-ssget
6.                     "\nSelect two parallel straight lines <Exit>:"
7.                     '((0 . "line"))
8.                   );ssget with prompt string
9.          )
10.          (setq e1 (ssname ss 0)
11.                e2 (ssname ss 1)
12.          )
13.     )
14.        (xdrx-begin)
15.        (xdrx_document_setprec 1.0 3.0);Set the angle tolerance for judging parallelism, within 3 degrees
16.        (if (xdrx-getpropertyvalue e1 "isParallelTo" e2);Angle tolerance, parallel within 3 degrees
17.            (setq xdir (xdrx-getpropertyvalue e1 "xdir");X-direction unit vector of line 1
18.                  box  (xdrx-entity-box ss xdir);Parallel bounding boxes in the direction of the X vector
19.                  p1   (xd::geom:get9pt box 4)
20.                  p2   (xd::geom:get9pt box 6)
21.            )
22.            (xdrx-line-make p1 p2); draw line
23.            (XD::Doc:DrawCrossHair p1 0.0 0.02);Draw screen crossing vector lines
24.            (XD::Doc:DrawCrossHair p2 0.0 0.02)
25.          )
26.            (xdrx-prompt
27.              "\nThe two selected straight lines are not parallel.Retry..."
28.            )
29.          )
30.        )
31.        (xdrx-end)
32.      )
33.   )
34.   (princ)
35. )
36.

=============

The above LISP code uses the XDRX-API, which can be downloaded from https://github.com/xdcad/XDrx-API and is updated at any time.

The XDRX API encapsulates AcDb, AcEd, AcGe, AcBr... C++ library, using C++ methods to develop LISP programs.Thousands of Lisp functions are available.
Modify message
« Last Edit: November 19, 2023, 09:23:04 PM by xdcad »
The code I wrote uses XDRX-API，which can be downloaded from github.com and is updated at any time.
===================================
[XDrx-Sub Forum]
https://www.theswamp.org/index.php?board=78.0

#### masao

• Newt
• Posts: 65 ##### Re: how to get two points and fix angle?
« Reply #4 on: November 21, 2023, 09:27:35 AM »
Code - Auto/Visual Lisp: [Select]
1. ;|
2. Draw two straight center lines
3. |;
4. (defun c:tt (/ ss e1 e2 xdir box p1 p2)
5.     (and (setq ss (xdrx-ssget
6.                     "\nSelect two parallel straight lines <Exit>:"
7.                     '((0 . "line"))
8.                   );ssget with prompt string
9.          )
10.          (setq e1 (ssname ss 0)
11.                e2 (ssname ss 1)
12.          )
13.     )
14.        (xdrx-begin)
15.        (xdrx_document_setprec 1.0 3.0);Set the angle tolerance for judging parallelism, within 3 degrees
16.        (if (xdrx-getpropertyvalue e1 "isParallelTo" e2);Angle tolerance, parallel within 3 degrees
17.            (setq xdir (xdrx-getpropertyvalue e1 "xdir");X-direction unit vector of line 1
18.                  box  (xdrx-entity-box ss xdir);Parallel bounding boxes in the direction of the X vector
19.                  p1   (xd::geom:get9pt box 4)
20.                  p2   (xd::geom:get9pt box 6)
21.            )
22.            (xdrx-line-make p1 p2); draw line
23.            (XD::Doc:DrawCrossHair p1 0.0 0.02);Draw screen crossing vector lines
24.            (XD::Doc:DrawCrossHair p2 0.0 0.02)
25.          )
26.            (xdrx-prompt
27.              "\nThe two selected straight lines are not parallel.Retry..."
28.            )
29.          )
30.        )
31.        (xdrx-end)
32.      )
33.   )
34.   (princ)
35. )
36.

=============

The above LISP code uses the XDRX-API, which can be downloaded from https://github.com/xdcad/XDrx-API and is updated at any time.

The XDRX API encapsulates AcDb, AcEd, AcGe, AcBr... C++ library, using C++ methods to develop LISP programs.Thousands of Lisp functions are available.
Modify message

use vlax-lisp can write it?