Author Topic: Filter to sum objects  (Read 286 times)

0 Members and 1 Guest are viewing this topic.

Romero

  • Mosquito
  • Posts: 18
Filter to sum objects
« on: August 10, 2019, 04:10:46 PM »
Hello everyone in this great forum.

Again here canning and I need your help.

I have this Lisp that gets the sum of the selected elements on the screen (line, Pline, Arc, Circle, Ellipse, 3dpoly)


Code - Auto/Visual Lisp: [Select]
  1. [code](defun c:SUMALL   (/ fList firSet entSet filOut entList totLen)
  2.  
  3.  
  4.   (setq fList  '((-4 . "<OR")
  5.                  (0 . "*LINE")
  6.                  (0 . "CIRCLE")
  7.                  (0 . "ARC")
  8.                  (0 . "ELLIPSE")
  9.                  (-4 . "OR>")
  10.                  (-4 . "<NOT")
  11.                  (0 . "MLINE")
  12.                  (-4 . "NOT>")
  13.                 )
  14.         filOut 0
  15.   )                                     ; end setq
  16.   (if
  17.     (not
  18.       (and
  19.         (setq firSet (ssget "_I")
  20.               entSet (ssget "_I" fList)
  21.         )                               ; end setq
  22.       )                                 ; end and
  23.     )                                   ; end not
  24.      (progn
  25.        (princ
  26.          "\n<<< Select entities to calculate total length >>> "
  27.        )
  28.        (setq entSet (ssget fList))
  29.      )                                  ; end progn
  30.      (setq filOut (- (sslength firSet) (sslength entset)))
  31.   )                                     ; end if
  32.   (if entSet
  33.     (progn
  34.       (setq entList (mapcar 'vlax-ename->vla-object
  35.                             (vl-remove-if
  36.                               'listp
  37.                               (mapcar 'cadr (ssnamex entSet))
  38.                             )
  39.                     )
  40.             totLen  (apply '+
  41.                            (mapcar '(lambda (x)
  42.                                       (vlax-curve-getDistAtParam
  43.                                         x
  44.                                         (vlax-curve-getEndParam x)
  45.                                       )
  46.                                     )
  47.                                    entList
  48.                            )
  49.                     )
  50.       )                                 ; end setq
  51.       (if (/= 0 filOut)
  52.         (princ (strcat "\n<!> "
  53.                        (itoa filout)
  54.                        " were filtered out (unsupported type)! <!>"
  55.                )
  56.         )
  57.       )                                 ; end if
  58.       (princ (strcat "\n<<< Total entities: "
  59.                      (itoa (length entList))
  60.                      ", Total length: "
  61.                      (rtos totLen)
  62.                      " >>> "
  63.              )
  64.       )
  65.     )                                   ; end progn
  66.     (princ "\n<!> Nothing selected! <!>")
  67.   )                                     ; end if
  68.   (princ)
  69. )                                       ; end of c:SUMALL
  70.  
[/code]

What I would like to do is to be able to filter to obtain the desired sums only from the following objects:
- Lines
- Polylines
- Arcs
- Splines
- All




and create a repeat cycle to continue designating objects according to the selected option

I tried a cond but I don't know how to filter the selection list for my requirements.

Code - Auto/Visual Lisp: [Select]
  1. (initget "Lines Plines aRrcs Splines")
  2. (setq Opsum (getkword
  3.               "\nGet the sum of: [Lines/Plines/aRcs/Splines] <All=>: "
  4.             )
  5. )
  6.  
  7.  
  8. (cond ((= Opsum "Lines") (SUML))    ;;How do I filter only Lines?
  9.       ((= Opsum "Plines") (SUMPL))     ;;How do I filter only Plines?
  10.       ((= Opsum "aRcs") (SUMAR))      ;;How do I filter only Arcs?
  11.       ((= Opsum "Splines") (SUMSP))   ;;How do I filter only Spines?
  12. )
  13.  

Any help will be welcome. Thank you

