Author Topic: Automatically draw a vertical line to a point of another already drawn object  (Read 723 times)

0 Members and 1 Guest are viewing this topic.

mhy3sx

  • Newt
  • Posts: 115
Hi ,I am trying to write a lisp code to automatically draw a vertical line to a point of another already drawn object (such as Line,Pline,arc,etc.)

I want to work like this :

1)First specify the side where the new line will be drawn
2)Specify the point on the already designed object
3)Ender the length of the new line (by number or distance on screen)

Look an example in gif file. I upload a test.dwg for the units of my template.

I am new in lisp.I try to start the code like this but i need help to finish the code.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:verline (pt1 pt2 pt3 pt4 pt5 l)
  2. (setvar "OSMODE" 513) ; END,NEAREST
  3. (setq pt1 (getpoint "\nPick point to specify the side where the new line will be drawn: "))
  4. (setq pt2 (getpoint "\nPick point on the already designed object: "))
  5. (setq pt3 (getpoint "\nPick 1st point for distance on screen: "))
  6. (setq pt4 (getpoint "\nPick 2nd point for distance on screen: "))
  7. ;---------------------------------------------------------------------------------------------------
  8.  
  9. (setq l (getdist (strcat "\n Give the length of the line: ")))
  10.  
  11. (setq l (distance pt3 pt4))  ; distance on screen
  12. ;---------------------------------------------------------------------------------------------------
  13.  
  14. (setq pt5   ;<----------------- correct angle point in correct length vertical to line
  15.  
  16.  
  17. (command "_line" "non" pt2 "non" pt5 "")
  18. (setvar "OSMODE" 13) ; NODE,END,CENTER
  19. ;layer 0
  20. (mapcar 'setvar '("clayer" "cecolor" "celtype" "celweight")  (list "0" "BYLAYER" "BYLAYER" -1))
  21. );end defun
  22.  


Thanks
« Last Edit: March 06, 2023, 11:05:08 AM by mhy3sx »

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Here, very quickly written, so untested...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:verline ( / pt1 pt2 pt3 pt4 pt5 l a )
  2.   (setq pt1 (getpoint "\nPick point to specify the side where the new line will be drawn: "))
  3.   (setq pt2 (getpoint "\nPick point on the already designed object: "))
  4.   (setq pt3 (getpoint "\nPick 1st point for distance on screen: "))
  5.   (setq pt4 (getpoint pt3 "\nPick 2nd point for distance on screen: "))
  6.   (initget 7)
  7.   (setq l (getdist pt2 "\nGive the length of the line: "))
  8.   (setq a (angle pt3 pt4))
  9.   (setq pt5 (polar pt2 a l))
  10.   (command "_.LINE" "non" pt2 "non" pt5 "")
  11.   (setvar "OSMODE" 13) ; NODE,END,CENTER
  12.   (mapcar 'setvar '("clayer" "cecolor" "celtype" "celweight")  (list "0" "BYLAYER" "BYLAYER" -1))
  13.   (princ)
  14. )
  15.  

HTH.
M.R.
« Last Edit: March 06, 2023, 11:09:51 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

mhy3sx

  • Newt
  • Posts: 115
Hi ribarm ,thanks for the reply. I think that is a mistake in the code
Quote
3)Ender the length of the new line (by number or distance on screen)

we can not have this the same time. We need an option , to give the distance or to pick to pick 2 point for the distance. How to do that?



Code - Auto/Visual Lisp: [Select]
  1.       (setq pt3 (getpoint "\nPick 1st point for distance on screen: "))
  2.       (setq pt4 (getpoint pt3 "\nPick 2nd point for distance on screen: "))
  3.       (initget 7)
  4.       (setq l (getdist pt2 "\nGive the length of the line: "))
  5.       (setq a (angle pt3 pt4))
  6.  

Thansk

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Just remove here pt2 :
(setq l (getdist pt2 "\nGive the length of the line: "))

(if I understood you correctly)...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

mhy3sx

  • Newt
  • Posts: 115
Hi ribarm,  Perhaps I didn't explain correct how this code I want to work.

1)First specify the side where the new line will be drawn  <- this is pt1
2)Specify the point on the already designed object <- this is pt2

pt1 and pt2 is not vertical
Then

3)Ender the length of the new line (by number or distance on screen)

4) Calculate  pt5 in vertical position with length  (from pt3 ,pt4  or given distance l )
5) Draw the line pt1 ,pt5

Like the gif file

For the correct angles look test.dwg my unit settings

Thanks

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Also untested...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:verline ( / osm pt1 pt2 pt3 pt4 pt5 d a1 a2 )
  2.  
  3.  
  4.   (setq osm (getvar (quote osmode)))
  5.   (setvar (quote osmode) 13)
  6.   (setq pt1 (getpoint "\nPick point to specify the side where the new line will be drawn: "))
  7.   (setq pt2 (getpoint pt1 "\nPick point on the already designed object: "))
  8.   (setq pt3 (getpoint "\nPick 1st point for distance on screen: "))
  9.   (setq pt4 (getpoint pt3 "\nPick 2nd point for distance on screen: "))
  10.   (setq d (distance pt3 pt4))
  11.   (setq pt5 (polar pt2 (if
  12.                          (<
  13.                            (distance
  14.                              pt1
  15.                              (polar
  16.                                pt2
  17.                                (setq a1
  18.                                  (+ (angle (list 0.0 0.0) (vlax-curve-getfirstderiv (car (nentselp pt2)) (vlax-curve-getparamatpoint (car (nentselp pt2)) pt2))) (* 0.5 pi)))
  19.                                1.0
  20.                              )
  21.                            )
  22.                            (distance
  23.                              pt1
  24.                              (polar
  25.                                pt2
  26.                                (setq a2
  27.                                  (- (angle (list 0.0 0.0) (vlax-curve-getfirstderiv (car (nentselp pt2)) (vlax-curve-getparamatpoint (car (nentselp pt2)) pt2))) (* 0.5 pi)))
  28.                                1.0
  29.                              )
  30.                            )
  31.                          )
  32.                          a1
  33.                          a2
  34.                        )
  35.                        d
  36.             )
  37.   )
  38.   (if command-s
  39.     (command-s "_.LINE" "non" pt2 "non" pt5 "")
  40.     (vl-cmdf "_.LINE" "non" pt2 "non" pt5 "")
  41.   )
  42.   (mapcar 'setvar '("osmode" "clayer" "cecolor" "celtype" "celweight")  (list osm "0" "BYLAYER" "BYLAYER" -1))
  43.   (princ)
  44. )
  45.  

Debugged and tested...
« Last Edit: March 06, 2023, 01:35:18 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

mhy3sx

  • Newt
  • Posts: 115
I have this error

Quote
Pick 2nd point for distance on screen: ; error: too few arguments

why ?

Thanks

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
I've updated the code...

Test it now...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

mhy3sx

  • Newt
  • Posts: 115
Thanks ribarm . Works fine.   :smitten: :smitten: