Author Topic: (Challenge) 3D Plines  (Read 4302 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(Challenge) 3D Plines
« on: June 20, 2008, 09:22:35 AM »
Return the extreme Z values (highest/lowest) of a given 3D polyline.
TheSwamp.org  (serving the CAD community since 2003)

fixo

  • Guest
Re: (Challenge) 3D Plines
« Reply #1 on: June 20, 2008, 09:57:44 AM »
Here is my 2c

Code: [Select]
(defun getexremelev  (3dpoly /)
  (vl-load-com)
  (setq coors (vlax-get 3dpoly 'Coordinates))
  (while coors
    (setq tmp (list (car coors) (cadr coors) (caddr coors)))
    (setq pt_list (cons tmp pt_list))
    (setq coors (cdddr coors)))
  (setq zs (list (apply 'min (mapcar 'caddr pt_list))
(apply 'max (mapcar 'caddr pt_list))
)
)
  zs
  )

(defun C:test  ()
  (if
    (setq ss (ssget "+.:S:E" (list (cons 0 "POLYLINE"))))
     (progn
       (setq obj (vlax-ename->vla-object (ssname ss 0)))
       (setq els (getexremelev obj))
       (alert (strcat "Min value: "
      (vl-princ-to-string (car els))
      "\n"
      "Max value: "
      (vl-princ-to-string (cadr els))))
       )
     )
  )

~'J'~

Didge

  • Bull Frog
  • Posts: 211
Re: (Challenge) 3D Plines
« Reply #2 on: June 20, 2008, 10:01:42 AM »
Here's another approach.

Code: [Select]
(defun c:MIN-MAX-Z (/ enm elst vlst)
  (if (and (setq enm (car (entsel "\nSelect 3D Polyline > "))) (eq (cdr (assoc 0 (setq elst (entget enm)))) "POLYLINE"))
    (progn
      (while (= (cdr (assoc 0 (setq elst (entget (setq enm (entnext enm))))  )) "VERTEX")
(setq vlst (append vlst (list (cdr (assoc 10 elst)))))
      )
      (alert (strcat "Highest Z value: " (rtos (apply 'max (mapcar 'caddr vlst))) "\n\n"
     "Lowest Z value: " (rtos (apply 'min (mapcar 'caddr vlst)))))
    )
    (prompt "\nSelected object is not a 3D Polyline")
  )
  (princ)
)
« Last Edit: June 20, 2008, 10:09:14 AM by Didge »
Think Slow......

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8805
  • AKA Daniel
Re: (Challenge) 3D Plines
« Reply #3 on: June 20, 2008, 10:41:04 AM »
mine  :lol:

Code: [Select]

