Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

i WANT TO AUTO UPDATE ALL BLOCKS WITH Z HIGHT WITH LISP

jlootsCB78E
Explorer

i WANT TO AUTO UPDATE ALL BLOCKS WITH Z HIGHT WITH LISP

jlootsCB78E
Explorer
Explorer

Hi I'm new to this

I have a large number of blocks in my drawing with the same field "UTILITY_INVERT".

they all the different z values, and i want to update all the fields in one go without to edit them manually.

 

Can someone direct me in the right direction 

0 Likes
Reply
580 Views
8 Replies
Replies (8)

Moshe-A
Mentor
Mentor

@jlootsCB78E  hi,

 

check this COZ (Common Z) command.

 

enjoy

Moshe

 

 

(vl-load-com) ; load activex support

; common z value
(defun c:coz (/ askdist ; local function
	        adoc ss ename elist)

 (defun askdist (def / ask)
  (if (not (setq ask (getdist (strcat "\nSpecify common Z <" (rtos def 2) ">: "))))
   (setq ask def)
   (setq def ask)
  )
 ); askdist

 ; here start c:coz 
 (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-startUndoMark adoc)
  
 (if (and
       (setvar "userr5" (setq z (askdist (getvar "userr5"))))
       (setq ss (ssget "_:L" '((0 . "insert"))))
     )
  (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
   (setq elist (entget ename))
   (entmod (subst (reverse (cons z (cdr (reverse (assoc '10 elist))))) (assoc '10 elist) elist))
  ); foreach
 ); if

 (vla-endUndoMark adoc)
 (vlax-release-object adoc)
 (princ) 
); c:coz

 

0 Likes

CADaSchtroumpf
Advisor
Advisor

If you stretch your line to the tip of your solid, you can insert a field in the default attribute value that will retrieve the Z of your starting point of the line.

On insert if a Z is provided (.XY then Z keyboard value or snap to an entity) the attribute will be updated

Field value:

 

 

%<\AcObjProp.16.2 Object(%<\_ObjId 1405295569824>%,1).StartPoint \f "%lu6%pt4">%

 

0 Likes

jlootsCB78E
Explorer
Explorer

The block already have a x y z position. I need to update the attribute value of "UTILITY_INVERT" in the data field.

So I need to take the Z from the block position and update the field.

 

0 Likes

jlootsCB78E
Explorer
Explorer

If you look at the Z it is at 1250 so i want to have the :UTILITY_INVERT" updated to I.L.=1250.000 and if posseble remove 110mm from the hight to give me the new invert of I.L.=1249.89 is where I want to land up.

 

Thanks for the help

0 Likes

Moshe-A
Mentor
Mentor

@jlootsCB78E ,

 

fixed

 

(vl-load-com) ; load activex support

; common z value
(defun c:coz (/ askdist ; local function
	        adoc ss ename elist)

 (defun askdist (def / ask)
  (if (not (setq ask (getdist (strcat "\nSpecify common Z <" (rtos def 2) ">: "))))
   (setq ask def)
   (setq def ask)
  )
 ); askdist

 ; here start c:coz 
 (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-startUndoMark adoc)
  
 (if (and
      ; (setvar "userr5" (setq z (askdist (getvar "userr5"))))
       (setq ss (ssget "_:L" '((0 . "insert"))))
     )
  (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
   (setq elist (entget ename))
 ; (entmod (subst (reverse (cons z (cdr (reverse (assoc '10 elist))))) (assoc '10 elist) elist))
   (setPropertyvalue ename "utility_invert" (strcat "I.L.=" (rtos (last (assoc '10 (entget ename))) 2 2)))
  ); foreach
 ); if

 (vla-endUndoMark adoc)
 (vlax-release-object adoc)
 (princ) 
); c:coz

 

0 Likes

jlootsCB78E
Explorer
Explorer

Thank you.

 

Is there a way to auto deduct the UTILITY_HEIGHT from the value as well?

 

Will be apreciated

 

0 Likes

CADaSchtroumpf
Advisor
Advisor

Alway with the fields...

Copy-paste directly in command line

((lambda ( / ss n ent obj)
  (setq ss (ssget "_X" '((0 . "INSERT") (2 . "Utl_Arrow Bottom Left"))))
  (cond
    (ss
      (setvar 'cmdecho 0)
      (repeat (setq n (sslength ss))
        (setq
          ent (ssname ss (setq n (1- n)))
          obj (vlax-ename->vla-object ent)
        )
        (vla-put-TextString (cadr (vlax-invoke obj 'GetAttributes))
          (strcat
            "I.L.="
            "%<\\AcExpr ("
            "%<\\AcObjProp Object(%<\\_ObjId "
            (itoa (vla-get-ObjectID obj))
            ">%).InsertionPoint \\f \"%pt4\">%"
            "-(0.001*"
            "%<\\AcObjProp Object(%<\\_ObjId "
            (itoa (vla-get-ObjectID (last (vlax-invoke obj 'GetAttributes))))
            ">%).TextString>%)) \\f \"%lu2%pr2\">%"
          )
        )
        (vl-cmdf "_.updatefield" ent "")
      )
      (setvar 'cmdecho 1)
    )
  )
  (prin1)
))
0 Likes

jlootsCB78E
Explorer
Explorer

Thank 

 

This helps a million

0 Likes