Author Topic: Help with a code  (Read 1579 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Guest
Help with a code
« on: March 31, 2021, 01:54:32 AM »
Hi. I am trying to write a code for door frame. I want to trim the mangenta wall lines between the  two magenta vertical lines

Code - Auto/Visual Lisp: [Select]
  1.       (command "line" point1 point4 "")
  2.       (command "line" point2 point3 "")
  3.  

and i want to trim the windoor green (color 90) lines between the the  two green (color 90) vertical lines ,like the attach photo

Code - Auto/Visual Lisp: [Select]
  1.       (command "line" point5 point6 "")
  2.       (command "line" point7 point8 ""
  3.  

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ()
  2. (COMMAND "_layer" "_m" "WINDOOR" "_c" "90" "" "")
  3. (setvar "OSMODE" 41)
  4. (setq point1 (getpoint "\n1first insertion point:"))
  5. (if (/= point1 nil)
  6.   (setq point2 (getpoint "\n2second insertion point:"))
  7.   (if (/= point2 nil)
  8.    (progn  
  9.     (setq point3 (getpoint "\nopposite wall point:"))
  10.     (if (/= point3 nil)
  11.      (progn  
  12.       (setq x1 (car point1))
  13.       (setq y1 (cadr point1))
  14.       (setq h1 (caddr point1))
  15.       (setq x2 (car point2))
  16.       (setq y2 (cadr point2))
  17.       (setq h2 (caddr point2))
  18.       (setq x3 (car point3))
  19.       (setq y3 (cadr point3))
  20.       (setq h3 (caddr point3))
  21.       (setq gonia12 (+ (- (* 2 PI) (angle point1 point2)) (/ PI 2)))
  22.       (IF (> GONIA12 (* 2 PI)) (- GONIA12 (* 2 PI)))
  23.       (setq gonia21 (+ (- (* 2 PI) (angle point2 point1)) (/ PI 2)))
  24.       (IF (> GONIA21 (* 2 PI)) (- GONIA21 (* 2 PI)))
  25.       (setq gonia23 (+ (- (* 2 PI) (angle point2 point3)) (/ PI 2)))
  26.       (IF (> GONIA23 (* 2 PI)) (- GONIA23 (* 2 PI)))
  27.         (setq fld1 (rtos gonia12 3 4))
  28.         (setq fld2 (rtos gonia21 3 4))
  29.         (setq fld3 (rtos gonia23 3 4))
  30.         (prin1 (strcat "-->" fld1 fld2 fld3))
  31.       (setq anoigma (distance point1 point2))      
  32.       (setq paxos (distance point2 point3))
  33.       (setq x4 (+ x3 (* anoigma (sin gonia21))))      
  34.       (setq y4 (+ y3 (* anoigma (cos gonia21))))
  35.       (setq point4 (list x4 y4 0))    
  36.       (setq x5 (+ x1 (* 0.05 (sin gonia12))))      
  37.       (setq y5 (+ y1 (* 0.05 (cos gonia12))))
  38.       (setq point5 (list x5 y5 0))      
  39.       (setq x6 (+ x4 (* 0.05 (sin gonia12))))      
  40.       (setq y6 (+ y4 (* 0.05 (cos gonia12))))
  41.       (setq point6 (list x6 y6 0))      
  42.       (setq x7 (+ x2 (* 0.05 (sin gonia21))))      
  43.       (setq y7 (+ y2 (* 0.05 (cos gonia21))))
  44.       (setq point7 (list x7 y7 0))      
  45.       (setq x8 (+ x3 (* 0.05 (sin gonia21))))      
  46.       (setq y8 (+ y3 (* 0.05 (cos gonia21))))
  47.       (setq point8 (list x8 y8 0))
  48.      (command "OSNAP" "NONE" "")
  49.       (command "line" point1 point2 "")
  50.       (command "line" point3 point4 "")
  51.       (command "line" point5 point6 "")
  52.       (command "line" point7 point8 "")
  53.      (COMMAND "_layer" "_m" "WALLS" "_c" "6" "" "_lw" "0.5" "" "")
  54.       (command "line" point1 point4 "")
  55.       (command "line" point2 point3 "")
  56.       )
  57.      )
  58.     )
  59.    )
  60.   )
  61.  )
  62. )
  63.  


Thanks

PM

  • Guest
Re: Help with a code
« Reply #1 on: March 31, 2021, 06:25:18 AM »
any ideas?

d2010

  • Bull Frog
  • Posts: 323
Re: Help with a code
« Reply #2 on: March 31, 2021, 06:18:56 PM »