(DEFUN C:DOIT (/ CNT L OBJ)
  (VL-LOAD-COM)
  (SETQ ENT (CAR (ENTSEL)))
 
  (IF ENT
    (PROGN
   
      (SETQ OBJ (VLAX-ENAME->VLA-OBJECT ENT))
     
      (IF (EQ (VLAX-GET OBJ 'OBJECTNAME) "AcDb3dPolyline")
        (PROGN
       
          (SETQ CNT (/ (LENGTH (VLAX-GET OBJ 'COORDINATES)) 3)
                L   '()
          )
         
          (WHILE (< 0 CNT)
            (SETQ CNT (1- CNT)
                  L   (CONS (CADDR (VLAX-SAFEARRAY->LIST
                                     (VLAX-VARIANT-VALUE
                                       (VLAX-GET-PROPERTY OBJ 'COORDINATE CNT)))) L))
          )
         
          (SETQ L (VL-SORT L '<)
                L (LIST (CAR L) (NTH (1- (LENGTH L)) L))
          )
         
          (PRINC
            (STRCAT "Low: " (RTOS (CAR L)) " High: " (RTOS (CADR L)))
          )
         
        )
      )
    )
  )
  (PRINC)
)


edit oops
« Last Edit: June 20, 2008, 10:52:06 AM by Daniel »

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: (Challenge) 3D Plines
« Reply #4 on: June 20, 2008, 02:56:58 PM »
Code: [Select]
(vl-load-com)
(defun test (EntName / LL UR)
  (vla-GetBoundingBox
    (vlax-ename->vla-object EntName)
    'LL
    'UR
  )
  (vl-sort (list (last (vlax-safearray->list LL))
(last (vlax-safearray->list UR))
   )
   '<
  )
)
;;;(test (car (entsel)))
wil return a list (minz maxz)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: (Challenge) 3D Plines
« Reply #5 on: June 20, 2008, 03:08:23 PM »
Code: [Select]
(vl-load-com)
(defun test (EntName / LL UR)
  (vla-GetBoundingBox
    (vlax-ename->vla-object EntName)
    'LL
    'UR
  )
  (vl-sort (list (last (vlax-safearray->list LL))
(last (vlax-safearray->list UR))
   )
   '<
  )
)
;;;(test (car (entsel)))
wil return a list (minz maxz)

Interesting code
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) 3D Plines
« Reply #6 on: June 21, 2008, 06:28:21 AM »
All hello! :)
I offer other variant.
Unlike others.

Code: [Select]
(defun test (e)
 ;; min-max-Z-point
 (list (vlax-curve-getclosestpointto e '(0. 0. -1e+99))
       (vlax-curve-getclosestpointto e '(0. 0. 1e+99))
 ) ;_  list
) ;_  defun
;;(test(car(entsel)))
(defun test1 (e)
 ;; min-max-box-point
 (list (list (car (vlax-curve-getclosestpointto e '(-1e+99 0. 0.)))
             (cadr (vlax-curve-getclosestpointto e '(0. -1e+99 0.)))
             (caddr (vlax-curve-getclosestpointto e '(0. 0. -1e+99)))
       ) ;_  list
       (list (car (vlax-curve-getclosestpointto e '(1e+99 0. 0.)))
             (cadr (vlax-curve-getclosestpointto e '(0. 1e+99 0.)))
             (caddr (vlax-curve-getclosestpointto e '(0. 0. 1e+99)))
       ) ;_  list
 ) ;_  list
) ;_  defun
;;(test1(car(entsel)))
« Last Edit: June 21, 2008, 07:03:49 AM by ElpanovEvgeniy »

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: (Challenge) 3D Plines
« Reply #7 on: June 21, 2008, 07:25:55 AM »
it's kinda tricky, Evgeniy :)
but try (test) on the following 3dpoly
(command "._3dpoly" '(-50 -50 10) '(-50 50 0) '(50 50 -10) '(50 -50 0) "_c")

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) 3D Plines
« Reply #8 on: June 21, 2008, 07:41:31 AM »
it's kinda tricky, Evgeniy :)
but try (test) on the following 3dpoly
(command "._3dpoly" '(-50 -50 10) '(-50 50 0) '(50 50 -10) '(50 -50 0) "_c")

fix...

Code: [Select]
(defun test (e)
 ;; min-max-Z-point
 (list (vlax-curve-getclosestpointto e '(0. 0. -1e+16))
       (vlax-curve-getclosestpointto e '(0. 0. 1e+16))
 ) ;_  list
) ;_  defun
;;(test(car(entsel)))
(defun test1 (e)
 ;; min-max-box-point
 (list (list (car (vlax-curve-getclosestpointto e '(-1e+16 0. 0.)))
             (cadr (vlax-curve-getclosestpointto e '(0. -1e+16 0.)))
             (caddr (vlax-curve-getclosestpointto e '(0. 0. -1e+16)))
       ) ;_  list
       (list (car (vlax-curve-getclosestpointto e '(1e+16 0.)))
             (cadr (vlax-curve-getclosestpointto e '(0. 1e+16)))
             (caddr (vlax-curve-getclosestpointto e '(0. 0. 1e+16)))
       ) ;_  list
 ) ;_  list
) ;_  defun
;;(test1(car(entsel)))

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: (Challenge) 3D Plines
« Reply #9 on: June 21, 2008, 07:52:27 AM »
congratulations Evgeniy, it looks like i've found a bug in vlax-curve-getclosestpointto function :)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) 3D Plines
« Reply #10 on: June 21, 2008, 07:57:38 AM »
congratulations Evgeniy, it looks like i've found a bug in vlax-curve-getclosestpointto function :)

It is my error!
There was no accuracy...
Code: [Select]
(equal 1e+99 (+ 1e+99 10))returne T..

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: (Challenge) 3D Plines
« Reply #11 on: June 21, 2008, 08:05:52 AM »
as a matter of fact your function (test) shouldn't work in most cases, but because of some 'undocumented features' in vlax-curve-getclosestpointto it returns the desired z's...

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) 3D Plines
« Reply #12 on: June 21, 2008, 08:09:26 AM »
-e+99 = a minus infinity for autocad

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: (Challenge) 3D Plines
« Reply #13 on: June 21, 2008, 11:00:02 AM »
Some very interesting solutions!

I like fixo's but would modify it to this:
Code: [Select]
(defun getexremelev (3dpoly / coors zList)
  (vl-load-com)
  (setq coors (vlax-get 3dpoly 'Coordinates))
  (while coors
    (setq zList (cons (caddr coors) zList))
    (setq coors (cdddr coors))
  )
  (list (apply 'min zList) (apply 'max zList))
)

Code: [Select]
(defun C:test (/ ss obj els)
  (if
    (setq ss (ssget "+.:S:E" (list (cons 0 "POLYLINE"))))
     (progn
       (setq obj (vlax-ename->vla-object (ssname ss 0)))
       (setq els (getexremelev obj))
       (alert (strcat "Min value: " (vl-princ-to-string (car els))
                      "\nMax value: " (vl-princ-to-string (cadr els))
              )
       )
     )
  )
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.