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

0 Members and 1 Guest are viewing this topic.

BIGAL

  • Swamp Rat
  • Posts: 1429
  • 40 + years of using Autocad
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #255 on: December 30, 2023, 05:55:47 PM »
I downloaded the roof2d-new-new-solutions.lsp it has "(defun Vl-sort" twice I think second needs to be maybe Vl-sorti ?

Not sure what 1st Vl-sort is doing, I have a sort done by others that allows any number of sort elements used for sorting lists. Very fast.

I have no idea if (nth x lst) is faster than (cadr lst) etc but every millisecond adds up.
A man who never made a mistake never made anything

ribarm

  • Gator
  • Posts: 3300
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #256 on: December 31, 2023, 09:05:30 AM »
@BIGAL,

Please refer to this topic for (vl-sort) issue : https://www.theswamp.org/index.php?topic=58952.0
When coded for (vl-sort), vl-sort that is coded has higher priority than built-in (vl-sort)... I only left my version previously named (_vl-sort) in case that someone that is coding for vl-sort in Object Arx, or Dot Net can actually find it useful...

P.S. Since you downloaded only *-solutions.lsp, you firstly have to have single solution to make *-solutions.lsp avoid that case... It's not you have to download all, but roof2d-new-new-new.lsp should give you that single solution, or 2droof-final.lsp, or roof2d-new-new.lsp and from practical reasons I strongly suggest that you download complete package for HIPPED ROOFS at www.cadtutor.net download section : https://www.cadtutor.net/forum/files/file/36-hipped-roof-routines/
« Last Edit: December 31, 2023, 09:12:37 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3300
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #257 on: January 04, 2024, 01:40:40 PM »
Here is the version I recently started over again... It matches the speed I need, but unfortunately if throws giberish of lines and the way I coded it is supposed to do on non-ortho hipped roofs... The main problem lies from line 470 to the end... So if someone is willing to help he/she is welcomed...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:roof ( / *error* func wcs initvalueslst ucsf unit rlw unioncollinearplaneprints unique car-sort inside-p distp2t vl-sort numbpos ti s dm lw lwi pl pli tl utl lst ll lll x y ip ips ipss pos ang d1 d2 d t1 t2 tt k done flag f lil )
  2.  
  3.   (defun *error* ( m )
  4.     (foreach li (unique lil)
  5.       (if (and (car li) (cadr li) (not (equal (car li) (cadr li) 1e-6)))
  6.         (entmake (list (cons 0 "LINE") (cons 10 (car li)) (cons 11 (cadr li))))
  7.       )
  8.     )
  9.     (if (and lwi (not (vlax-erased-p lwi)))
  10.       (if (= (type lwi) (quote ename))
  11.         (entdel lwi)
  12.         (vla-delete lwi)
  13.       )
  14.     )
  15.     (if wcs
  16.       (if ucsf
  17.         (while
  18.           (not
  19.             (and
  20.               (equal (getvar (quote ucsxdir)) (car ucsf) 1e-6)
  21.               (equal (getvar (quote ucsydir)) (cadr ucsf) 1e-6)
  22.               (equal (trans (list 0.0 0.0 1.0) 1 0 t) (caddr ucsf) 1e-6)
  23.             )
  24.           )
  25.           (exe (list "_.UCS" "_P"))
  26.         )
  27.       )
  28.     )
  29.     (while (= 8 (logand 8 (getvar (quote undoctl))))
  30.       (if (not (exe (list "_.UNDO" "_E")))
  31.         (if doc
  32.           (vla-endundomark doc)
  33.         )
  34.       )
  35.     )
  36.     (if initvalueslst
  37.       (mapcar (function apply_cadr->car) initvalueslst)
  38.     )
  39.     (foreach fun (list (quote func) (quote vl-load) (quote exe) (quote cmdfun) (quote cmderr) (quote catch_cont) (quote apply_cadr->car) (quote ftoa))
  40.       (setq fun nil)
  41.     )
  42.     (if doc
  43.       (vla-regen doc acactiveviewport)
  44.     )
  45.     (if m
  46.       (prompt m)
  47.     )
  48.     (princ)
  49.   )
  50.  
  51.   (defun func ( wcs / sysvarpreset sysvarlst sysvarvals ) ;;; wcs (T/nil) ;;; cad, doc, alo, spc - global variables (Visual Lisp main VLA-OBJECT pointers) ;;; vl-load exe cmdfun cmderr catch_cont apply_cadr->car ftoa - library sub functions common for standard template initialization ;;;
  52.  
  53.     (defun vl-load nil
  54.       (or cad
  55.           (setq cad (vlax-get-acad-object))
  56.           (progn
  57.             (vl-load-com)
  58.             (setq cad (vlax-get-acad-object))
  59.           )
  60.         )
  61.       )
  62.       (or doc (setq doc (vla-get-activedocument cad)))
  63.       (or alo (setq alo (vla-get-activelayout doc)))
  64.       (or spc (setq spc (vla-get-block alo)))
  65.     )
  66.  
  67.     ;;; sometimes not needed to use/initialize AxiveX Visual Lisp extensions - (comment/uncomment) following line ;;;
  68.     (or (and cad doc alo spc) (vl-load))
  69.  
  70.     (defun exe ( tokenslist )
  71.       ( (lambda ( tokenslist / ctch )
  72.           (if (vl-catch-all-error-p (setq ctch (cmdfun tokenslist t)))
  73.             (progn
  74.               (cmderr tokenslist)
  75.               (catch_cont ctch)
  76.             )
  77.             (progn
  78.               (while (< 0 (getvar (quote cmdactive)))
  79.                 (vl-cmdf "")
  80.               )
  81.               t
  82.             )
  83.           )
  84.         )
  85.         tokenslist
  86.       )
  87.     )
  88.  
  89.     (defun cmdfun ( tokenslist flag / ctch ) ;;; tokenslist - command parameters list of strings ;;; flag - if "t" specified, upon successful execution returns t, otherwise if "nil" specified, return is always nil no matter what outcome of function execution is - it should be successful anyway if specified tokenslist was hardcoded correctly... ;;;
  90.       (if command-s
  91.         (if flag
  92.           (if (not (vl-catch-all-error-p (setq ctch (vl-catch-all-apply (function command-s) tokenslist))))
  93.             flag
  94.             ctch
  95.           )
  96.           (if (vl-catch-all-error-p (setq ctch (vl-catch-all-apply (function command-s) tokenslist)))
  97.             ctch
  98.           )
  99.         )
  100.         (if flag
  101.           (if (not (vl-catch-all-error-p (setq ctch (vl-catch-all-apply (function vl-cmdf) tokenslist))))
  102.             flag
  103.             ctch
  104.           )
  105.           (if (vl-catch-all-error-p (setq ctch (vl-catch-all-apply (function command) tokenslist)))
  106.             ctch
  107.           )
  108.         )
  109.       )
  110.     )
  111.  
  112.     (defun cmderr ( tokenslist ) ;;; tokenslist - list of tokens representing command syntax at which used (cmdfun) failed with successful execution ;;;
  113.       (prompt (strcat "\ncommand execution failure... error at used command tokenslist : " (vl-prin1-to-string tokenslist)))
  114.     )
  115.  
  116.     (defun catch_cont ( ctch / gr )
  117.       (prompt "\nleft mouse click to continue or enter to generate catch error - ESC to break...")
  118.       (while
  119.         (and
  120.           (vl-catch-all-error-p (or ctch (setq ctch (vl-catch-all-apply (function /) (list 1 0)))))
  121.           (setq gr (grread))
  122.           (/= (car gr) 3)
  123.           (not (equal gr (list 2 13)))
  124.         )
  125.       )
  126.       (if (vl-catch-all-error-p ctch)
  127.         ctch
  128.       )
  129.     )
  130.  
  131.     (defun apply_cadr->car ( sysvarvaluepair / ctch )
  132.       (setq ctch (vl-catch-all-apply (function setvar) sysvarvaluepair))
  133.       (if (vl-catch-all-error-p ctch)
  134.         (progn
  135.           (prompt (strcat "\ncatched error on setting system variable : " (vl-prin1-to-string (vl-symbol-name (car sysvarvaluepair))) " with value : " (vl-prin1-to-string (cadr sysvarvaluepair))))
  136.           (catch_cont ctch)
  137.         )
  138.       )
  139.     )
  140.  
  141.     (defun ftoa ( n / m a s b )
  142.       (if (numberp n)
  143.         (progn
  144.           (setq m (fix ((if (< n 0) - +) n 1e-8)))
  145.           (setq a (abs (- n m)))
  146.           (setq m (itoa m))
  147.           (setq s "")
  148.           (while (and (not (equal a 0.0 1e-6)) (setq b (fix (* a 10.0))))
  149.             (setq s (strcat s (itoa b)))
  150.             (setq a (- (* a 10.0) b))
  151.           )
  152.           (if (= (type n) (quote int))
  153.             m
  154.             (if (= s "")
  155.               m
  156.               (if (and (= m "0") (< n 0))
  157.                 (strcat "-" m "." s)
  158.                 (strcat m "." s)
  159.               )
  160.             )
  161.           )
  162.         )
  163.       )
  164.     )
  165.  
  166.     (setq sysvarpreset
  167.       (list
  168.         (list (quote cmdecho) 0)
  169.         (list (quote 3dosmode) 0)
  170.         (list (quote osmode) 0)
  171.         (list (quote unitmode) 0)
  172.         (list (quote cmddia) 0)
  173.         (list (quote ucsvp) 0)
  174.         (list (quote ucsortho) 0)
  175.         (list (quote projmode) 0)
  176.         (list (quote orbitautotarget) 0)
  177.         (list (quote insunits) 0)
  178.         (list (quote hpseparate) 0)
  179.         (list (quote hpgaptol) 0)
  180.         (list (quote halogap) 0)
  181.         (list (quote edgemode) 0)
  182.         (list (quote pickdrag) 0)
  183.         (list (quote qtextmode) 0)
  184.         (list (quote dragsnap) 0)
  185.         (list (quote angdir) 0)
  186.         (list (quote aunits) 0)
  187.         (list (quote limcheck) 0)
  188.         (list (quote gridmode) 0)
  189.         (list (quote nomutt) 0)
  190.         (list (quote apbox) 0)
  191.         (list (quote attdia) 0)
  192.         (list (quote blipmode) 0)
  193.         (list (quote copymode) 0)
  194.         (list (quote circlerad) 0.0)
  195.         (list (quote filletrad) 0.0)
  196.         (list (quote filedia) 1)
  197.         (list (quote autosnap) 1)
  198.         (list (quote objectisolationmode) 1)
  199.         (list (quote highlight) 1)
  200.         (list (quote lispinit) 1)
  201.         (list (quote layerpmode) 1)
  202.         (list (quote fillmode) 1)
  203.         (list (quote dragmodeinterrupt) 1)
  204.         (list (quote dispsilh) 1)
  205.         (list (quote fielddisplay) 1)
  206.         (list (quote deletetool) 1)
  207.         (list (quote delobj) 1)
  208.         (list (quote dblclkedit) 1)
  209.         (list (quote attreq) 1)
  210.         (list (quote explmode) 1)
  211.         (list (quote frameselection) 1)
  212.         (list (quote ltgapselection) 1)
  213.         (list (quote pickfirst) 1)
  214.         (list (quote plinegen) 1)
  215.         (list (quote plinetype) 1)
  216.         (list (quote peditaccept) 1)
  217.         (list (quote solidcheck) 1)
  218.         (list (quote visretain) 1)
  219.         (list (quote regenmode) 1)
  220.         (list (quote celtscale) 1.0)
  221.         (list (quote ltscale) 1.0)
  222.         (list (quote osnapcoord) 2)
  223.         (list (quote grips) 2)
  224.         (list (quote dragmode) 2)
  225.         (list (quote lunits) 2)
  226.         (list (quote pickstyle) 3)
  227.         (list (quote navvcubedisplay) 3)
  228.         (list (quote pickauto) 3)
  229.         (list (quote draworderctl) 3)
  230.         (list (quote expert) 5)
  231.         (list (quote auprec) 6)
  232.         (list (quote luprec) 6)
  233.         (list (quote pickbox) 6)
  234.         (list (quote aperture) 6)
  235.         (list (quote osoptions) 7)
  236.         (list (quote dimzin) 8)
  237.         (list (quote pdmode) 35)
  238.         (list (quote pdsize) -1.5)
  239.         (list (quote celweight) -1)
  240.         (list (quote cecolor) "BYLAYER")
  241.         (list (quote celtype) "ByLayer")
  242.         (list (quote clayer) "0")
  243.       )
  244.     )
  245.     (setq sysvarlst (mapcar (function car) sysvarpreset))
  246.     (setq sysvarvals (mapcar (function cadr) sysvarpreset))
  247.     (setq sysvarvals
  248.       (vl-remove nil
  249.         (mapcar
  250.           (function (lambda ( x )
  251.             (if (getvar x) (nth (vl-position x sysvarlst) sysvarvals))
  252.           ))
  253.           sysvarlst
  254.         )
  255.       )
  256.     )
  257.     (setq sysvarlst
  258.       (vl-remove-if-not
  259.         (function (lambda ( x )
  260.           (getvar x)
  261.         ))
  262.         sysvarlst
  263.       )
  264.     )
  265.     (setq initvalueslst
  266.       (apply (function mapcar)
  267.         (cons (function list)
  268.           (list
  269.             sysvarlst
  270.             (mapcar (function getvar) sysvarlst)
  271.           )
  272.         )
  273.       )
  274.     )
  275.       (cons (function setvar)
  276.         (list
  277.           sysvarlst
  278.           sysvarvals
  279.         )
  280.       )
  281.     )
  282.     (while (= 8 (logand 8 (getvar (quote undoctl))))
  283.       (if (not (exe (list "_.UNDO" "_E")))
  284.         (if doc
  285.           (vla-endundomark doc)
  286.         )
  287.       )
  288.     )
  289.     (if (not (exe (list "_.UNDO" "_M")))
  290.       (if doc
  291.         (vla-startundomark doc)
  292.       )
  293.     )
  294.     (if wcs
  295.       (if (= 0 (getvar (quote worlducs)))
  296.         (progn
  297.           (setq ucsf
  298.             (list
  299.               (getvar (quote ucsxdir))
  300.               (getvar (quote ucsydir))
  301.               (trans (list 0.0 0.0 1.0) 1 0 t)
  302.             )
  303.           )
  304.           (exe (list "_.UCS" "_W"))
  305.         )
  306.       )
  307.     )
  308.     wcs
  309.   )
  310.  
  311.   (defun unit ( v / d )
  312.     (if (not (equal (setq d (distance '(0.0 0.0 0.0) v)) 0.0 1e-6))
  313.       (mapcar '(lambda ( x ) (/ x d)) v)
  314.     )
  315.   )
  316.  
  317.   (defun rlw ( lw / e x1 x2 x3 x4 x5 x6 )
  318.     ;; by ElpanovEvgeniy
  319.     (if (= (cdr (assoc 0 (setq e (entget lw)))) "LWPOLYLINE")
  320.       (progn
  321.         (foreach a1 e
  322.           (cond
  323.             ( (= (car a1) 10) (setq x2 (cons a1 x2)) )
  324.             ( (= (car a1) 40) (setq x4 (cons (cons 41 (cdr a1)) x4)) )
  325.             ( (= (car a1) 41) (setq x3 (cons (cons 40 (cdr a1)) x3)) )
  326.             ( (= (car a1) 42) (setq x5 (cons (cons 42 (- (cdr a1))) x5)) )
  327.             ( (= (car a1) 210) (setq x6 (cons a1 x6)) )
  328.             ( t (setq x1 (cons a1 x1)) )
  329.           )
  330.         )
  331.         (entmod
  332.           (append (reverse x1)
  333.             (append
  334.               (apply 'append
  335.                 (apply 'mapcar
  336.                   (cons 'list
  337.                     (list x2
  338.                       (cdr (reverse (cons (car x3) (reverse x3))))
  339.                       (cdr (reverse (cons (car x4) (reverse x4))))
  340.                       (cdr (reverse (cons (car x5) (reverse x5))))
  341.                     )
  342.                   )
  343.                 )
  344.               )
  345.               x6
  346.             )
  347.           )
  348.         )
  349.         (entupd lw)
  350.       )
  351.     )
  352.   )
  353.  
  354.   (defun unioncollinearplaneprints ( tl / a b tll )
  355.     (while (setq a (car tl))
  356.       (setq b (vl-remove-if-not (function (lambda ( x ) (and (collinear-pp (car a) (cadr a) (car x)) (collinear-pp (car a) (cadr a) (cadr x))))) tl))
  357.       (setq tll (cons a tll))
  358.       (if b
  359.         (setq tl (vl-remove-if (function (lambda ( x ) (vl-some (function (lambda ( y ) (equal x y 1e-6))) b))) tl))
  360.         (setq tl (cdr tl))
  361.       )
  362.     )
  363.     tll
  364.   )
  365.  
  366.   (defun unique ( lst / a ll )
  367.     (while (setq a (car lst))
  368.       (if (vl-some (function (lambda ( x ) (equal x a 1e-6))) (cdr lst))
  369.         (setq ll (cons a ll) lst (vl-remove-if (function (lambda ( x ) (equal x a 1e-6))) (cdr lst)))
  370.         (setq ll (cons a ll) lst (cdr lst))
  371.       )
  372.     )
  373.     (reverse ll)
  374.   )
  375.  
  376.   (defun car-sort ( lst cmp / rtn )
  377.     (setq rtn (car lst))
  378.     (foreach itm (cdr lst)
  379.       (if (apply cmp (list itm rtn))
  380.         (setq rtn itm)
  381.       )
  382.     )
  383.     rtn
  384.   )
  385.  
  386.   (defun inside-p ( p lw lwi )
  387.   )
  388.  
  389.   (defun distp2t ( p gg / i d )
  390.     (if (setq i (inters p (polar p (+ (angle (car gg) (cadr gg)) (* 0.5 pi)) 1.0) (car gg) (cadr gg) nil))
  391.       (setq d (distance p i))
  392.     )
  393.   )
  394.  
  395.   (defun vl-sort ( lst func )
  396.     (mapcar
  397.       (function (lambda ( x ) (nth x lst)))
  398.       (vl-sort-i lst func)
  399.     )
  400.   )
  401.  
  402.   (defun numbpos ( n len )
  403.     (cond
  404.       ( (< n len)
  405.         n
  406.       )
  407.       ( (> n len)
  408.         (- n len)
  409.       )
  410.       ( t 0 )
  411.     )
  412.   )
  413.  
  414.   (setq wcs (func t)) ;;; starting "library" template sub function - initialization ;;;
  415.   (prompt "\nPick closed polygonal LWPOLYLINE on unlocked layer...")
  416.   (if (setq s (ssget "_+.:E:S:L" (list (cons 0 "LWPOLYLINE") (cons -4 "&=") (cons 70 1) (cons -4 "<not") (cons -4 "<>") (cons 42 0.0) (cons -4 "not>"))))
  417.     (progn
  418.       (setq ti (car (_vl-times)))
  419.       (setq dm 1e+308)
  420.       (setq lw (ssname s 0))
  421.       (vlax-invoke (vlax-ename->vla-object lw) (quote offset) -1e-3)
  422.       (setq lwi (entlast))
  423.       (if (> (vlax-curve-getarea lwi) (vlax-curve-getarea lw))
  424.         (progn
  425.           (rlw lw)
  426.           (entdel lwi)
  427.           (vlax-invoke (vlax-ename->vla-object lw) (quote offset) -1e-3)
  428.           (setq lwi (entlast))
  429.         )
  430.       )
  431.       (setq pl (mapcar (function cdr) (vl-remove-if (function (lambda ( x ) (/= (car x) 10))) (entget lw))))
  432.       (setq pli (mapcar (function cdr) (vl-remove-if (function (lambda ( x ) (/= (car x) 10))) (entget lwi))))
  433.       (while (not (equal (car pl) (car pli) 0.1))
  434.         (setq pli (append (cdr pli) (list (car pli))))
  435.       )
  436.       (setq tl (mapcar (function (lambda ( a b ) (list a b))) pl (append (cdr pl) (list (car pl)))))
  437.       ;(setq utl (unioncollinearplaneprints tl))
  438.       (setq lst (mapcar (function (lambda ( a b c d ) (list a (angle a b) c d))) pl pli (cons (last tl) (reverse (cdr (reverse tl)))) tl))
  439.       (while (not done)
  440.         (if (not flag)
  441.           (progn
  442.             (setq ll lst ips nil dm 1e+308)
  443.             (while (setq x (car ll))
  444.               (setq ll (cdr ll))
  445.               (setq y (car ll))
  446.               (if (and x y (setq ip (inters (car x) (polar (car x) (cadr x) 1.0) (car y) (polar (car y) (cadr y) 1.0) nil)) (inside-p ip lw lwi))
  447.                 (if (< (setq d (min (distp2t ip (caddr x)) (distp2t ip (last y)))) dm)
  448.                   (setq ips (list ip x y) dm d)
  449.                 )
  450.               )
  451.             )
  452.             (setq pos (vl-position (cadr ips) lst))
  453.             (if pos
  454.               (repeat (numbpos pos (length pl))
  455.                 (setq lst (append (cdr lst) (list (car lst))))
  456.               )
  457.             )
  458.             (setq tt (vl-remove-if (function (lambda ( x ) (= (length (vl-remove-if (function (lambda ( y ) (equal x y 1e-6))) (list (caddr (cadr ips)) (cadddr (cadr ips)) (caddr (caddr ips)) (cadddr (caddr ips))))) 2))) (list (caddr (cadr ips)) (cadddr (cadr ips)) (caddr (caddr ips)) (cadddr (caddr ips)))))
  459.             ;(setq tl (vl-remove (car (vl-remove-if (function (lambda ( x ) (vl-some (function (lambda ( y ) (equal x y 1e-6))) tt))) (list (caddr (cadr ips)) (cadddr (cadr ips)) (caddr (caddr ips)) (cadddr (caddr ips))))) tl))
  460.             (if (and (car ips) (car (cadr ips)) (car (caddr ips)))
  461.               (setq lil (cons (list (car ips) (car (cadr ips))) lil) lil (cons (list (car ips) (car (caddr ips))) lil))
  462.             )
  463.             (setq ang (angle (car ips) (inters (caar tt) (cadar tt) (caadr tt) (cadadr tt) nil)))
  464.             (setq lst (cons (setq ips (list (car ips) ang (car tt) (cadr tt))) lst))
  465.           )
  466.         )
  467.         (setq flag t)
  468.         (setq ll lst dm 1e+308)
  469.         (setq x (assoc (caar lil) ll))
  470.         (setq ll (vl-remove x ll))
  471.         (while (setq y (car ll))
  472.           (setq ll (cdr ll))
  473.           (if (and x y (setq ip (inters (car x) (polar (car x) (cadr x) 1.0) (car y) (polar (car y) (cadr y) 1.0) nil)))
  474.             (if (and (not (equal (setq d (distance ip (caar lil))) 0.0 1e-6)) (< d dm) (inside-p ip lw lwi))
  475.               (setq ips (list ip x y) dm d)
  476.             )
  477.           )
  478.         )
  479.         (setq pos (vl-position (list (cadadr lil) (cadar lil)) tl))
  480.         (setq tl (vl-remove (list (cadadr lil) (cadar lil)) tl))
  481.         (if (and pos (not f))
  482.           (repeat (numbpos pos (length pl))
  483.             (setq lst (append (cdr lst) (list (car lst))))
  484.             (setq tl (append (cdr tl) (list (car tl))))
  485.           )
  486.         )
  487.         (setq f t)
  488.         (setq tt (vl-some (function (lambda ( x ) (if (member x (last tl)) (last tl)))) (mapcar (function cadr) lil)))
  489.         (setq tl (vl-remove tt tl))
  490.         (setq t1 (car tl))
  491.         (setq t2 (last tl))
  492.         (if tl
  493.           (progn
  494.             (setq ang (angle (car ips) (inters (car t1) (cadr t1) (car t2) (cadr t2) nil)))
  495.             (setq ips (list (car ips) ang t1 t2))
  496.             (setq lst (cons ips lst))
  497.             (setq lil (cons (list (car ips) (caar lil)) lil))
  498.             (foreach l lst
  499.               (if (equal (angle (car l) (car ips)) (cadr l) 1e-6)
  500.                 (setq lil (cons (list (car ips) (car l)) lil))
  501.               )
  502.             )
  503.           )
  504.         )
  505.         (if (not k)
  506.           (setq k 1)
  507.           (setq k (1+ k))
  508.         )
  509.         (if (equal k (length pl))
  510.           (setq done t)
  511.         )
  512.       )
  513.       (prompt "\nElapsed time : ") (prompt (ftoa (- (car (_vl-times)) ti))) (prompt " milliseconds...")
  514.       (prompt "\nFor UNDO - type \"UNDO\" - \"Back\" option...")
  515.     )
  516.   )
  517.   (*error* nil)
  518. )
  519.  

Regards, M.R.
« Last Edit: January 04, 2024, 06:17:05 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3300
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #258 on: January 06, 2024, 01:43:17 PM »
So, here in attachment is revised version of code I published... But it doesn't finish or just start to some point... Speed is satisfactory, but I would like to see some *.arx, *.brx, *.dll on the same theme...

Regards and stay well in New 2024 Year...
« Last Edit: January 13, 2024, 01:18:37 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2149
  • class keyThumper<T>:ILazy<T>
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #259 on: January 06, 2024, 03:55:40 PM »
@ribarm,

What is your definition of
Quote
non-ortho hipped roofs...

Best new year wishes.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

ribarm

  • Gator
  • Posts: 3300
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #260 on: January 06, 2024, 07:09:56 PM »
@ribarm,

What is your definition of
Quote
non-ortho hipped roofs...

Best new year wishes.

The random acute or obtuse angles - without 90 degrees between 2 segments of polygonal closed LWPOLYLINE...
« Last Edit: January 06, 2024, 07:34:04 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2149
  • class keyThumper<T>:ILazy<T>
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #261 on: January 06, 2024, 10:04:18 PM »
If I recall correctly from my bin and chute (plate steelwork ) days, for equal angle faces the hip/valley line will always bisect the corner angle,
and logic says that a ridge line will always be central between parallel walls , so I can't imagine a roof will be any different [ except turned upside down ]

But programming for my work discipline is different to yours.

Your definition is as I imagined, but I thought I'd just check terminology :)
« Last Edit: January 06, 2024, 10:29:11 PM by kdub_nz »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

ribarm

  • Gator
  • Posts: 3300
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #262 on: January 09, 2024, 04:24:23 AM »
Well, no one want to participate... Then how do you expect that need for improvement will happen...
I posted 3 files here : https://www.theswamp.org/index.php?topic=41837.msg618211#msg618211
And no one didn't even download not to mention looked it...
I explained to some point where I need help... It is not that I don't want to write it to the finish... The problem is that variable that holds planes points are removed sooner than should and removal of planes from planes list is the way it should function...
Someone with great expirience should really take look at those 3 attempts (lisps)...
« Last Edit: January 09, 2024, 07:36:23 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2149
  • class keyThumper<T>:ILazy<T>
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #263 on: January 09, 2024, 02:23:11 PM »
Marco,
I didn't know you required assistance, I thought your posts were progress reports (ignoring the 'Challenge' in the title :) ).

Could you re-post one file that works best and the one that you are having issues with ( and describe the issues. )

. . . at least pointing people in the right direction may encourage assistance.

I assume we can select any outline amongst the several posted.

Because I haven't read through the thread;
Does the outline represent the eaves line ?
Where is the roof pitch being set ? (if at all . . I noticed a mention of a plane, so ? )
Do you have any procedural requirements ?

Regards,
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

ribarm

  • Gator
  • Posts: 3300
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #264 on: January 09, 2024, 03:15:08 PM »
The last one I coded is "roof-2chk-n.lsp"... But it has lacks that I can't figure why exist... It doesn't complete the job... My thougts were pointed in direction of writing faster version then currently the one that finishes job in slow time period... It is called "roof2d-new-new-new.lsp", but I realized that all we, I needed was faster LISP processing which is acomplished with Bricsys BricsCAD... Anyway there is realy fast one, but it fails in search for finding right combination of variables when starting search... It is called "2droof-final.lsp" and it also completes the job correctly, even better than "roof2d-new-new-new.lsp"... All this you can find in *.ZIP I posted at www.cadtutor.net - download section... So, if someone has spare time, I'd suggest trying to fix "roof-2chk-n.lsp"... There could be perhaps progress in gaining better time execution...

Thanks for interes and Happy Holidays...
M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3300
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #265 on: January 12, 2024, 01:37:59 PM »
I am realy stacked here with "roof-2chk-n.lsp"... Can someone check it from line 653 - roof-chk-n.lsp / 642 - roof-chk-nn.lsp to the end of file... In my opinion it should work, but it isn't - it just starts and then stops after 6 lines drawn... If someone has spare time, please download it from this post : https://www.theswamp.org/index.php?topic=41837.msg618211#msg618211

Your help is always welcomed...
M.R.
« Last Edit: January 13, 2024, 12:25:39 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3300
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #266 on: January 13, 2024, 01:35:10 PM »
As you can see, I've added my latest "roof-2chk-nn.lsp"... So, expecting any feedback... Still it's buggy and sometimes though it starts correctly, may make unexpected mistake(s) - so I've added OVERKILL, just for overlaps, though it may create line(s) that are without any relation to roof solution...

Latest version attached to this post...
 :-( :mrgreen:
« Last Edit: January 14, 2024, 01:30:38 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

pkohut

  • Bull Frog
  • Posts: 483
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #267 on: January 14, 2024, 04:55:10 AM »
I am realy stacked here with "roof-2chk-n.lsp"... Can someone check it from line 653 - roof-chk-n.lsp / 642 - roof-chk-nn.lsp to the end of file... In my opinion it should work, but it isn't - it just starts and then stops after 6 lines drawn... If someone has spare time, please download it from this post : https://www.theswamp.org/index.php?topic=41837.msg618211#msg618211

Your help is always welcomed...
M.R.

Hey Marco,

I added some logging to the code base and collected output, both are in the attached zip file.   This should help.


Code: [Select]
;;; printf debugging added by Paul Kohut, 1/14/2024
;;; Purpose: track down why code is not outputting the correct
;;; roof ridge lines. The debug output sent to the acad console,
;;; tags will help tie to the source code/variables/entities.
;;;
;;; The cpatured data was weakly tested against some key subrointes,
;;; all of them preformed as expected.
;;; Original code provided by Marko Ribar in HIPPED ROOF ROUTINES.ZIP

I think this is the problem spot.
Code: [Select]
(setq lst (mapcar (function (lambda ( a b c d ) (list a (angle a b) c d))) pl pli (cons (last tl) (reverse (cdr (reverse tl)))) tl))
        (princ (strcat "\natt=" (itoa att) "  lst length=" (itoa (length lst))))
        (print lst)
;;; pk - I think at this point the first 7 entity are rerun a
;;; few times creating duplicate ridge geometry in lst.
;;; These long complex lines should get reformed so debugging
;;; in VLISP or VS Code is easier.

New tread (not retired) - public repo at https://github.com/pkohut

ribarm

  • Gator
  • Posts: 3300
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #268 on: January 14, 2024, 11:59:24 AM »
@pkohut

I saw attachment, but reposting the same file I attach doesn't solve things... I posted files in hope that they could be used purpously in task for completion of whole ridge solution on any non-ortho closed polygonal LWPOLYLINE... Nevertheless I attached few more at *.ZIP at cadtutor... So now I wait cos' I don't know why it stops after drawing 6 lines... At the end I'll give up with those roof-*.lsp... So still I am hoping that "roof2d-new-new-new.lsp" could be converted to *.arx, *.brx, or *.dll...

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

:)

M.R. on Youtube

pkohut

  • Bull Frog
  • Posts: 483
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #269 on: January 14, 2024, 02:52:13 PM »
@pkohut

I saw attachment, but reposting the same file I attach doesn't solve things... I posted files in hope that they could be used purpously in task for completion of whole ridge solution on any non-ortho closed polygonal LWPOLYLINE... Nevertheless I attached few more at *.ZIP at cadtutor... So now I wait cos' I don't know why it stops after drawing 6 lines... At the end I'll give up with those roof-*.lsp... So still I am hoping that "roof2d-new-new-new.lsp" could be converted to *.arx, *.brx, or *.dll...

Have a nice day...
M.R.

So, I spent about 10 hours looking at the code trying to see how it works.  Additions were made, to your file, to facilitate collecting data for analysis.  That "changed" lisp file is included in my zip attachment. This is just one of the steps I might go through when looking at an unknown problem space.   So, the lisp file I attached is not the same as your original.

Given the additional data points, my intent was to look at why the lst variable is not populated properly.  Either I'll get lucky figuring it out on my own or maybe someone will chime in with support.  Once the program is creating the correct results I can move on to optimizations.

Speaking of optimizations, one of my collected data points was for the entmakex of circle and entdel of said circle, which is called about 750 times. Calling entmake(x) is not very fast and one of the vl- create routines would be much faster.  Since the circles are just used for their built in geometry routines, only 2 circles are needed.  Create them early, then modify their radius and center points  everywhere entmakex is called.

Converting "roof2d-new-new-new.lsp" to ARX can be done by someone familiar with ARX. Someone would have to go routine by routine and do mental gymnastics from Autolisp to ARX.  I am not aware of any automated task to do such a conversion.  The benefit of such a conversion, faster speed, will be lost because the nested loops run deep recalculating same values over and over.   I was going to spend a few cycles doing the conversion to ARX for a straight on head to head comparison.  After that I was going to investigate different collection algorithms for huge speed improvements.

I don't think I have anything else useful to contribute.

Later.
That's all I got to say
New tread (not retired) - public repo at https://github.com/pkohut