See the top rated post in this thread. Click here

Results 1 to 4 of 4

Thread: Trim between two lines

  1. #1
    topomav
    Guest
    Login to Give a bone
    0

    Default Trim between two lines

    Hi i write this code to draw the frame of a door. I am trying to trim the lines of the wall when I draw the frame but I can not succes to trim automatically .

    Code:
    (defun c:doorframe ()
    (command "_layer" "_m" "WINDOOR" "_c" "90" "" "")
    (setvar "OSMODE" 41) 
    (setq point1 (getpoint "\n1st insertion point:"))
    (if (/= point1 nil)
     (progn
      (setq point2 (getpoint "\n2nd insertion point:"))
      (if (/= point2 nil)
       (progn  
        (setq point3 (getpoint "\n Opposite wall point:"))
        (if (/= point3 nil)
         (progn  
          (setq x1 (car point1))
          (setq y1 (cadr point1))
          (setq h1 (caddr point1))
          (setq x2 (car point2))
          (setq y2 (cadr point2))
          (setq h2 (caddr point2))
          (setq x3 (car point3))
          (setq y3 (cadr point3))
          (setq h3 (caddr point3))
          (setq gonia12 (+ (- (* 2 PI) (angle point1 point2)) (/ PI 2)))
          (IF (> GONIA12 (* 2 PI)) (- GONIA12 (* 2 PI)))
          (setq gonia21 (+ (- (* 2 PI) (angle point2 point1)) (/ PI 2)))
          (IF (> GONIA21 (* 2 PI)) (- GONIA21 (* 2 PI)))
          (setq gonia23 (+ (- (* 2 PI) (angle point2 point3)) (/ PI 2)))
          (IF (> GONIA23 (* 2 PI)) (- GONIA23 (* 2 PI)))
          (setq fld1 (rtos gonia12 3 4))
          (setq fld2 (rtos gonia21 3 4))
          (setq fld3 (rtos gonia23 3 4))
          (prin1 (strcat "-->" fld1 fld2 fld3))
          (setq anoigma (distance point1 point2))      
          (setq paxos (distance point2 point3))
          (setq x4 (+ x3 (* anoigma (sin gonia21))))       
          (setq y4 (+ y3 (* anoigma (cos gonia21))))
          (setq point4 (list x4 y4 0))     
          (setq x5 (+ x1 (* 0.05 (sin gonia12))))       
          (setq y5 (+ y1 (* 0.05 (cos gonia12))))
          (setq point5 (list x5 y5 0))       
          (setq x6 (+ x4 (* 0.05 (sin gonia12))))       
          (setq y6 (+ y4 (* 0.05 (cos gonia12))))
          (setq point6 (list x6 y6 0))       
          (setq x7 (+ x2 (* 0.05 (sin gonia21))))       
          (setq y7 (+ y2 (* 0.05 (cos gonia21))))
          (setq point7 (list x7 y7 0))       
          (setq x8 (+ x3 (* 0.05 (sin gonia21))))       
          (setq y8 (+ y3 (* 0.05 (cos gonia21))))
          (setq point8 (list x8 y8 0))
          (command "OSNAP" "NONE" "")
          (command "line" point1 point5 "")
          (command "line" point2 point7 "")
          (command "line" point3 point8 "")
          (command "line" point4 point6 "")
          (command "line" point5 point6 "")
          (command "line" point7 point8 "")
          (command "_layer" "_m" "WALLS-2D" "_c" "6" "" "_lw" "0.5" "" "")
          (command "line" point1 point4 "")
          (command "line" point2 point3 "")
          (command "_trim" point1 point2 "")
          (command "_trim" point4 point3 "")
          )
         )
        )
       )
      )
     )
    );--- end defun
    Attached Images Attached Images
    Last edited by Razor; 2022-12-14 at 02:13 PM.

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    1

    Default Re: Trim between two lines

    It may be a language translation error, but your code is a little difficult to follow.

    Your multiple if statements at the beginning could be reduced to one if statement by using the and function as the conditional. You could then place each getpoint statement within the and function. If any of the getpoints returns nil, the routine does not continue.

    In your getpoint statement for points 2 and 3, you could include the previous point as the first argument of the getpoint function to allow for rubber-banding. It would help for point 3 particularly as it would allow for the usage of a perpendicular osnap.

    You other if statements to check GONIA## are only calculating a number but not updating the variable.

    Now to your trim question. You have calculated all of your points you will use for the lines. Instead of the trim command, you might consider the break command. You may also move the break earlier in your code to before drawing the lines to reduce the amount of items the break command would have to consider.
    Code:
    (defun c:doorframe (/      x1     y1     h1     x2     y2     h2
                        x3     y3     h3     gonia12       gonia21
                        gonia23       fld1   fld2   fld3   anoigma
                        paxos  x4     y4     x5     y5     x6     y6
                        x7y7   x8     y8     point4 point5 point6 point7
                        point8
                       )
    
      (defun _getGonia (pointa pointb / gonia)
        (setq gonia (+ (- (* 2 pi) (angle pointa pointb)) (/ pi 2)))
        (if (> gonia (* 2 pi))
          (setq gonia (- gonia (* 2 pi)))
        )
        gonia
      )
      (command "_layer" "_m" "WINDOOR" "_c" "90" "" "")
      (setvar "OSMODE" 41)
      (if (and
            (setq point1 (getpoint "\n1st insertion point:"))
            (setq point2 (getpoint point1 "\n2nd insertion point:"))
            (setq point3 (getpoint point2 "\n Opposite wall point:"))
          )
        (progn
          (setq x1 (car point1))
          (setq y1 (cadr point1))
          (setq h1 (caddr point1)) ;;<- not used
          (setq x2 (car point2))
          (setq y2 (cadr point2))
          (setq h2 (caddr point2)) ;;<- not used
          (setq x3 (car point3))
          (setq y3 (cadr point3))
          (setq h3 (caddr point3)) ;;<- not used
    
          ;; Calculate gonia between points
          ;; moved the recurring code into a sub-routine to reduce
          (setq gonia12 (_getGonia point1 point2))
          (setq gonia21 (_getGonia point2 point1))
          (setq gonia23 (_getGonia point2 point3))
    
          ;; Convert gonia to string
          (setq fld1 (rtos gonia12 3 4))
          (setq fld2 (rtos gonia21 3 4))
          (setq fld3 (rtos gonia23 3 4))
          ;; Report gonia strings
          (prin1 (strcat "-->" fld1 fld2 fld3))
          
          (setq anoigma (distance point1 point2))
          (setq paxos (distance point2 point3))
          
          (setq x4 (+ x3 (* anoigma (sin gonia21))))
          (setq y4 (+ y3 (* anoigma (cos gonia21))))
          (setq point4 (list x4 y4 0))
          (setq x5 (+ x1 (* 0.05 (sin gonia12))))
          (setq y5 (+ y1 (* 0.05 (cos gonia12))))
          (setq point5 (list x5 y5 0))
          (setq x6 (+ x4 (* 0.05 (sin gonia12))))
          (setq y6 (+ y4 (* 0.05 (cos gonia12))))
          (setq point6 (list x6 y6 0))
          (setq x7 (+ x2 (* 0.05 (sin gonia21))))
          (setq y7 (+ y2 (* 0.05 (cos gonia21))))
          (setq point7 (list x7 y7 0))
          (setq x8 (+ x3 (* 0.05 (sin gonia21))))
          (setq y8 (+ y3 (* 0.05 (cos gonia21))))
          (setq point8 (list x8 y8 0))
    
          (command "OSNAP" "NONE" "")
          ;; Break frame opening
          (command "_trim" "" "m2p" point1 point2 "m2p" point4 point3 "")
    
          (command "line" point1 point5 "")
          (command "line" point2 point7 "")
          (command "line" point3 point8 "")
          (command "line" point4 point6 "")
          (command "line" point5 point6 "")
          (command "line" point7 point8 "")
          (command "_layer" "_m" "WALLS-2D" "_c" "6" "" "_lw" "0.5" "" "")
          (command "line" point1 point4 "")
          (command "line" point2 point3 "")
        )
      )
    )
    Another thing you may consider is to localize your variables to reduce unexpected results from reusing variable names between routines.
    Last edited by Opie; 2022-12-14 at 05:35 PM. Reason: tweaked based on new information
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    topomav
    Guest
    Login to Give a bone
    0

    Default Re: Trim between two lines

    Hi Opie. I test your code. But not trim the wall
    Attached Files Attached Files

  4. #4
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Trim between two lines

    I was wondering how you were locating your points. The additional lines you show in your test were not shown in your original post. The routine is breaking the additional lines instead of the wall lines. I've adjusted my code in the post above.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

Similar Threads

  1. 2018: Stretch Two Lines in Two Different Angles
    By archie.manza in forum Dynamic Blocks - Technical
    Replies: 2
    Last Post: 2017-05-04, 02:25 PM
  2. Trim lines and annotations between Crop Region
    By defreestijl209041 in forum Revit Architecture - General
    Replies: 2
    Last Post: 2012-02-19, 11:25 PM
  3. Trim not trimming back to selected trim boundary
    By Wwhite72082 in forum AutoCAD General
    Replies: 7
    Last Post: 2007-03-23, 01:47 PM
  4. Columns and beams: to trim or not to trim?
    By patricks in forum Revit Architecture - General
    Replies: 0
    Last Post: 2006-02-16, 03:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •