Jump to content

Lisp for total line length for lines which in every separately box


Recommended Posts

Posted

Hi Everyone,

I want to make this with lisp in Autocad... 

 

I want to export totale line lenght to excel table..

but i want to see lenght of lines with their box name with lenght..

Pls see example in attachment,

 

Can you help me pls this issue

 

Autocad Lisp.jpg

Posted

@mssoysal  For better understanding, and  maybe get further help, please upload such sample.dwg
As far as I know, ACAD only can edit DWG.
 Or send it to devitg@gmail.com 

Posted
6 hours ago, devitg said:

@mssoysal  For better understanding, and  maybe get further help, please upload such sample.dwg
As far as I know, ACAD only can edit DWG.
 Or send it to devitg@gmail.com 

 

Hi Devitg;

Pls find sample document with attachment...

 

Thank you so much

 

Autocad Lisp.rar

Posted (edited)

;;; Source : https://www.cadtutor.net/forum/topic/74677-lisp-for-total-line-length-for-lines-which-in-every-separately-box/?do=findComment&comment=591483
;;; REMOVE DUPLICATES - NON RECURSIVE NON COMMAND FUNCTION ;;;

(setq lst '("box1" "box1" "box1" "box2" "box2" "box3" "box3"))
(defun mr_RemoveDupl (InList fuzz / x r )
  (while (setq x (car InList))
    (setq InList
      (vl-remove-if
        (function
          (lambda ( y )
            (equal x y fuzz)
          )
        ) InList
      )
    )
    (setq r (append r (list x)))
  )
)
(mr_RemoveDupl lst 0) => ("box1" "box2" "box3")

(setq lst '("box1" "box1" "box1" "box2" "box2" "box3" "box3"))
(defun mr_RemoveDupl (InList fuzz)
  (vl-remove-if-not
    (function
      (lambda ( x )
        (if
          (vl-some
            (function
              (lambda ( y )
                (equal x y fuzz)
              )
            ) InList
          )
          (progn
            (setq InList
              (vl-remove-if
                (function
                  (lambda ( y )
                    (equal x y fuzz)
                  )
                ) InList
              )
            )
            x
          )
        )
      )
    ) InList
  )
)
(mr_RemoveDupl lst 0) => ("box1" "box2" "box3")

(setq lst '("box1" "box1" "box1" "box2" "box2" "box3" "box3"))
(setq rtn
  (vl-sort
    (setq lst
      (vl-remove nil
        (mapcar
          (function
            (lambda ( x / r )
              (if
                (vl-some
                  (function
                    (lambda ( y )
                      (equal x y)
                    )
                  ) lst
                )
                (progn
                  (setq lst
                    (vl-remove-if
                      (function
                        (lambda ( z )
                          (equal x z)
                        )
                      ) lst
                    )
                  )
                  x
                )
              )
            )
          ) lst
        )
      )
    )
    (function
      (lambda ( a b )
        (< (atoi a) (atoi b))
      )
    )
  )
)
rtn => ("box1" "box2" "box3")

Create pseudo code :
1. Select all rectangles...
2. Iterate through selection set...
3. Foreach rectangle :
  * 1. Select all entities inside - [ curve entities / have lenghts : (vlax-curve-getdistatparam curve (vlax-curve-getendparam curve)) ]
  * 2. Foreach curve :
      * create/append association list (rectangle-description / curve-length ^^^ look above ^^^)

4. Look into this topic to learn how to quickly create TABLE enitity from data stored in LIST (association list - previously built)
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/table-editing/m-p/9335975

5. Insert 2 tables - like you wanted...

For first one :

for ex. :

(setq assoclst '(("box1" 15) ("box1" 20) ("box1" 50) ("box2" 30) ("box2" 20) ("box3" 25) ("box3" 12)))
(setq rtn
  (vl-sort assoclst
    (function
      (lambda ( a b )
        (< (atoi (car a)) (atoi (car b)))
      )
    )
  )
)
rtn => (("box1" 15) ("box1" 20) ("box1" 50) ("box2" 30) ("box2" 20) ("box3" 25) ("box3" 12))

For second one - you'll have to summarize lengths foreach parent rectangle :

for ex. :

(setq assoclst '(("box1" 15) ("box1" 20) ("box1" 50) ("box2" 30) ("box2" 20) ("box3" 25) ("box3" 12)))
(setq rtn
  (vl-sort
    (vl-remove nil
      (mapcar
        (function
          (lambda ( x / r )
            (if
              (and
                (setq r
                  (apply (function +)
                    (mapcar (function cadr)
                      (vl-remove-if-not
                        (function
                          (lambda ( y )
                            (equal (car x) (car y))
                          )
                        )
                        (progn
                          (or
                            lst
                            (setq lst assoclst)
                          )
                          lst
                        )
                      )
                    )
                  )
                )
                (assoc (car x) lst)
                (setq lst
                  (vl-remove-if
                    (function
                      (lambda ( z )
                        (equal (car x) (car z))
                      )
                    ) lst
                  )
                )
              )
              (list (car x) r)
            )
          )
        ) assoclst
      )
    )
    (function
      (lambda ( a b )
        (< (atoi (car a)) (atoi (car b)))
      )
    )
  )
)
rtn => (("box1" 85) ("box2" 50) ("box3" 37))

Edited by marko_ribar
Posted
On 3/26/2022 at 11:25 PM, marko_ribar said:

;;; Source : https://www.cadtutor.net/forum/topic/74677-lisp-for-total-line-length-for-lines-which-in-every-separately-box/?do=findComment&comment=591483
;;; REMOVE DUPLICATES - NON RECURSIVE NON COMMAND FUNCTION ;;;

(setq lst '("box1" "box1" "box1" "box2" "box2" "box3" "box3"))
(defun mr_RemoveDupl (InList fuzz / x r )
  (while (setq x (car InList))
    (setq InList
      (vl-remove-if
        (function
          (lambda ( y )
            (equal x y fuzz)
          )
        ) InList
      )
    )
    (setq r (append r (list x)))
  )
)
(mr_RemoveDupl lst 0) => ("box1" "box2" "box3")

(setq lst '("box1" "box1" "box1" "box2" "box2" "box3" "box3"))
(defun mr_RemoveDupl (InList fuzz)
  (vl-remove-if-not
    (function
      (lambda ( x )
        (if
          (vl-some
            (function
              (lambda ( y )
                (equal x y fuzz)
              )
            ) InList
          )
          (progn
            (setq InList
              (vl-remove-if
                (function
                  (lambda ( y )
                    (equal x y fuzz)
                  )
                ) InList
              )
            )
            x
          )
        )
      )
    ) InList
  )
)
(mr_RemoveDupl lst 0) => ("box1" "box2" "box3")

(setq lst '("box1" "box1" "box1" "box2" "box2" "box3" "box3"))
(setq rtn
  (vl-sort
    (setq lst
      (vl-remove nil
        (mapcar
          (function
            (lambda ( x / r )
              (if
                (vl-some
                  (function
                    (lambda ( y )
                      (equal x y)
                    )
                  ) lst
                )
                (progn
                  (setq lst
                    (vl-remove-if
                      (function
                        (lambda ( z )
                          (equal x z)
                        )
                      ) lst
                    )
                  )
                  x
                )
              )
            )
          ) lst
        )
      )
    )
    (function
      (lambda ( a b )
        (< (atoi a) (atoi b))
      )
    )
  )
)
rtn => ("box1" "box2" "box3")

Create pseudo code :
1. Select all rectangles...
2. Iterate through selection set...
3. Foreach rectangle :
  * 1. Select all entities inside - [ curve entities / have lenghts : (vlax-curve-getdistatparam curve (vlax-curve-getendparam curve)) ]
  * 2. Foreach curve :
      * create/append association list (rectangle-description / curve-length ^^^ look above ^^^)

4. Look into this topic to learn how to quickly create TABLE enitity from data stored in LIST (association list - previously built)
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/table-editing/m-p/9335975

5. Insert 2 tables - like you wanted...

For first one :

for ex. :

(setq assoclst '(("box1" 15) ("box1" 20) ("box1" 50) ("box2" 30) ("box2" 20) ("box3" 25) ("box3" 12)))
(setq rtn
  (vl-sort assoclst
    (function
      (lambda ( a b )
        (< (atoi (car a)) (atoi (car b)))
      )
    )
  )
)
rtn => (("box1" 15) ("box1" 20) ("box1" 50) ("box2" 30) ("box2" 20) ("box3" 25) ("box3" 12))

For second one - you'll have to summarize lengths foreach parent rectangle :

for ex. :

(setq assoclst '(("box1" 15) ("box1" 20) ("box1" 50) ("box2" 30) ("box2" 20) ("box3" 25) ("box3" 12)))
(setq rtn
  (vl-sort
    (vl-remove nil
      (mapcar
        (function
          (lambda ( x / r )
            (if
              (and
                (setq r
                  (apply (function +)
                    (mapcar (function cadr)
                      (vl-remove-if-not
                        (function
                          (lambda ( y )
                            (equal (car x) (car y))
                          )
                        )
                        (progn
                          (or
                            lst
                            (setq lst assoclst)
                          )
                          lst
                        )
                      )
                    )
                  )
                )
                (assoc (car x) lst)
                (setq lst
                  (vl-remove-if
                    (function
                      (lambda ( z )
                        (equal (car x) (car z))
                      )
                    ) lst
                  )
                )
              )
              (list (car x) r)
            )
          )
        ) assoclst
      )
    )
    (function
      (lambda ( a b )
        (< (atoi (car a)) (atoi (car b)))
      )
    )
  )
)
rtn => (("box1" 85) ("box2" 50) ("box3" 37))

Thanks Marko_ribar..

But I didnt open lisp.. It error Bad function Type - "box1"..

But I want to draw table in excel.. not in the cad? Your code draw table in cad i think?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...