Multi line filtering to measure the length

Multi line filtering to measure the length

Anonymous
Not applicable
1,252 Views
4 Replies
Message 1 of 5

Multi line filtering to measure the length

Anonymous
Not applicable

Since more than a year I am looking for a solution for this below problem.

 

I have several types of multi line styles in my drawing. Each multi line styles having plenty of line objects. I want to calculate the total length of each multi lines styles used in the drawing. I am unable to filter the multi lines based on their styles.

 

Please refer the attached sketch shown for example. In this I have 4 types of multi line styles like UB610, UB406, UB203 & UB305. I need to calculate the total length of UB610, UB406, UB203 & UB305 used in the drawing. Can anybody suggest any lisp program for this. Your suggestions may solve our big problem.

 

Thank you.

 

Regards

 

Premkumar d

0 Likes
1,253 Views
4 Replies
Replies (4)
Message 2 of 5

marko_ribar
Advisor
Advisor

From posted picture, I see the differences between those MLINE styles are in their widths... Is that true? And what do you need as lengths - cumulative distances of both sides ( or if some style is caped of all 4 sides ) as MLINEs line sub entities, or just single distances which is what I think is your request is about? It would be also nice if you could also post small DWG with your MLINES with defined styles... Probably the answer is stored somewhere inside DXF codes of MLINES or their property values for which you should look into either through function (dumpallproperties mline-ename) or through (vlax-dump-object mline-vla-object t = methods-optional parameter) and using (vla-get-xxx mline-vla-object) and (vla-put-xxx mline-vla-object) functions...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 3 of 5

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... I am unable to filter the multi lines based on their styles.

 

.... I have 4 types of multi line styles like UB610, UB406, UB203 & UB305. I need to calculate the total length of UB610, UB406, UB203 & UB305 used in the drawing.

 

....

I don't understand being unable to filter based on Style.  Does this not find all the UB610-Style Multilines?

 

(ssget "_X" '((0 . "MLINE") (2 . "UB610")))

Kent Cooper, AIA
0 Likes
Message 4 of 5

marko_ribar
Advisor
Advisor

Here, I've written something, if my assumptions are correct about single distances ( if you have 2 sub entity lines and you wish them to account - you can just multiply this results by 2.0 )... For 4 sub entity lines you have to include widths DXF Code 40 within each mline and also multiply by 2.0 for each rectangular mline and add those values within total results...

 

(defun c:mlstyleslengths ( / mlstylesdict mlstyles mlstyless i ml coords pl len rtn )

  (vl-load-com)

  (setq mlstylesdict (dictsearch (namedobjdict) "acad_mlinestyle"))
  (setq mlstyles (mapcar 'cdr (vl-remove-if '(lambda ( x ) (/= (car x) 3)) mlstylesdict)))
  (foreach mlstyle mlstyles
    (setq mlstyless (ssget "_A" (list '(0 . "MLINE") (cons 2 (strcase mlstyle)) (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model")))))
    (if mlstyless
      (progn
        (repeat (setq i (sslength mlstyless))
          (setq ml (ssname mlstyless (setq i (1- i))))
          (setq coords (safearray-value (variant-value (vla-get-coordinates (vlax-ename->vla-object ml)))))
          (repeat (/ (length coords) 3)
            (setq pl (cons (list (car coords) (cadr coords) (caddr coords)) pl))
            (setq coords (cdddr coords))
          )
          (setq len (apply '+ (mapcar '(lambda ( a b ) (distance a b)) pl (cdr pl)))) ;;; only single length by each mline
;;; (setq len (* len 2.0)) - remove this comment if you wish results by 2 sub entity lines
;;; (setq len (+ (* len 2.0) (* (cdr (assoc 40 (entget ml))) 2.0))) - remove this comment if you wish results by rectangular mlines (setq pl nil) ) (setq rtn (cons (list mlstyle len) rtn)) ) (setq rtn (cons (list mlstyle 0.0) rtn)) ) ) (foreach row rtn (prompt "\nTotal length of MLSTYLE : \"") (princ (car row)) (prompt "\" is : ") (princ (rtos (cadr row) 2 50)) ) (princ) )

HTH., M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 5 of 5

marko_ribar
Advisor
Advisor

I had some lacks in my code... Here is revision :

 

(defun c:mlstyleslengths ( / mlstylesdict mlstyles mlstyless lens i ml coords pl len rtn )

  (vl-load-com)

  (setq mlstylesdict (dictsearch (namedobjdict) "acad_mlinestyle"))
  (setq mlstyles (mapcar 'cdr (vl-remove-if '(lambda ( x ) (/= (car x) 3)) mlstylesdict)))
  (foreach mlstyle mlstyles
    (setq mlstyless (ssget "_A" (list '(0 . "MLINE") (cons 2 (strcase mlstyle)) (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model")))))
    (if mlstyless
      (progn
        (setq lens 0.0)
        (repeat (setq i (sslength mlstyless))
          (setq ml (ssname mlstyless (setq i (1- i))))
          (setq coords (safearray-value (variant-value (vla-get-coordinates (vlax-ename->vla-object ml)))))
          (repeat (/ (length coords) 3)
            (setq pl (cons (list (car coords) (cadr coords) (caddr coords)) pl))
            (setq coords (cdddr coords))
          )
          (setq len (apply '+ (mapcar '(lambda ( a b ) (distance a b)) pl (cdr pl)))) ;;; only single length by each mline
          ;;; (setq len (* len 2.0)) - remove this comment if you wish results by 2 sub entity lines
          ;;; (setq len (+ (* len 2.0) (* (cdr (assoc 40 (entget ml))) 2.0))) - remove this comment if you wish results by rectangular mlines
          (setq lens (+ lens len))
          (setq pl nil)
        )
        (setq rtn (cons (list mlstyle lens) rtn))
      )
      (setq rtn (cons (list mlstyle 0.0) rtn))
    )
  )
  (foreach row rtn
    (prompt "\nTotal length of MLSTYLE : \"") (princ (car row)) (prompt "\" is : ") (princ (rtos (cadr row) 2 50))
  )
  (princ)
)
Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes