Author Topic: ==={Challenge}===Find the ridge lines of sloped roof  (Read 106836 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #225 on: August 10, 2023, 02:47:02 AM »
Still not good, but logic is correct, so it should work now better...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:roof-new-new-new ( / *error* mid _offset unit rlw offd inside-p collinear-p unique chkcircinside mc preprocess1 preprocess2 rem-vllvlli subprocess process done lw lwi lwx lwo ent enti lil lix lwnl ch el p1 p2 pp ppp ipp ippl vll vlli tll iplst lst ) ;;; cad, doc, spc, lay, vlll, vllli, tlll, f - global variables ;;;
  2.  
  3.  
  4.   (defun *error* ( m )
  5.     (if (and lwi (not (vlax-erased-p lwi)))
  6.       (entdel lwi)
  7.     )
  8.     (if (and enti (not (vlax-erased-p enti)))
  9.       (entdel enti)
  10.     )
  11.     (if (setq ppp (unique ppp))
  12.       (foreach pp ppp
  13.         (if (not (vl-some '(lambda ( x ) (and (not (equal (car x) pp 1e-6)) (not (equal (cadr x) pp 1e-6)) (not (equal (car x) (cadr x) 1e-6)) (collinear-p (car x) pp (cadr x)))) lil))
  14.           (entmake (list (cons 0 "POINT") (cons 10 pp) (cons 62 1)))
  15.         )
  16.       )
  17.     )
  18.     (if (= ch "No")
  19.       (while (setq el (entnext el))
  20.         (if (and el (not (vlax-erased-p el)))
  21.           (entdel el)
  22.         )
  23.       )
  24.     )
  25.     (if lil
  26.       (foreach li lil
  27.         (if (vl-some '(lambda ( x ) (and (not (equal (car li) x 1e-6)) (not (equal (cadr li) x 1e-6)) (not (equal (car li) (cadr li) 1e-6)) (collinear-p (car li) x (cadr li)))) ppp)
  28.           (setq lil (vl-remove li lil))
  29.           (if (vl-some '(lambda ( x ) (equal x (car li) 1e-6)) ppp)
  30.             (entmake (list (cons 0 "LINE") (cons 10 (car li)) (cons 11 (cadr li)) (cons 62 3)))
  31.           )
  32.         )
  33.       )
  34.     )
  35.     (command-s "_.-OVERKILL" "_ALL" "_T" "_Y" "" "")
  36.     (if (= 8 (logand 8 (getvar 'undoctl)))
  37.       (vla-endundomark doc)
  38.     )
  39.     (prompt "\nIf you want to start again on different sample, make sure you nil flag f : (setq f nil vlll nil vllli nil tlll nil) ...")
  40.     (if m
  41.       (prompt m)
  42.     )
  43.     (princ)
  44.   )
  45.  
  46.   (defun mid ( p1 p2 )
  47.     (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) p1 p2)
  48.   )
  49.  
  50.   (defun _offset ( lw dist / lill lww vl lwx tl tln iplst lws )
  51.     (setq vl (mapcar 'cdr (vl-remove-if '(lambda ( x ) (/= (car x) 10)) (setq lwx (entget lw)))))
  52.     (setq tl (mapcar '(lambda ( a b ) (list a b)) vl (append (cdr vl) (list (car vl)))))
  53.     (setq tln (mapcar '(lambda ( x ) (list (polar (car x) (+ (* 0.5 pi) (angle (car x) (cadr x))) (- dist)) (polar (cadr x) (+ (* 0.5 pi) (angle (car x) (cadr x))) (- dist)))) tl))
  54.     (setq iplst (mapcar '(lambda ( a b ) (inters (car a) (cadr a) (car b) (cadr b) nil)) tln (append (cdr tln) (list (car tln)))))
  55.     (setq lill (mapcar '(lambda ( a b ) (list a b)) iplst (append (cdr iplst) (list (car iplst)))))
  56.     (setq lill (vl-remove-if '(lambda ( x ) (or (null (car x)) (null (cadr x)))) lill))
  57.     (setq lws
  58.       (cons
  59.         (setq lww
  60.           (entmakex
  61.             (append
  62.               (list
  63.                 (cons 0 "LWPOLYLINE")
  64.                 (cons 100 "AcDbEntity")
  65.                 (cons 100 "AcDbPolyline")
  66.                 (cons 90 (length iplst))
  67.                 (cons 70 (1+ (* 128 (getvar 'plinegen))))
  68.                 (cons 38 0.0)
  69.               )
  70.               (mapcar '(lambda ( p ) (cons 10 p)) iplst)
  71.               (list (list 210 0.0 0.0 1.0))
  72.             )
  73.           )
  74.         )
  75.         lws
  76.       )
  77.     )
  78.   )
  79.  
  80.   (defun unit ( v / d )
  81.     (if (not (equal (setq d (distance '(0.0 0.0 0.0) v)) 0.0 1e-6))
  82.       (mapcar '(lambda ( x ) (/ x d)) v)
  83.     )
  84.   )
  85.  
  86.   (defun rlw ( lw / e x1 x2 x3 x4 x5 x6 )
  87.     ;; by ElpanovEvgeniy
  88.     (if (= (cdr (assoc 0 (setq e (entget lw)))) "LWPOLYLINE")
  89.       (progn
  90.         (foreach a1 e
  91.           (cond ((= (car a1) 10) (setq x2 (cons a1 x2)))
  92.                 ((= (car a1) 40) (setq x4 (cons (cons 41 (cdr a1)) x4)))
  93.                 ((= (car a1) 41) (setq x3 (cons (cons 40 (cdr a1)) x3)))
  94.                 ((= (car a1) 42) (setq x5 (cons (cons 42 (- (cdr a1))) x5)))
  95.                 ((= (car a1) 210) (setq x6 (cons a1 x6)))
  96.                 (t (setq x1 (cons a1 x1)))
  97.           )
  98.         )
  99.         (entmod (append (reverse x1)
  100.                   (append (apply 'append
  101.                             (apply 'mapcar
  102.                               (cons 'list
  103.                                 (list x2
  104.                                   (cdr (reverse (cons (car x3) (reverse x3))))
  105.                                   (cdr (reverse (cons (car x4) (reverse x4))))
  106.                                   (cdr (reverse (cons (car x5) (reverse x5))))
  107.                                 )
  108.                               )
  109.                             )
  110.                           )
  111.                           x6
  112.                   )
  113.                 )
  114.         )
  115.         (entupd lw)
  116.       )
  117.     )
  118.   )
  119.  
  120.   (defun offd ( sign ip tl / dl )
  121.     (setq dl (mapcar '(lambda ( x )
  122.                         (distance ip
  123.                           (inters
  124.                             ip
  125.                             (polar ip (+ (* 0.5 pi) (angle (car x) (cadr x))) 1.0)
  126.                             (car x)
  127.                             (polar (car x) (angle (car x) (cadr x)) 1.0)
  128.                             nil
  129.                           )
  130.                         )
  131.                       ) tl
  132.               )
  133.     )
  134.     (vl-some '(lambda ( x )
  135.                (if
  136.                  (>
  137.                    (-
  138.                      (length dl)
  139.                      (length (vl-remove-if '(lambda ( y ) (equal x y 0.05)) dl))
  140.                    ) 2
  141.                  )
  142.                  x
  143.                )
  144.              ) (vl-sort dl sign)
  145.     )
  146.   )
  147.  
  148.   (defun inside-p ( p lw lwi )
  149.   )
  150.  
  151.   (defun collinear-p ( p1 p p2 )
  152.     (equal (distance p1 p2) (+ (distance p1 p) (distance p p2)) 1e-6)
  153.   )
  154.  
  155.   (defun unique ( pl )
  156.     (if pl
  157.       (cons (car pl)
  158.             (unique
  159.               (vl-remove-if
  160.                 '(lambda ( x )
  161.                    (equal x (car pl) 1e-6)
  162.                  )
  163.                 (cdr pl)
  164.               )
  165.             )
  166.       )
  167.     )
  168.   )
  169.  
  170.   (defun chkcircinside ( pp tll / d ci ipp ippl tst )
  171.     (if (and pp tll)
  172.       (progn
  173.         (setq ci (entmakex (list (cons 0 "CIRCLE") (cons 10 pp) (cons 40 (offd (function <) pp tll)))))
  174.         (if (setq ipp (vlax-invoke (vlax-ename->vla-object ci) 'intersectwith (vlax-ename->vla-object ent) acextendnone))
  175.           (progn
  176.             (while ipp
  177.               (setq ippl (cons (list (car ipp) (cadr ipp) (caddr ipp)) ippl))
  178.               (setq ipp (cdddr ipp))
  179.             )
  180.             (if (or (not ippl) (vl-every '(lambda ( x ) (inside-p x ent enti)) (apply 'append (mapcar '(lambda ( x ) (list (vlax-curve-getpointatparam ci (- x 0.1)) (vlax-curve-getpointatparam ci (+ x 0.1)))) (mapcar '(lambda ( x ) (vlax-curve-getparamatpoint ci x)) ippl)))))
  181.               (setq tst t)
  182.             )
  183.           )
  184.           (setq tst t)
  185.         )
  186.         (if (and ci (not (vlax-erased-p ci)))
  187.           (entdel ci)
  188.         )
  189.       )
  190.     )
  191.     tst
  192.   )
  193.  
  194.   (defun mc ( p lw / ci pl mp p1 p2 p3 p4 )
  195.     (setq ci (entmakex (list (cons 0 "CIRCLE") (cons 10 p) (cons 40 2.0))))
  196.     (setq pl (vlax-invoke (vlax-ename->vla-object ci) 'intersectwith (vlax-ename->vla-object lw) acextendnone))
  197.     (if (and ci (not (vlax-erased-p ci)))
  198.       (entdel ci)
  199.     )
  200.     (cond
  201.       ( (= (length pl) 12)
  202.         (setq p1 (list (car pl) (cadr pl)))
  203.         (setq p2 (list (nth 3 pl) (nth 4 pl)))
  204.         (setq p3 (list (nth 6 pl) (nth 7 pl)))
  205.         (setq p4 (list (nth 9 pl) (nth 10 pl)))
  206.         (cond
  207.           ( (vl-some '(lambda ( li ) (or (equal (unit (mapcar '- (car li) (cadr li))) (unit (mapcar '- (mid p1 p2) p)) 1e-3) (equal (unit (mapcar '- (car li) (cadr li))) (unit (mapcar '- p (mid p2 p1))) 1e-3))) lil)
  208.             (setq mp (mid p3 p4))
  209.           )
  210.           ( (vl-some '(lambda ( li ) (or (equal (unit (mapcar '- (car li) (cadr li))) (unit (mapcar '- (mid p2 p3) p)) 1e-3) (equal (unit (mapcar '- (car li) (cadr li))) (unit (mapcar '- p (mid p3 p2))) 1e-3))) lil)
  211.             (setq mp (mid p4 p1))
  212.           )
  213.           ( (vl-some '(lambda ( li ) (or (equal (unit (mapcar '- (car li) (cadr li))) (unit (mapcar '- (mid p3 p4) p)) 1e-3) (equal (unit (mapcar '- (car li) (cadr li))) (unit (mapcar '- p (mid p4 p3))) 1e-3))) lil)
  214.             (setq mp (mid p1 p2))
  215.           )
  216.           ( (vl-some '(lambda ( li ) (or (equal (unit (mapcar '- (car li) (cadr li))) (unit (mapcar '- (mid p4 p1) p)) 1e-3) (equal (unit (mapcar '- (car li) (cadr li))) (unit (mapcar '- p (mid p1 p4))) 1e-3))) lil)
  217.             (setq mp (mid p2 p3))
  218.           )
  219.         )
  220.       )
  221.       ( (= (length pl) 6)
  222.         (setq p1 (list (car pl) (cadr pl)))
  223.         (setq p2 (list (nth 3 pl) (nth 4 pl)))
  224.         (setq mp (mid p1 p2))
  225.       )
  226.     )
  227.     (list p mp)
  228.   )
  229.  
  230.   (defun preprocess1 ( vl vli / ip ) ;;; iplst - lexical global variable
  231.     (setq iplst (mapcar '(lambda ( p1 p2 p3 p4 / ip )
  232.                           (if
  233.                             (and
  234.                               (setq ip (inters p1 p2 p3 p4 nil))
  235.                               (inside-p ip ent enti)
  236.                               (equal (unit (mapcar '- ip p1)) (unit (mapcar '- p2 p1)) 1e-6)
  237.                               (equal (unit (mapcar '- ip p3)) (unit (mapcar '- p4 p3)) 1e-6)
  238.                               (inside-p (mapcar '+ p1 (mapcar '* (unit (mapcar '- ip p1)) (list 1e-2 1e-2))) ent enti)
  239.                               (inside-p (mapcar '+ p3 (mapcar '* (unit (mapcar '- ip p3)) (list 1e-2 1e-2))) ent enti)
  240.                             )
  241.                             (list ip (list p1 p3))
  242.                             (list nil nil)
  243.                           )
  244.                         )
  245.                         vl
  246.                         vli
  247.                         (append (cdr vl) (list (car vl)))
  248.                         (append (cdr vli) (list (car vli)))
  249.                 )
  250.     )
  251.     iplst
  252.   )
  253.  
  254.   (defun preprocess2 ( vl vli / ip ) ;;; iplst - lexical global variable
  255.     (setq iplst (mapcar '(lambda ( p1 p2 p3 p4 / ip )
  256.                           (if
  257.                             (and
  258.                               (setq ip (inters p1 p2 p3 p4 nil))
  259.                               (inside-p ip ent enti)
  260.                               (equal (unit (mapcar '- ip p1)) (unit (mapcar '- p2 p1)) 1e-6)
  261.                               (equal (unit (mapcar '- ip p3)) (unit (mapcar '- p4 p3)) 1e-6)
  262.                               (inside-p (mapcar '+ p1 (mapcar '* (unit (mapcar '- ip p1)) (list 1e-2 1e-2))) ent enti)
  263.                               (inside-p (mapcar '+ p3 (mapcar '* (unit (mapcar '- ip p3)) (list 1e-2 1e-2))) ent enti)
  264.                             )
  265.                             (list ip (list p1 p3))
  266.                             (list nil nil)
  267.                           )
  268.                         )
  269.                         vl
  270.                         vli
  271.                         (mapcar '(lambda ( x ) (car (mc (caar lil) (cond ( (ssname (ssget "_C" (caar lil) (caar lil) '((0 . "LWPOLYLINE"))) 0) ) ( entlast ))))) vl)
  272.                         (mapcar '(lambda ( x ) (cadr (mc (caar lil) (cond ( (ssname (ssget "_C" (caar lil) (caar lil) '((0 . "LWPOLYLINE"))) 0) ) ( entlast ))))) vli)
  273.                 )
  274.     )
  275.     iplst
  276.   )
  277.  
  278.   (defun rem-vllvlli ( lil )
  279.     (if (vl-some '(lambda ( x ) (equal x (cadr (car lil)) 1e-2)) vll)
  280.       (progn
  281.         (setq vll (vl-remove-if '(lambda ( x ) (equal (cadr (car lil)) x 1e-2)) vll))
  282.         (setq vlli (vl-remove-if '(lambda ( x ) (equal (cadr (car lil)) x 1e-2)) vlli))
  283.       )
  284.     )
  285.     (if (vl-some '(lambda ( x ) (equal x (cadr (cadr lil)) 1e-2)) vll)
  286.       (progn
  287.         (setq vll (vl-remove-if '(lambda ( x ) (equal (cadr (cadr lil)) x 1e-2)) vll))
  288.         (setq vlli (vl-remove-if '(lambda ( x ) (equal (cadr (cadr lil)) x 1e-2)) vlli))
  289.       )
  290.     )
  291.   )
  292.  
  293.   (defun subprocess ( iplst flag / p1 p2 pp1 pp2 )
  294.     (setq iplst (vl-remove-if '(lambda ( x ) (or (null (car x)) (null (cadr x)))) iplst))
  295.     (setq iplstoffd (mapcar '(lambda ( x ) (if (and (car x) (cadr x))
  296.                                              (list
  297.                                                (mapcar '+ '(0.0 0.0) (car x))
  298.                                                (mapcar '(lambda ( y ) (mapcar '+ '(0.0 0.0) y)) (cadr x))
  299.                                                (offd (function <) (mapcar '+ '(0.0 0.0) (car x)) tlll)
  300.                                              )
  301.                                              (list nil nil nil)
  302.                                            )
  303.                              ) iplst
  304.                     )
  305.     )
  306.     (setq iplstoffd (vl-remove-if '(lambda ( x ) (null (caddr x))) iplstoffd))
  307.     (if (not flag)
  308.       (setq iplstoffd (vl-sort iplstoffd '(lambda ( a b ) (< (caddr a) (caddr b)))))
  309.       (setq iplstoffd (vl-sort iplstoffd '(lambda ( a b ) (if (equal (caddr a) (caddr b) 1e-6) (< (distance (car a) (caar lst)) (distance (car b) (caar lst))) (< (caddr a) (caddr b))))))
  310.     )
  311.     (if (not (vl-position (car iplstoffd) lst))
  312.       (setq ipd (car iplstoffd) lst (cons ipd lst))
  313.       (progn
  314.         (setq iplstoffd (cdr (member (car lst) iplstoffd)))
  315.         (setq ipd (car iplstoffd) lst (cons ipd lst))
  316.       )
  317.     )
  318.     (if (and ipd (chkcircinside (car ipd) tlll))
  319.       (progn
  320.         (setq ppp (cons (car ipd) ppp))
  321.         (if
  322.           (and
  323.             (setq p1
  324.               (vl-some '(lambda ( x )
  325.                 (if
  326.                   (equal
  327.                     (unit (mapcar '- (car ipd) x))
  328.                     (unit (mapcar '- (car ipd) (caadr ipd)))
  329.                     1e-6
  330.                   )
  331.                   x
  332.                 )
  333.               ) vll
  334.               )
  335.             )
  336.             (setq pp1
  337.               (vl-some '(lambda ( x )
  338.                 (if
  339.                   (equal
  340.                     (unit (mapcar '- (car ipd) x))
  341.                     (unit (mapcar '- (car ipd) p1))
  342.                     1e-6
  343.                   )
  344.                   x
  345.                 )
  346.               ) vlll
  347.               )
  348.             )
  349.           )
  350.           (setq lil (cons (list (car ipd) pp1) lil))
  351.           (if p1
  352.             (setq lil (cons (list (car ipd) p1) lil))
  353.             (setq lil (cons (list (car ipd) (caadr ipd)) lil))
  354.           )
  355.         )
  356.         (if
  357.           (and
  358.             (setq p2
  359.               (vl-some '(lambda ( x )
  360.                 (if
  361.                   (equal
  362.                     (unit (mapcar '- (car ipd) x))
  363.                     (unit (mapcar '- (car ipd) (cadadr ipd)))
  364.                     1e-6
  365.                   )
  366.                   x
  367.                 )
  368.               ) vll
  369.               )
  370.             )
  371.             (setq pp2
  372.               (vl-some '(lambda ( x )
  373.                 (if
  374.                   (equal
  375.                     (unit (mapcar '- (car ipd) x))
  376.                     (unit (mapcar '- (car ipd) p2))
  377.                     1e-6
  378.                   )
  379.                   x
  380.                 )
  381.               ) vlll
  382.               )
  383.             )
  384.           )
  385.           (setq lil (cons (list (car ipd) pp2) lil))
  386.           (if p2
  387.             (setq lil (cons (list (car ipd) p2) lil))
  388.             (setq lil (cons (list (car ipd) (cadadr ipd)) lil))
  389.           )
  390.         )
  391.         (if
  392.           (and
  393.             (caddr ipd)
  394.             (setq lwnl (vl-catch-all-apply '_offset (list ent (- (caddr ipd)))))
  395.           )
  396.           (if (and lwnl (vl-catch-all-error-p lwnl))
  397.             (setq done t)
  398.           )
  399.         )
  400.         (cond
  401.           ( (and lwnl (not (vl-catch-all-error-p lwnl)) (= (length lwnl) 1))
  402.             (rem-vllvlli lil)
  403.           )
  404.           ( (and lwnl (not (vl-catch-all-error-p lwnl)) (> (length lwnl) 1))
  405.             (setq lwnl (vl-sort lwnl '(lambda ( a b ) (< (distance (car ipd) (vlax-curve-getclosestpointto a (car ipd))) (distance (car ipd) (vlax-curve-getclosestpointto b (car ipd)))))))
  406.             (rem-vllvlli lil)
  407.           )
  408.         )
  409.       )
  410.     )
  411.     lwnl
  412.   )
  413.  
  414.   (defun process ( lw / lwi lwx vl vli iplst tl lwnl ) ;;; vll, vlli, tll, lwnl, ppp, done, flag - lexical global variables ;;;
  415.     (if lw
  416.       (progn
  417.         (setq vl (mapcar 'cdr (vl-remove-if '(lambda ( x ) (/= (car x) 10)) (setq lwx (entget lw)))))
  418.         (if (not vll)
  419.           (setq vll vl)
  420.         )
  421.         (setq lwi (vlax-vla-object->ename (car (vlax-invoke (vlax-ename->vla-object lw) 'offset -1e-3))))
  422.         (setq vli (mapcar 'cdr (vl-remove-if '(lambda ( x ) (/= (car x) 10)) (entget lwi))))
  423.         (if (not vlli)
  424.           (setq vlli vli)
  425.         )
  426.         (setq tl (mapcar '(lambda ( a b ) (list a b)) vl (append (cdr vl) (list (car vl)))))
  427.         (if (not tll)
  428.           (setq tll tl)
  429.         )
  430.         (setq iplst nil)
  431.         (setq iplst (preprocess1 vll vlli))
  432.         (subprocess iplst nil)
  433.         (repeat (length vll)
  434.           (setq iplst nil)
  435.           (setq iplst (preprocess2 vll vlli))
  436.           (subprocess iplst t)
  437.         )
  438.         (if (and lwi (not (vlax-erased-p lwi)))
  439.           (entdel lwi)
  440.         )
  441.         lwnl
  442.       )
  443.     )
  444.   )
  445.  
  446.   (or doc (setq doc (vla-get-activedocument cad)))
  447.   (or spc (setq spc (vla-get-block (setq lay (vla-get-activelayout doc)))))
  448.  
  449.   (if (= 8 (logand 8 (getvar 'undoctl)))
  450.     (vla-endundomark doc)
  451.   )
  452.   (if
  453.     (and
  454.       (setq lw (car (entsel "\nPick boundary closed polygonal LWPOLYLINE with only straight segments...")))
  455.       (= (cdr (assoc 0 (setq lwx (entget lw)))) "LWPOLYLINE")
  456.       (= 1 (logand 1 (cdr (assoc 70 lwx))))
  457.       (vl-every '(lambda ( x ) (= 0.0 (cdr x))) (vl-remove-if '(lambda ( x ) (/= (car x) 42)) lwx))
  458.       (setq el (entlast) ent lw)
  459.     )
  460.     (progn
  461.       (setq lwi (vlax-vla-object->ename (car (vlax-invoke (vlax-ename->vla-object lw) 'offset -1e-3))))
  462.       (if (> (vlax-curve-getarea lwi) (vlax-curve-getarea lw))
  463.         (setq lw (rlw lw)) ;;; force main lwpolyline CCW - counter clockwise ;;;
  464.       )
  465.       (setq enti (vlax-vla-object->ename (car (vlax-invoke (vlax-ename->vla-object ent) 'offset -1e-3))))
  466.       (if (and lwi (not (vlax-erased-p lwi)))
  467.         (entdel lwi)
  468.       )
  469.       (if (not f)
  470.         (progn
  471.           (setq vlll (mapcar 'cdr (vl-remove-if '(lambda ( x ) (/= (car x) 10)) (entget ent))))
  472.           (setq vllli (mapcar 'cdr (vl-remove-if '(lambda ( x ) (/= (car x) 10)) (entget enti))))
  473.           (setq tlll (mapcar '(lambda ( a b ) (list a b)) vlll (append (cdr vlll) (list (car vlll)))))
  474.           (setq f t)
  475.         )
  476.       )
  477.       (initget "Yes No")
  478.       (setq ch (cond ( (getkword "\nDo you want points-offsets-lines or just lines [Yes / No] <No> : ") ) ( "No" )))
  479.       (while (not done)
  480.         (if
  481.           (and
  482.             (not (vl-catch-all-error-p (setq lwnl (vl-catch-all-apply 'process (list lw)))))
  483.             lwnl
  484.           )
  485.           (while (and (not done) (setq lww (car (vl-sort lwnl '(lambda ( a b ) (> (vlax-curve-getarea a) (vlax-curve-getarea b)))))))
  486.             (setq lwnl (vl-remove lww lwnl))
  487.             (setq lwo lww)
  488.             (setq lwnl (vl-catch-all-apply 'process (list lww)))
  489.             (if (vl-catch-all-error-p lwnl)
  490.               (setq done t)
  491.               (if (eq (car lwnl) lwo)
  492.                 (setq done t)
  493.               )
  494.             )
  495.           )
  496.           (setq done t)
  497.         )
  498.       ) ;;; main engine ;;;
  499.     )
  500.   )
  501.   (*error* nil)
  502. )
  503.  

Regards, M.R.
« Last Edit: August 10, 2023, 05:32:12 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #226 on: August 11, 2023, 03:26:14 AM »
Who is interested in this over custom _offset sub function version, I've made few improvements, but still it doesn't solve but there is attempt which is pretty good for a start for experienced member that wants to continue... Also I've implemented *.lsp in archive at www.cadtutor.net download section...
If nothing, I've played with this challenge one more time...

Thanks for following, but I see there are no too much interest for roofs - hipped ones...
« Last Edit: August 14, 2023, 04:46:12 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #227 on: August 14, 2023, 02:49:38 AM »
Who is interested in this over custom _offset sub function version, I've made few improvements, but still it doesn't solve but there is attempt which is pretty good for a start for experienced member that wants to continue... Also I've implemented *.lsp in archive at www.cadtutor.net download section...
If nothing, I've played with this challenge one more time...

Thanks for following, but I see there are no too much interest for roofs - hipped ones...

Anyone?
You can download attachment from previous post and continue on that basis... We need fast and good code still... And I wanted to be used offset relations as this is correct path for correct solution...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8722
  • AKA Daniel
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #228 on: August 14, 2023, 05:05:03 AM »
Cool stuff, never had the need to draw sloped roofs. back when I was drafting, I was in New Mexico, most of the houses were Adobe, with flat roofs.
That, and I mostly did submittals for commercial casework

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #229 on: August 14, 2023, 05:15:54 AM »
Cool stuff, never had the need to draw sloped roofs. back when I was drafting, I was in New Mexico, most of the houses were Adobe, with flat roofs.
That, and I mostly did submittals for commercial casework

Daniel, if it was you downloaded my post, I must say that solution exist in archieve on www.cadtutor.net - download section... This was for fun and for me to see if it would behave correct with offsettings... But sadly I was wrong, so here is the link at cadtutor with all neccessary routines you may find for correct construct 2d+3d solutions and there are even hatches... Main one is : 2droof-final.lsp and others based on it... But I'd check firstly : hr.lsp and if it fails, then 2droof-final.lsp... There is also good command version : roof-command-new.lsp and my versions for finding random solutions based on input correct one (2droof-final.lsp)... Those are just possibilities and solution version works very slow, so if you want improvements for speed, this could be the task for challenging *.arx, or *.dll, or ...

Link : https://www.cadtutor.net/forum/files/file/36-hipped-roof-routines/
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #230 on: August 14, 2023, 05:18:51 PM »
I've changed (mc) sub function... Also I've changed the code all around where I founded it's necessity...

HTH., M.R.
« Last Edit: August 18, 2023, 11:46:01 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #231 on: August 18, 2023, 10:14:42 AM »
I have no feedback...

Could someone have a look into my attachment in previous post and give opinion, or better implement something I forgot...
It seems that this all looks like joke, but I've spent a lot of time to collect and compose and this version... So please, help by download and look, or give opinion ab things implemented or more yet to be implemented next...
C'mon show some courage...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ronjonp

  • Needs a day job
  • Posts: 7529
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #232 on: August 18, 2023, 12:13:26 PM »
I have no feedback...

Could someone have a look into my attachment in previous post and give opinion, or better implement something I forgot...
It seems that this all looks like joke, but I've spent a lot of time to collect and compose and this version... So please, help by download and look, or give opinion ab things implemented or more yet to be implemented next...
C'mon show some courage...
I just tried it and it does nothing ?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #233 on: August 18, 2023, 11:46:22 PM »
I have no feedback...

Could someone have a look into my attachment in previous post and give opinion, or better implement something I forgot...
It seems that this all looks like joke, but I've spent a lot of time to collect and compose and this version... So please, help by download and look, or give opinion ab things implemented or more yet to be implemented next...
C'mon show some courage...
I just tried it and it does nothing ?

It's because you probably tested routine on othogonal polygonal LWPOLYLINE... Try this mod. attached here - should throw triangles on porches...
But when it's needed to continue from there to build complete solution it stops around first continuation points all around, or make not correct connections... With ultimate roof, that's the case, it makes triangles, at few places correct continuation and then not correct connections over whole area from one side to opposite side of roof... So it's doing something, but wrong...
« Last Edit: August 23, 2023, 03:00:28 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #234 on: August 22, 2023, 05:21:00 AM »
@Ron

I can not say for sure that attached version will solve at least something as I am facing the same thing on some examples - throws nothing!!! But I've sorted some things as you can see if you download file from previous post... I will try some more fixing if I find spare time, but I doubt it'll be revolutionary fixing... Now I and anyone can see that this is challenge topic... But I tried on some different basis to approach things - by using custom (_offset) function... Anyway thanks for looking into this and feedbacking...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #235 on: August 24, 2023, 08:43:41 AM »
Hi, me again... I think I've connected what was the problem... I've removed 2 vvl and vvli upon sucessful connecting 2 lines, but also added vvl and vvli to apex of triangle (if it's somewhere in the beggining of calculations)... That with vvl and vvli should iterate all until there are no vvl and vvli... And there is the problem : (prout) sub catched error in it's operations... So routine either crashes before error handler output, or (while) loops into endless time... Either way I finished what should be working, but it's not... So I'll chill out for now until someone figures out and finish it all correctly...
Thanks for attention, M.R.
« Last Edit: September 21, 2023, 12:40:08 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #236 on: August 28, 2023, 09:43:28 AM »
I am stuck here with posted *.lsp in previous reply... Can someone see and solve it, or give opinion, suggestion, advice in right direction...
I've put also previous versions - last one is : roof-newest.lsp... Some new gurus, reply, please...

P.S. I doubt that someone will fix it as it has many lacks, but nevertheless, this was only for experimental purposes... Hope dies lastly, so we are waiting for valuable input...
« Last Edit: September 12, 2023, 09:03:02 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #237 on: September 02, 2023, 05:46:38 AM »
I didn't know that only @Ron came and commented what I posted... @Daniel is busy, but what ab @Cab, @Lee Mac, @Highflyingbird, @Evgeniy-@VovKa (if they are available for conflict situation in their countries)...
My latest intervention is roof-newest.lsp from pre-previous post... IMHO, it should bite and finish and somewhere that's the case, but there are examples where it throws forest of lines that don't have any relation to the code...
My sincerily best wishes to anyone reading and willing to help...
M.R.
« Last Edit: September 12, 2023, 09:05:38 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #238 on: September 02, 2023, 07:49:06 PM »
I have been following your comments as years ago did a house package that included roofs it was 3D based so roof pitch was included. We just used a method of making each section of roof using pface. had a number of options Hip, Gable, Straight, Flat etc Unfortunately the package never took off. It was overtaken by Autocad Architecture.

A man who never made a mistake never made anything

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #239 on: September 08, 2023, 04:14:54 PM »
Can someone have a look at my (mc) sub function and complete routine for lacks... I believe that (mc) function is the key for solving as much as possible... I am out of fuel for coding, but no one want to even download "roof-newest.lsp" and look - 4 eyes are more than 2... I believe that I am close, but routine gives forest of lines in no relation to what's written in routine, but i may be wrong... So basically I am looking for help for this particular versions with custom (_offset) sub...

Thanks for reading,
Maybe at the end someone will relight my candles of hope...
« Last Edit: October 06, 2023, 07:54:37 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube