Help for select line or polyline based on a diameter text under

Help for select line or polyline based on a diameter text under

Anonymous
Not applicable
2,084 Views
17 Replies
Message 1 of 18

Help for select line or polyline based on a diameter text under

Anonymous
Not applicable

hello

I have dwg contain a bunch of line similar to attached dwg. Lines are drawn with the same layers but their diameters are different. I need to do a list based on the length and diameter of the lines. I want to select all the lines with Q40 and Q32 diameter seperately and calculate the legth. If they different layer it would be easy . How can I do it

thnks

ozgun

0 Likes
Accepted solutions (1)
2,085 Views
17 Replies
Replies (17)
Message 2 of 18

imadHabash
Mentor
Mentor

Hi,

 

>> If they different layer it would be easy . << 

Yes you're right ... in such case i'm afraid that you have to do it manually and start to separate those lines. 

 

Regards,

Imad Habash

EESignature

0 Likes
Message 3 of 18

Anonymous
Not applicable

manually would be very time consuming. There must be code or lisp ?

0 Likes
Message 4 of 18

tramber
Advisor
Advisor

Time consuming in lisp too !

 

(defun c:d32-40(/ selb32 selb40 sel compt ent comptbis ent32 ent40) 
 (setq selb32(ssget "_A" '((0 . "INSERT")(2 . "32"))));(sslength selb32)
 (setq selb40(ssget "_A" '((0 . "INSERT")(2 . "40"))));(sslength selb40)
 (setq sel(ssget '((0 . "LINE")))  compt -1)
 (repeat(sslength sel)
  (setq ent(ssname sel(setq compt(1+ compt))))
  (setq comptbis -1 stop nil)
  (while (and (setq ent32(ssname selb32(setq comptbis(1+ comptbis))))
          (not stop))
   (if(vlax-curve-getParamAtPoint(vlax-ename->vla-object ent)(cdr(assoc 10(entget ent32))))
    (progn(vla-put-color(vlax-ename->vla-object ent) 1)(setq stop T))))
  (setq comptbis -1)
  (while (and (setq ent40(ssname selb40(setq comptbis(1+ comptbis))))
          (not stop))
   (if(vlax-curve-getParamAtPoint(vlax-ename->vla-object ent)(cdr(assoc 10(entget ent40))))
    (progn(vla-put-color(vlax-ename->vla-object ent) 3)(setq stop T))))
  ) 
 (princ(strcat"\n"(itoa(1+ compt))" objects treated"))
 (princ)
 )

But with this one loaded you can enter D32-40 as a command, select the lines.

They will have their color changed if and only if one of your two block is inserted exactly on the line, snaped in a word.

The result is bad for now. But it works.

We could detect a minimal distance too, but you may agree that it would be dangerous :!?

U can use the code to publish it and modify it in the right sub-forum if you want.


EESignature

0 Likes
Message 5 of 18

imadHabash
Mentor
Mentor

>> manually would be very time consuming. There must be code or lisp ? <<

the problem here is that there is NO link between the text and the line and there is a variety of lines positions (Hor. or Ver. ) so the question here is how to force AUtoCAD to find those lines without existing common property such as layer,color,..etc ? you may find some one who can try to write a code for such a case !!

 

Regards,

Imad Habash

EESignature

0 Likes
Message 6 of 18

john.uhden
Mentor
Mentor

There are many lines that don't have labels and many more labels that don't have lines.

What's the difference between "yogusma" and "dia?"

I do notice that certain labels are parallel  and proximitous to certain lines.  I guess that is the "glue" we must analyze to determine what label goes with what line.  But as I said, there are many lines (mostly short) that have no apparent labels.  At least the lines that have multiple labels have the same label.

 

Then again, I had to use TrueView to convert the drawing back to 2000, so maybe a number of objects disappeared in the conversion.

 

My thought is to create a selection set of all the lines and a separate selection set of all the labels.  Then I would iterate through all the members of the line selection and have a function to test each label for proximity and parallelity.  If there are one or more matching labels, then I would add its length to one variable for 032 and one for 040.  At the same time I would change each qualifying line to a new appropriate layer, such as D032 and D040, each with different colors so that you can easily see what lines were matched with labels.

John F. Uhden

0 Likes
Message 7 of 18

john.uhden
Mentor
Mentor

Oops.  Upon further inspection the labels are attribute blocks.  Can we be certain that the attributes are at the same angle as the block insertion?

John F. Uhden

0 Likes
Message 8 of 18

CADaSchtroumpf
Advisor
Advisor
Accepted solution

Hi,

 

It's have similar discussion here.

 

For your exemple, the lisp are adapted. Can be a possible way for you?

 

First use this:

 

(defun round_number (xr n / )
  (* (fix (atof (rtos (/ xr n) 2 0))) n)
)
(defun c:Ozgun( / l_var doc sel l_text pt js ent dxf_ent)
  (vl-load-com)
  (setq l_var (mapcar 'getvar '("CMDECHO" "APERTURE" "APBOX" "AUTOSNAP" "OSMODE" "PICKBOX")))
  (mapcar 'setvar '("CMDECHO" "APERTURE" "APBOX" "AUTOSNAP" "OSMODE" "PICKBOX") '(0 1 0 0 0 0))
  (vl-cmdf "_.zoom" "_extent")
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (ssget "_X" (list '(0 . "INSERT") '(2 . "40,32")(cons 410 (getvar "ctab"))))
  (vlax-for bl (setq sel (vla-get-activeselectionset doc))
    (cond
      ((or (= "32" (vla-get-EffectiveName bl)) (= "40" (vla-get-EffectiveName bl)))
        (foreach pr (vlax-invoke bl 'GetAttributes)
          (setq l_text (cons (vlax-get-property pr 'TextString) l_text))
        )
        (setq pt (vlax-get bl 'InsertionPoint))
      )
    )
    (cond
      ((and l_text pt)
        (vl-cmdf "_.zoom" "_ce" pt 2000)
        (setq js
          (ssget "_C" (mapcar '- pt '(5.0 5.0 0.0)) (mapcar '+ pt '(5.0 5.0 0.0))
            (list
              '(0 . "LINE")
              '(8 . "vrfyog")
              (cons 67 (if (eq (getvar "CVPORT") 1) 1 0))
              (cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model"))
            )
          )
        )
        (cond
          (js
            (setq
              ent (ssname js 0)
              dxf_ent (entget ent)
            )
            (if (null (tblsearch "appid" "ARMATURE"))
              (regapp "ARMATURE")
            )
            (entmod
              (append
                (entget ent)
                (list
                  (list -3
                    (list
                      "ARMATURE"
                      (cons 1002 "{")
                      (cons 1000 "Diameter")
                      (cons 1000 (car l_text))
                      (cons 1000 "Length")
                      (cons 1040 (distance (cdr (assoc 10 dxf_ent)) (cdr (assoc 11 dxf_ent))))
                      (cons 1002 "}")
                    )
                  )
                )
              )
            )
          )
          (T (princ "\nPas de selection"))
        )
      )
    )
    (setq l_text nil)
  )
  (vl-cmdf "_.zoom" "_extent")
  (mapcar 'setvar '("CMDECHO" "APERTURE" "APBOX" "AUTOSNAP" "OSMODE" "PICKBOX") l_var)
  (prin1)
)

And after this:

(vl-load-com)
(defun c:Tab_Ozgun ( / js nb lst_hdl lst_length lst_dia obj dxf_ent elist xd_list e_data file2open f_open oldim)
  (princ "\nSelect model polyline for filtering layer: ")
	(while (null (setq js (ssget "_+.:E:S" '((0 . "LINE") (-3 ("ARMATURE"))))))
		(princ "\nIsn't an available object!")
	)
  (setq js
    (ssget "_X" 
      (list
        '(0 . "LINE") '(-3 ("ARMATURE"))
        (assoc 8 (entget (ssname js 0)))
      )
    )
  )
  (cond
    (js
      (setq
        nb 0
        lst_hdl '()
        lst_length '()
        lst_dia '()
      )
      (repeat (setq n (sslength js))
        (setq
          obj (ssname js (setq n (1- n)))
          dxf_ent (entget obj)
          elist (entget obj (list "ARMATURE"))
          xd_list (cdr (assoc -3 elist))
          e_data (mapcar 'cdr (cdr (car xd_list)))
          lst_hdl (cons (cdr (assoc 5 dxf_ent)) lst_hdl)
          lst_length (cons (cadr (cdddr e_data)) lst_length)
          lst_dia (cons (car (cddr e_data)) lst_dia)
          nb (1+ nb)
        )
      )
      (setq
        file2open (strcat (getvar "DWGPREFIX") (getvar "DWGNAME") ".CSV")
        f_open (open file2open "w")
      )
      (setq oldim (getvar "dimzin"))
      (setvar "dimzin" 0)
      (foreach n
        (mapcar'list
          (cons "Handle" lst_hdl)
          (cons "Length" lst_length)
          (cons "Diameter" lst_dia)
        )
        (write-line
          (apply
            'strcat
            (mapcar 
              '(lambda (x)
                (strcat
                  (cond
                    ((eq (type x) 'REAL) (rtos x 2 0))
                    ((eq (type x) 'INT) (itoa x))
                    ((eq (type x) 'STR) x)
                  )
                  ";"
                )
              )
              n
            )
          )
          f_open
        )
      )
      (close f_open)
      (setvar "dimzin" oldim)
      (princ (strcat "\nData are written in the file -> " file2open))
    ) 
    (T (princ "\nNo find LINE with appid ARMATURE"))
  )
  (prin1)
)
0 Likes
Message 9 of 18

Anonymous
Not applicable

hello

Thanks for the replies. Not have time to check the code. I have not write any code in autocad. Do I write it to command window in autocad ?

0 Likes
Message 10 of 18

imadHabash
Mentor
Mentor

Hi,

 

>> Do I write it to command window in autocad ? <<

No..just copy it to an empty new .txt file then rename it to .lsp. after that use APPLOAD command for the new previous .lsp file then execute it from command line.

 

Regards,

Imad Habash

EESignature

0 Likes
Message 11 of 18

Anonymous
Not applicable

I named it but after loading the command not found occurs. Can I give any name can't I

0 Likes
Message 12 of 18

Anonymous
Not applicable

Also I do as 2 seperate lisp file , correct right ?

0 Likes
Message 13 of 18

imadHabash
Mentor
Mentor

honestly ... i didn't use it or examine it ... but make the file name as the same name existing in the beginning of the code after .... defun c:  .

Imad Habash

EESignature

0 Likes
Message 14 of 18

Anonymous
Not applicable

It did not recognise first lsp unfortunately

0 Likes
Message 15 of 18

Anonymous
Not applicable

Not working for now. I add a blank after C:ozgun text in the first lisp. It loaded and after second loaded but nothing happened. It says Is not an avaliable Object

0 Likes
Message 16 of 18

Anonymous
Not applicable

after applying the code, I cannot get inside block attributes it only selects blocks what happened ?

0 Likes
Message 17 of 18

Anonymous
Not applicable

I needed to restore defaults to take settings back to normal. Why did you use osnap, polar track .. etc set to 0. It did not see all the lines so gave missing lenght.

0 Likes
Message 18 of 18

Anonymous
Not applicable

I have a similar problem. This time, no block attributes just Dtext format pipe diameter for fresh water lines. The trick is pipe diameter pointer line intersects with the relative line. So how can I write pipe according to their diameter in an excel file with length again ?

An example is uploaded

0 Likes