ronjonp

  • Needs a day job
  • Posts: 6995
Re: Filter to sum objects
« Reply #1 on: August 12, 2019, 10:16:43 AM »
Try something like this:
Code - Auto/Visual Lisp: [Select]
  1. (initget "Lines Plines aRrcs Splines All")
  2. (setq opsum (getkword "\nGet the sum of: [Lines/Plines/aRcs/Splines/All] <All>: "))
  3. (cond ((= opsum "Lines") "LINE")
  4.       ;;How do I filter only Lines?
  5.       ((= opsum "Plines") "LWPOLYLINE")
  6.       ;;How do I filter only Plines?
  7.       ((= opsum "aRcs") "ARC")
  8.       ;;How do I filter only Arcs?
  9.       ((= opsum "Splines") "SPLINE")
  10.       ;;How do I filter only Spines?
  11.       ((= opsum "All") "ARC,LINE,LWPOLYLINE,SPLINE")
  12. )
  13. (setq flist  (list (cons 0 opsum))
  14.       filout 0
  15. )

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

Romero

  • Mosquito
  • Posts: 18
Re: Filter to sum objects
« Reply #2 on: August 13, 2019, 12:20:05 PM »
Try something like this:
Code - Auto/Visual Lisp: [Select]
  1. (initget "Lines Plines aRrcs Splines All")
  2. (setq opsum (getkword "\nGet the sum of: [Lines/Plines/aRcs/Splines/All] <All>: "))
  3. (cond ((= opsum "Lines") "LINE")
  4.       ;;How do I filter only Lines?
  5.       ((= opsum "Plines") "LWPOLYLINE")
  6.       ;;How do I filter only Plines?
  7.       ((= opsum "aRcs") "ARC")
  8.       ;;How do I filter only Arcs?
  9.       ((= opsum "Splines") "SPLINE")
  10.       ;;How do I filter only Spines?
  11.       ((= opsum "All") "ARC,LINE,LWPOLYLINE,SPLINE")
  12. )
  13. (setq flist  (list (cons 0 opsum))
  14.       filout 0
  15. )


Hi Ron. Thank you for your response, I'm trying as you suggest, however, I'm still having problems. Do I have to delete the original list? Or just replace it?

Try something like this, but without success. I appreciate the good intention in helping the truth is that I am starting.


Code - Auto/Visual Lisp: [Select]
  1. (setq fList  '((-4 . "<OR")
  2.                (0 . "LINE")
  3.                (0 . "LWPLINE")
  4.                (0 . "ARC")
  5.                (0 . "SPLINE")
  6.                (-4 . "OR>")
  7.               )
  8.       filOut 0
  9. )

ronjonp

  • Needs a day job
  • Posts: 6995
Re: Filter to sum objects
« Reply #3 on: August 13, 2019, 12:33:12 PM »
Try something like this (untested)
Code - Auto/Visual Lisp: [Select]
  1. (defun c:sumall (/ entset firset opsum totlen x)
  2.   (initget "Lines Plines aRrcs Splines All")
  3.   (setq opsum (cond ((getkword "\nGet the sum of: [Lines/Plines/aRcs/Splines/All] <All>: "))
  4.                     ("All")
  5.               )
  6.   )
  7.   (setq opsum (cond ((= opsum "Lines") "LINE")
  8.                     ;;How do I filter only Lines?
  9.                     ((= opsum "Plines") "LWPOLYLINE")
  10.                     ;;How do I filter only Plines?
  11.                     ((= opsum "aRcs") "ARC")
  12.                     ;;How do I filter only Arcs?
  13.                     ((= opsum "Splines") "SPLINE")
  14.                     ;;How do I filter only Spines?
  15.                     ((= opsum "All") "ARC,LINE,LWPOLYLINE,SPLINE")
  16.               )
  17.   )
  18.   (if (setq entset (ssget (list (cons 0 opsum))))
  19.     (if (setq totlen
  20.                (apply '+
  21.                       (mapcar '(lambda (x) (vlax-curve-getdistatparam x (vlax-curve-getendparam x)))
  22.                               (vl-remove-if 'listp (mapcar 'cadr (ssnamex entset)))
  23.                       )
  24.                )
  25.         )
  26.       (princ (strcat "\n<<< Total entities: "
  27.                      (itoa (sslength entset))
  28.                      ", Total length: "
  29.                      (rtos totlen)
  30.                      " >>> "
  31.              )
  32.       )
  33.     )
  34.     (princ "\n<!> Nothing selected! <!>")
  35.   )
  36.   (princ)
  37. )