Code - Auto/Visual Lisp: [Select]
  1. (Defun dfn_enamk_line(p1 p2 la color lt / $rr nfl)
  2.   (if (=  color nil) (setq;|a20225|;
  3.          color 256)) (setq;|a20253|;
  4.          la (if (>  la "") la (getvar "CLAYER"))
  5.          p1 (append (list 10) p1)
  6.          p2 (append (list 11) p2)
  7.          nfl (list (cons 0 "LINE") (cons 100 "AcDbEntity") (cons 8 la) (cons 100 "AcDbLine") p1 p2 (cons 62 color))) (if (>  lt "") (setq;|a20545|;
  8.          nfl (append nfl (list (cons 6 lt))))) (setq;|a20601|;
  9.          $rr (entmakex nfl)) (princ)
  10. $rr)
  11.  

any ideas?
You replace the (command "line" point1 point2) with (dfn_enamk_line...)
Code: [Select]
     (command "OSNAP" "NONE" "")
      (command "line" point1 point2 "")
      (command "line" point3 point4 "")
      (command "line" point5 point6 "")
      (command "line" point7 point8 "")
     (COMMAND "_layer" "_m" "WALLS" "_c" "6" "" "_lw" "0.5" "" "")
      (command "line" point1 point4 "")
      (command "line" point2 point3 "")
:thinking:

« Last Edit: November 15, 2021, 05:52:20 PM by d2010 »

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Help with a code
« Reply #3 on: March 31, 2021, 07:44:33 PM »
If your interested this is very cheap, does windows and doors, roofs, elevations etc. Just PM me.



A man who never made a mistake never made anything

PM

  • Guest
Re: Help with a code
« Reply #4 on: April 01, 2021, 11:49:35 AM »
Hi d2010 . Thanks for the reply, but i can not understand your code

what is
Code - Auto/Visual Lisp: [Select]
  1.  $rr=  
  2.  { j_nop=car(j_new);
  3.  

I never use them before. And i can not see anywere the command trim in your code. I want  to trim the lines between magenta and color 90 like the attach photo

d2010

  • Bull Frog
  • Posts: 323
Re: Help with a code
« Reply #5 on: April 01, 2021, 02:06:17 PM »
Try this code.
You extract the command break
I do not push-here the mySource because I hope other user/s respond to you, other solution/s, more better, that I have my pocket.
« Last Edit: April 01, 2021, 02:25:45 PM by d2010 »

PM

  • Guest
Re: Help with a code
« Reply #6 on: April 02, 2021, 04:52:21 AM »
TEE lisp is not doing what i am searching for.

Thanks

d2010

  • Bull Frog
  • Posts: 323
Re: Help with a code
« Reply #7 on: April 02, 2021, 04:55:19 AM »
You,only,  extract the (command "break"..)  and you insert it into your-lisp.

apricot125

  • Mosquito
  • Posts: 13
Re: Help with a code
« Reply #8 on: November 07, 2021, 09:54:29 PM »
layer and color need adjusted by youself. How to upload a picture?
Code: [Select]
(defun GetUserInput ( / p1 p2 p3 osmd)
  (setq osmd (getvar "OSMODE"))
  (setvar "OSMODE" 545)    ; nea + int + end
  (setq p1 (getpoint "\nthe first insertion point: "))
  (if (/= nil p1) (setq p2 (getpoint p1 "\nthe second insertion point: ")))
  (setvar "OSMODE" 128)   ; Per
  (if (/= nil p2) (setq p3 (getpoint p2 "\nthe opposite wall point: ")))
  (setvar "OSMODE" osmd)
  (list p1 p2 p3)
)


(defun DoorFrame(/ p1 p2 p3 p4 dist delta ang p5 p6 p7 p8 osmd ss cmd)
  (setq osmd (getvar "OSMODE") cmd (getvar "CMDECHO"))
  (setvar "OSMODE" 0)
  (setq Plist (GetUserInput))
  (setq p1 (car Plist) p2 (cadr Plist) p3 (caddr Plist))
  (if (or (not p1)(not p2)(not p3))
    (princ "\nFunction Canceled.")
    (progn
      (setq ang (angle p1 p2)
            delta 55          ; correct the value
            dist (distance p1 p2)
            p4 (polar p3 (+ pi ang) dist)
            p5 (polar p1 ang delta)
            p6 (polar p4 ang delta)
            p7 (polar p2 (+ pi ang) delta)
            p8 (polar p3 (+ pi ang) delta)
      )
      (command "_pline" p1 p4 "")
      (setq ss (ssadd))
      (ssadd (entlast) ss)
      (command "_pline" p2 p3 "")
      (ssadd (entlast) ss)
      (command "_trim" ss "" "C" p7 p6 "")
      (command "_line" p1 p5 p6 p4 "")
      (command "_line" p2 p7 p8 p3 "")
    )  ; _ end of progn
  )  ; _ end of if
  (setvar "OSMODE" osmd)
  (setvar "CMDECHO" cmd)
  (princ)
)