Jump to content

Block Attribute Value to Polyline elevation.


Civils_Ben

Recommended Posts

Hi all, first time poster here.

 

Been searching around for a while on various sites for a Lisp routine that I can select an attribute block then apply the value in the block to a polyline's elevation.

 

I even tried Chat GPT but this appears to be too complex for it so i thought I would ask the experts.

 

CAD test file attached for assistance.

 

test.dwg

 

Apologies if this is in the wrong thread.

 

Cheers,

 

Ben

 

 

Link to comment
Share on other sites

Welcome aboard, there are 2 ways to set the elevations. You can also use nentsel to pick the attribute value directly from the block.

 

(defun c:selev ( / ent ent2)
(setq ent (car  (nentsel "\nPick the attribute text ")))
(setq elev (atof (cdr (assoc 1 (entget ent)))))
(setq ent2 (entget (car (entsel "\nPick pline "))))
(entmod (subst (cons 38 elev) (assoc 38 ent2) ent2))
(princ)
)

 

; VL
(defun c:selev ( / obj elev obj2)
(setq obj (vlax-ename->vla-object (car (nentsel "\pick the attribute "))))
(setq elev (atof (vlax-get obj 'textstring)))
(setq obj2 (vlax-ename->vla-object (car (entsel "\nPick the pline "))))
(vlax-put obj2 'elevation elev)
(princ)
)

 

Link to comment
Share on other sites

With your dynamic bloc, try this...

(defun c:att2elev ( / ss n ename dxf_ent dxf_10 ss_bl o l_att)
	(princ "\nSelect polyline")
  (setq ss
    (ssget
      (list
        (cons 0 "lWPOLYLINE")
        (cons 67 (if (eq (getvar "CVPORT") 1) 1 0))
        (cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model"))
        (cons 8 "T_E_Construction layer")
        (cons -4 "&") (cons 70 1)
      )
    )
  )
  (cond
    (ss
      (repeat (setq n (sslength ss))
        (setq
          ename (ssname ss (setq n (1- n)))
          dxf_ent (entget ename)
          dxf_10 (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10))dxf_ent))
          ss_bl (ssget "_WP" (mapcar '(lambda (x) (trans x 0 1)) dxf_10) '((0 . "INSERT") (2 . "`*U*") (8 . "T_E_FFL") (66 . 1)))
        )
        (cond
          (ss_bl
            (if (= "T_E_FFL" (strcase (vla-get-effectivename (setq o (vlax-ename->vla-object (ssname ss_bl 0))))))
              (progn
                (setq
                  l_att
                  (mapcar
                    '(lambda (at)
                      (list (Vla-get-tagstring at)(Vla-get-textstring at) at)
                    )
                    (vlax-invoke o 'GetAttributes)
                  )
                )
                (mapcar
                  '(lambda (x)
                    (if (eq (car x) "FFL")
                      (entmod (subst (cons 38 (read (cadr x))) (assoc 38 dxf_ent) dxf_ent))
                    )
                  )
                  l_att
                )
              )
            )
          )
        )
      )
    )
  )
  (prin1)
)

 

Link to comment
Share on other sites

Only one minor adjustment in @Tsuky code...

This line :

(setq ss_bl (ssget "_WP" (mapcar '(lambda (x) (trans x 0 1)) dxf_10) '((0 . "INSERT") (2 . "`*U*") (8 . "T_E_FFL") (66 . 1))))

Should be :

(setq ss_bl (ssget "_WP" (mapcar '(lambda (x) (trans x ename 1)) dxf_10) '((0 . "INSERT") (2 . "`*U*") (8 . "T_E_FFL") (66 . 1))))

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