« Last Edit: August 13, 2019, 02:08:13 PM by ronjonp »

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

Romero

  • Mosquito
  • Posts: 18
Re: Filter to sum objects
« Reply #4 on: August 13, 2019, 12:45:19 PM »
Try something like this (untested)


Hi Ron Thank you very much because it works very well. I really appreciate your help.

I realized that I had an error when I wrote the initget: on line 3; but I simply removed the "r" which is too much, since it doesn't work with arcs. But now everything is fine. I will study your code to learn from it.

Another detail that I do not know how to solve is when I want to add everything, I have to type "a" to be able to designate objects. How can I make it to be predetermined and work with an enter key?
« Last Edit: August 13, 2019, 01:01:30 PM by Romero »

ronjonp

  • Needs a day job
  • Posts: 6995
Re: Filter to sum objects
« Reply #5 on: August 13, 2019, 12:47:42 PM »
Try something like this (untested)


Hi Ron Thank you very much because it works very well. I really appreciate your help.

I realized that I had an error when I wrote the initget: on line 3; but I simply removed the "r" which is too much, since it doesn't work with arcs. But now everything is fine. I will study your code to learn from it.
Sounds good .. I just quickly updated the code above to remove unnecessary calls. Also remove the conversion to val-objects since the curve function work faster with enames.

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

Romero

  • Mosquito
  • Posts: 18
Re: Filter to sum objects
« Reply #6 on: August 13, 2019, 01:13:56 PM »
Try something like this (untested)


Hi Ron Thank you very much because it works very well. I really appreciate your help.

I realized that I had an error when I wrote the initget: on line 3; but I simply removed the "r" which is too much, since it doesn't work with arcs. But now everything is fine. I will study your code to learn from it.
Sounds good .. I just quickly updated the code above to remove unnecessary calls. Also remove the conversion to val-objects since the curve function work faster with enames.

Hi Ron. Your last modification now does not work with any of the elements. Something went wrong.

ronjonp

  • Needs a day job
  • Posts: 6995
Re: Filter to sum objects
« Reply #7 on: August 13, 2019, 02:05:31 PM »
Try something like this (untested)


Hi Ron Thank you very much because it works very well. I really appreciate your help.

I realized that I had an error when I wrote the initget: on line 3; but I simply removed the "r" which is too much, since it doesn't work with arcs. But now everything is fine. I will study your code to learn from it.
Sounds good .. I just quickly updated the code above to remove unnecessary calls. Also remove the conversion to val-objects since the curve function work faster with enames.

Hi Ron. Your last modification now does not work with any of the elements. Something went wrong.
Try again .. copy paste error and needed a default for 'All' :)
« Last Edit: August 13, 2019, 02:08:43 PM by ronjonp »

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

Romero

  • Mosquito
  • Posts: 18
Re: Filter to sum objects
« Reply #8 on: August 13, 2019, 04:16:34 PM »
Try again .. copy paste error and needed a default for 'All' :)

Thanks Ron. That has worked great. I really appreciate your help and effort. Cheers

ronjonp

  • Needs a day job
  • Posts: 6995
Re: Filter to sum objects
« Reply #9 on: August 14, 2019, 11:41:01 AM »
Try again .. copy paste error and needed a default for 'All' :)

Thanks Ron. That has worked great. I really appreciate your help and effort. Cheers
Glad to help :)

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC