Jump to content

Select all blocks crossing by specific polylines


Jozef13

Recommended Posts

Dear all,

I am looking for lisp to select all blocks crossing by specific polylines.

I have scheme of ventilation ducting system drawn by polylines where are inserted flow dampers.

My polylines have specific linetypes correspondig to size of the duct.

So I want to select e.g. all blocks lying on polylines with linetype "TZB_100" and than I can write to flow damper block atttibute tag "SIZE" the value 100.

And next the same for others sizes 125, 160, ....

 

And finaly I can create bill of quantyty of specific flow dampers and others components.

Scheme.dwg

Scheme.png

Link to comment
Share on other sites

Hi,

 

Just this a go.

 

(defun c:Test (/ int sel ent get bks lws ins)
 ;;	Tharwat . Date: 17.Jun.2018	;;
 (and
   (setq int -1
         sel (ssget "_:L"
                    '((-4 . "<OR")
                      (-4 . "<AND")
                      (0 . "LWPOLYLINE")
                      (6 . "TZB_100,TZB_125,TZB_160")
                      (-4 . "AND>")
                      (-4 . "<AND")
                      (0 . "INSERT")
                      (2 . "dn_cu")
                      (-4 . "AND>")
                      (-4 . "OR>")
                     )
             )
   )
   (progn
     (while (setq ent (ssname sel (setq int (1+ int))))
       (if (= (cdr (assoc 0 (setq get (entget ent)))) "INSERT")
         (setq bks (cons get bks))
         (setq lws (cons get lws))
       )
     )
     (and bks lws)
   )
   (foreach lw lws
     (foreach bk bks
       (and
         (setq ins (cdr (assoc 10 bk)))
         (equal (distance
                  (vlax-curve-getclosestpointto (cdr (assoc -1 lw)) ins)
                  ins
                )
                0.0
                1e-4
         )
         (vl-some
           '(lambda (att)
              (and
                (eq (vla-get-tagstring att) "DN")
                (vla-put-textstring att (substr (cdr (assoc 6 lw)) 5))
              )
            )
           (vlax-invoke
             (vlax-ename->vla-object (cdr (assoc -1 bk)))
             'getattributes
           )
         )
         (setq bks (vl-remove bk bks))
       )
     )
   )
 )
 (princ)
) (vl-load-com)

Link to comment
Share on other sites

Perfect Tharwat,

First I was confused because it seemed to me it do nothing.

But when I looked at tho code I realised tht it works, but it work with "dn_cu" block and attribute tag "DN" instead of "Flow damper-JL" block and tag "SIZE".

When I changed it, It work exactly as I need.

 

You helped me more than I expected :):):)

 

Small problem is with "Flow damper-JL" block because it is dynamic block and if it is dynamicaly rotated it apears as Anonymous (Block Name: "Flow damper-JL", Anonymous Name: "*U20") and it isn't selected by code.

 

Is it possible to modify it to select blocks based on original name ?

Link to comment
Share on other sites

Hi Jozef,

 

Sorry for this late reply due to overload of work.

 

I have modified the program to include that Dynamic block 'Flow Damper-JL' with the related tag string 'SIZE' so please try the following program and let me know.

 

(defun c:Test (/ int sel ent get obj bks lws ins)
 ;;	Tharwat . Date: 19.Jun.2018	;;
 (and
   (setq int -1
         sel (ssget "_:L"
                    '((-4 . "<OR")
                      (-4 . "<AND")
                      (0 . "*POLYLINE")
                      (6 . "TZB_100,TZB_125,TZB_160")
                      (-4 . "AND>")
                      (-4 . "<AND")
                      (0 . "INSERT")
                      (2 . "`*U*,Flow damper-JL,dn_cu")
                      (-4 . "AND>")
                      (-4 . "OR>")
                     )
             )
   )
   (progn
     (while (setq ent (ssname sel (setq int (1+ int))))
       (cond ((wcmatch (cdr (assoc 0 (setq get (entget ent)))) "*LINE")
              (setq lws (cons get lws))
             )
             ((wcmatch (vla-get-effectivename
                         (setq obj (vlax-ename->vla-object ent))
                       )
                       "Flow damper-JL,dn_cu"
              )
              (setq bks (cons (list obj get) bks))
             )
       )
     )
     (and bks lws)
   )
   (foreach lw lws
     (foreach bk bks
       (and
         (setq ins (cdr (assoc 10 (cadr bk))))
         (or (equal
               (distance
                 (vlax-curve-getclosestpointto (cdr (assoc -1 lw)) ins)
                 ins
               )
               0.0
               1e-4
             )
             (vlax-invoke
               (car bk)
               'intersectwith
               (vlax-ename->vla-object (cdr (assoc -1 lw)))
               AcExtendnone
             )
         )
         (vl-some
           '(lambda (att)
              (and
                (wcmatch (vla-get-tagstring att) "DN,SIZE")
                (progn (vla-put-textstring att (substr (cdr (assoc 6 lw)) 5)) t)
              )
            )
           (vlax-invoke (car bk) 'getattributes)
         )
         (setq bks (vl-remove bk bks))
       )
     )
   )
 )
 (princ)
) (vl-load-com)

Edited by Tharwat
Codes enhanced a bit
Link to comment
Share on other sites

Thank you very much.

It works perfectly :o:o:)

I have a new idea if you can find some time for that.

Is it possible to modify secondary block attribute based on primary block attribute that are both lying on the same polyline ?

I describe the reason why:

When I create scheme of ventilation ducting system drawn by polylines I insert block "dn_cu" on each segment with different airflow.

Than I make numbering of segments ("CU" Tag) and add airflows in m3/h ("V" Tag).

After that I export all attributes to excel and make dimensioning of ducts sizes ("DN" Tag) and import it back to AutoCAD.

So block "dn_cu" is my primary block with informations about ducting scheme.

Than I need to modify "size" attribute of secondary block ar blocks (dampers, attenuators..) and finaly change linetype of the polyline segment based on "DN" attribute.

Link to comment
Share on other sites

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...