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))
)

xdcad

  • 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
https://github.com/xdcad/XDrx-API
http://bbs.xdcad.net

xdcad

  • 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.   (while
  6.     (and (setq ss (xdrx-ssget
  7.                     "\nSelect two parallel straight lines <Exit>:"
  8.                     '((0 . "line"))
  9.                   );ssget with prompt string
  10.          )
  11.          (setq e1 (ssname ss 0)
  12.                e2 (ssname ss 1)
  13.          )
  14.     )
  15.      (progn
  16.        (xdrx-begin)
  17.        (xdrx_document_setprec 1.0 3.0);Set the angle tolerance for judging parallelism, within 3 degrees
  18.        (if (xdrx-getpropertyvalue e1 "isParallelTo" e2);Angle tolerance, parallel within 3 degrees
  19.          (progn
  20.            (setq xdir (xdrx-getpropertyvalue e1 "xdir");X-direction unit vector of line 1
  21.                  box  (xdrx-entity-box ss xdir);Parallel bounding boxes in the direction of the X vector
  22.                  p1   (xd::geom:get9pt box 4)
  23.                  p2   (xd::geom:get9pt box 6)
  24.            )
  25.            (xdrx-line-make p1 p2); draw line
  26.            (XD::Doc:DrawCrossHair p1 0.0 0.02);Draw screen crossing vector lines
  27.            (XD::Doc:DrawCrossHair p2 0.0 0.02)
  28.          )
  29.          (progn
  30.            (xdrx-prompt
  31.              "\nThe two selected straight lines are not parallel.Retry..."
  32.            )
  33.          )
  34.        )
  35.        (xdrx-end)
  36.      )
  37.   )
  38.   (princ)
  39. )
  40.  

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

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
https://github.com/xdcad/XDrx-API
http://bbs.xdcad.net

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.   (while
  6.     (and (setq ss (xdrx-ssget
  7.                     "\nSelect two parallel straight lines <Exit>:"
  8.                     '((0 . "line"))
  9.                   );ssget with prompt string
  10.          )
  11.          (setq e1 (ssname ss 0)
  12.                e2 (ssname ss 1)
  13.          )
  14.     )
  15.      (progn
  16.        (xdrx-begin)
  17.        (xdrx_document_setprec 1.0 3.0);Set the angle tolerance for judging parallelism, within 3 degrees
  18.        (if (xdrx-getpropertyvalue e1 "isParallelTo" e2);Angle tolerance, parallel within 3 degrees
  19.          (progn
  20.            (setq xdir (xdrx-getpropertyvalue e1 "xdir");X-direction unit vector of line 1
  21.                  box  (xdrx-entity-box ss xdir);Parallel bounding boxes in the direction of the X vector
  22.                  p1   (xd::geom:get9pt box 4)
  23.                  p2   (xd::geom:get9pt box 6)
  24.            )
  25.            (xdrx-line-make p1 p2); draw line
  26.            (XD::Doc:DrawCrossHair p1 0.0 0.02);Draw screen crossing vector lines
  27.            (XD::Doc:DrawCrossHair p2 0.0 0.02)
  28.          )
  29.          (progn
  30.            (xdrx-prompt
  31.              "\nThe two selected straight lines are not parallel.Retry..."
  32.            )
  33.          )
  34.        )
  35.        (xdrx-end)
  36.      )
  37.   )
  38.   (princ)
  39. )
  40.  

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

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?