autocad LIsp for change the attributes value in object data.. one at a time glob

autocad LIsp for change the attributes value in object data.. one at a time glob

Yuvaraju.Dhananjay
Enthusiast Enthusiast
4,572 Views
13 Replies
Message 1 of 14

autocad LIsp for change the attributes value in object data.. one at a time glob

Yuvaraju.Dhananjay
Enthusiast
Enthusiast

hi all,

please anyone provide the lisp for change the attribute value one at a time in object data of block reference.

example: suppose i need CO288E instead of CO288(10M). How to change this one at a time through out drawing of 2000 blocks. For more details find the attached image and drawing.

0 Likes
Accepted solutions (2)
4,573 Views
13 Replies
Replies (13)
Message 2 of 14

Kent1Cooper
Consultant
Consultant

FIND will do that.

 

FIND.png

Kent Cooper, AIA
Message 3 of 14

Yuvaraju.Dhananjay
Enthusiast
Enthusiast

Kent,

 

FIND command will search the values in object data rite. i want the values changes in object data of block reference. 

 

Capture.JPG

0 Likes
Message 4 of 14

CADaSchtroumpf
Advisor
Advisor
Accepted solution

If always substitute (10M) -> E, you can try this:

 

(defun C:yuvaraju ( / string-subst js n ent val)
  (defun string-subst (value_string old_string new_string / nbs tmp_nbs)
    (setq nbs 0)
    (while nbs
      (if (setq nbs (vl-string-search old_string value_string (setq tmp_nbs nbs)))
        (setq
          value_string (vl-string-subst new_string old_string value_string tmp_nbs)
          nbs (1+ nbs)
        )
      )
    )
    value_string
  )
  (setq js (ssget "_X" '((0 . "INSERT") (2 . "POLE_JU") (8 . "AERIAL_POLE") (66 . 1))))
  (cond
    (js
      (repeat (setq n (sslength js))
        (setq ent (ssname js (setq n (1- n))))
        (setq val (ade_odgetfield ent "FTTH_POINTS" "RUS_UNIT1" 0))
        (cond
          (val
            (ade_odsetfield ent "FTTH_POINTS" "RUS_UNIT1" 0 (string-subst val "(10M)" "E"))
          )
        )
      )
    )
  )
  (prin1)
)
Message 5 of 14

Yuvaraju.Dhananjay
Enthusiast
Enthusiast

Your great.. thank you.. keep in touch always... 

0 Likes
Message 6 of 14

Kent1Cooper
Consultant
Consultant

@Yuvaraju.Dhananjay wrote:

.... 

FIND command will search the values in object data rite. i want the values changes in object data of block reference. 

 


That's a different animal than an Attribute as described in the Subject line and Post 1....

Kent Cooper, AIA
0 Likes
Message 7 of 14

Yuvaraju.Dhananjay
Enthusiast
Enthusiast

oh okay kent. thank you for your co-operation.

0 Likes
Message 8 of 14

Yuvaraju.Dhananjay
Enthusiast
Enthusiast

From above you have solved one of my problem. To be frank i dont have much knowledge in lisp programming. can u solve same kind of problem but different block.

 

here i need to remove the footage symbol " ' " from the field RUS unti1.( SEAO1=88'---> SEAO=88) i have so many blocks like this in my drawing so i need to change globally from the lisp.

 

see attached drawing.

0 Likes
Message 9 of 14

CADaSchtroumpf
Advisor
Advisor

For this task, I use this:

 

(defun c:Sel_By_OD ( / js dxf_model all_fldnamelist all_fldtypelist all_vallist tbllist tbldef tblstr
                       fldnamelist fldtypelist fldnme fldtyp numrec ct cttemp vallist typ val nl
                       tmp_file dcl_file dcl_id indx Id_tbl Id_nam Id_val op_log what_next js_sel n)
  (princ "\nSelect an model entitie with Object Data ")
  (while
    (null
      (setq js
        (ssget "_+.:E:S:L:N" 
          (list
            (cons 0 "*")
            (cons 67 (if (eq (getvar "CVPORT") 2) 0 1))
            (cons 410 (if (eq (getvar "CVPORT") 2) "Model" (getvar "CTAB")))
          )
        )
      )
    )
  )
  (setq dxf_model (entget (ssname js 0)) all_fldnamelist () all_fldtypelist () all_vallist ())
  (if (null (setq tbllist (ade_odgettables (cdar dxf_model))))
    (princ "\nSelected object without Object Data ")
    (foreach tbl (reverse tbllist)
      (setq
        tbldef (ade_odtabledefn tbl)
        tblstr (cdr (nth 2 tbldef))
        fldnamelist ()
        fldtypelist ()
      )
      (foreach fld tblstr
        (setq
          fldnme (cdr (nth 0 fld))
          fldtyp (cdr (nth 2 fld))
          fldnamelist (append fldnamelist (list fldnme))
          fldtypelist (append fldtypelist (list fldtyp))
        )
      )
      (setq
        numrec (ade_odrecordqty (cdar dxf_model) tbl)
        ct 0
        all_fldnamelist (cons fldnamelist all_fldnamelist)
        all_fldtypelist (cons fldtypelist all_fldtypelist)
      )
      (while (< ct numrec)
        (setq cttemp 0 vallist ())
        (foreach fld fldnamelist
          (setq
            typ (nth cttemp fldtypelist)
            cttemp (+ cttemp 1)
            val (ade_odgetfield (cdar dxf_model) tbl fld ct)
          )
          (if (= typ "Integer")(setq val (fix val)))
          (setq vallist (append vallist (list val)))
        )
        (setq ct (+ ct 1))
      )
      (setq all_vallist (cons vallist all_vallist))
    )
  )
  (cond
    ((and tbllist all_fldnamelist all_fldtypelist all_vallist)
      (setq
        tmp_file (vl-filename-mktemp "sel_by_od.dcl")
        dcl_file (open tmp_file "w")
      )
      (write-line
        "Sel_By_OD : dialog {
          label = \"Choice of field to filter\";
            :column {
              label = \"Table\";
              :popup_list {key=\"tbl\";edit_width=25;}
              }
            :column {
              label = \"Object data\";
              :popup_list {key=\"nam\";edit_width=25;}
              :edit_box {
                label = \"Value of field:\";
                mnemonic = \"V\";
                key = \"val\";
                edit_width = 15;
                edit_limit = 31;
                }
              }
              :boxed_row {
                label = \"Choice of logic operator\";
                :radio_button {
                  label = \"=\";
                  key = \"b_equ\";
                }
                :radio_button {
                  label = \"/=\";
                  key = \"b_dif\";
                }
                :radio_button {
                  label = \">\";
                  key = \"b_sup\";
                }
                :radio_button {
                  label = \"<\";
                  key = \"b_inf\";
                }
                :radio_button {
                  label = \">=\";
                  key = \"b_sup-eq\";
                }
                :radio_button {
                  label = \"<=\";
                  key = \"b_inf-eq\";
                }
              }
            ok_cancel_err;
          }"
        dcl_file
      )
      (close dcl_file)
      (setq dcl_id (load_dialog tmp_file) indx (1- (length tbllist)) Id_tbl (nth indx tbllist) Id_nam (car (nth indx all_fldnamelist)) Id_val (car (nth indx all_vallist)) op_log "=")
      (setq what_next 2)
      (while (< 1 what_next)
        (if (not (new_dialog "Sel_By_OD" dcl_id)) (exit))
        (start_list "tbl")
        (mapcar 'add_list tbllist)
        (end_list)
        (set_tile "tbl" (itoa indx))
        (start_list "nam")
        (mapcar 'add_list (nth indx all_fldnamelist))
        (end_list)
        (set_tile "nam" (itoa (- (length (nth indx all_fldnamelist)) (length (member (car (nth indx all_fldnamelist)) (nth indx all_fldnamelist))))))
        (set_tile "val"
          (setq Id_val
            (car
              (mapcar
                '(lambda (x)
                  (cond
                    ((eq (type x) 'REAL) (rtos x))
                    ((eq (type x) 'INT) (itoa x))
                    ((eq (type x) 'LIST) (apply 'strcat (mapcar 'strcat (mapcar 'rtos x)'("," "," ""))))
                    (T x)
                  )
                )
                (nth indx all_vallist)
              )
            )
          )
        )
        (cond
          ((= op_log "=") (set_tile "b_equ" "1") (mode_tile "b_equ" 2))
          ((= op_log "/=") (set_tile "b_dif" "1") (mode_tile "b_dif" 2))
          ((= op_log ">") (set_tile "b_sup" "1") (mode_tile "b_sup" 2))
          ((= op_log "<") (set_tile "b_inf" "1") (mode_tile "b_inf" 2))
          ((= op_log ">=") (set_tile "b_sup-eq" "1") (mode_tile "b_sup-eq" 2))
          ((= op_log "<=") (set_tile "b_inf-eq" "1") (mode_tile "b_inf-eq" 2))
        )
        (set_tile "error" "")
        (action_tile "tbl" "(setq Id_tbl (nth (setq indx (fix (atof (get_tile \"tbl\")))) tbllist))
        (start_list \"nam\")
        (mapcar 'add_list (nth indx all_fldnamelist))
        (end_list)
        (set_tile \"nam\" (setq Id_nam (nth (- (length (nth indx all_fldnamelist)) (length (member (car (nth indx all_fldnamelist)) (nth indx all_fldnamelist)))) (nth indx all_fldnamelist))))
        (set_tile \"val\"
          (setq Id_val
            (car
              (mapcar
                '(lambda (x)
                  (cond
                    ((eq (type x) 'REAL) (rtos x))
                    ((eq (type x) 'INT) (itoa x))
                    ((eq (type x) 'LIST) (apply 'strcat (mapcar 'strcat (mapcar 'rtos x)'(\",\" \",\" \"\"))))
                    (T x)
                  )
                )
                (nth indx all_vallist)
              )
            )
          )
        )
        ")
        (action_tile "nam" "(setq Id_nam (nth (fix (atof (get_tile \"nam\"))) (nth indx all_fldnamelist)))
        (set_tile \"val\"
          (setq Id_val 
            (nth (vl-position Id_nam (nth indx all_fldnamelist))
              (mapcar
                '(lambda (x)
                  (cond
                    ((eq (type x) 'REAL) (rtos x))
                    ((eq (type x) 'INT) (itoa x))
                    ((eq (type x) 'LIST) (apply 'strcat (mapcar 'strcat (mapcar 'rtos x)'(\",\" \",\" \"\"))))
                    (T x)
                  )
                )
                (nth indx all_vallist)
              )
            )
          )
        )
        ")
        (action_tile "val" "(setq Id_val $value)")
        (action_tile "b_equ" "(setq op_log \"=\")")
        (action_tile "b_dif" "(setq op_log \"/=\")")
        (action_tile "b_sup" "(setq op_log \">\")")
        (action_tile "b_inf" "(setq op_log \"<\")")
        (action_tile "b_sup-eq" "(setq op_log \">=\")")
        (action_tile "b_inf-eq" "(setq op_log \"<=\")")
        (action_tile "accept" "(done_dialog 1)")
        (action_tile "cancel" "(done_dialog 0)")
        (setq what_next (start_dialog))
      )
      (unload_dialog dcl_id)
      (vl-file-delete tmp_file)
      (setq typ (nth (- (length (nth indx all_fldnamelist)) (length (member id_nam (nth indx all_fldnamelist)))) (nth indx all_fldtypelist)) nl nil)
      (cond
        ((eq typ "Real") (setq Id_val (atof Id_val)))
        ((eq typ "Integer") (setq Id_val (atoi Id_val)))
        ((eq typ "Point") (setq Id_val (read (vl-list->string (append (cons 40 (foreach n (reverse (vl-string->list id_val)) (setq nl (cons (if (eq n 44) 32 n) nl)))) '(41))))))
      )
      (setq js
        (ssget "_X"
          (list
            (assoc 0 dxf_model)
            (assoc 8 dxf_model)
            (if (assoc 6 dxf_model) (assoc 6 dxf_model) '(6 . "BYLAYER"))
            (if (assoc 62 dxf_model) (assoc 62 dxf_model) '(62 . 256))
            (if (assoc 48 dxf_model) (assoc 48 dxf_model) '(48 . 1))
            (cons 67 (if (eq (getvar "CVPORT") 1) 1 0))
            (cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model"))
          )
        )
        js_sel (ssadd)
      )
      (cond
        (js
          (repeat (setq n (sslength js))
            (if (not (null (setq tbllist (ade_odgettables (setq ent (ssname js (setq n (1- n))))))))
              (foreach tbl tbllist
                (setq
                  tbldef (ade_odtabledefn tbl)
                  tblstr (cdr (nth 2 tbldef))
                  fldnamelist ()
                  fldtypelist ()
                )
                (foreach fld tblstr
                  (setq
                    fldnme (cdr (nth 0 fld))
                    fldtyp (cdr (nth 2 fld))
                    fldnamelist (append fldnamelist (list fldnme))
                    fldtypelist (append fldtypelist (list fldtyp))
                  )
                )
                (setq numrec (ade_odrecordqty ent tbl) ct 0)
                (while (< ct numrec)
                  (setq cttemp 0)
                  (foreach fld fldnamelist
                    (setq
                      typ (nth cttemp fldtypelist)
                      cttemp (+ cttemp 1)
                      val (ade_odgetfield ent tbl fld ct)
                    )
                    (if (= typ "Integer")(setq val (fix val)))
                    (if
                      (and
                        (eq tbl Id_tbl)
                        (eq fld Id_nam)
                        (if (= typ "Character")
                          (wcmatch val Id_val)
                          (if (= typ "Point")
                            (mapcar '(lambda (u v) (eval (read op_log)) u v) val Id_val)
                            ((eval (read op_log)) val Id_val)
                          )
                        )
                      )
                      (setq js_sel (ssadd ent js_sel))
                    )
                  )
                  (setq ct (+ ct 1))
                )
              )
            )
          )
        )
      )
    )
  )
  (princ (strcat "\n" (itoa (sslength js_sel)) " find(s)"))
  (sssetfirst nil js_sel)
  (prin1)
)

Filter with Table:FFTH_SUBS and field RUS_UNIT1 and in properties of entities change the value.

 

You have an application with best performance in big drawing: Search MQSELECT MAPSHOWOD on the web (it's a dll to load with the command "netload")

0 Likes
Message 10 of 14

Yuvaraju.Dhananjay
Enthusiast
Enthusiast

i had this lisp already. but its not working. The values are not changed. that too i need remove that special symbol from RUS UNIT1. But in this which changes the whole value of the field. 

0 Likes
Message 11 of 14

Yuvaraju.Dhananjay
Enthusiast
Enthusiast

Can you provide that DLL. i searched on the web. i am not getting...

0 Likes
Message 12 of 14

CADaSchtroumpf
Advisor
Advisor

When you are in dialog box "Choice of field to filter" of "sel_by_od", select table "FTTH_SUBS" and object data "RUS_UNIT1"

 

The value of field is (for exemple: SEAO1=88')

Select operator "=" and click Ok

 

Then in properties change 88' to 88

 

For mqselect and mapshow I have this (thank to Olivier Eckmann)

 

 

 

 

0 Likes
Message 13 of 14

Yuvaraju.Dhananjay
Enthusiast
Enthusiast

Its really great one, but how to import the modified CSV file to autocad from using of MAPSHOWOD command.

 

Actually, i have this kind of block of huge number. in all these blocks the RUS UNIT feild having the Footage symbol( ' ). i need to remove the symbol at a time.

0 Likes
Message 14 of 14

CADaSchtroumpf
Advisor
Advisor
Accepted solution

If I have understand...

 

You can use SEL_BY_OD, select your object data "RUS_UNIT1"

The value of field can be SEAO1=88'

 

You can replace for exemple SEAO1=88' by SEAO1=??' (see wcmatch)

Then only object with OD corresponding are selected and gripped.

 

Copy-paste this code in command line must be the change on set selection (change ' to blank).

((lambda ( / js n ename)
  (defun match_replace (string pattern target / l_str l_pat l_trg n tmp l_rv)
    (cond
      ((and (eq (type string) 'STR) (eq (type pattern) 'STR) (eq (type target) 'STR))
        (setq
          l_str (vl-string->list string)
          l_pat (vl-string->list pattern)
          l_trg (vl-string->list target)
        )
        (while l_str
          (repeat (setq n (length l_pat))
            (setq tmp (cons (nth (setq n (1- n)) l_str) tmp))
          )
          (cond
            ((equal tmp l_pat)
              (setq l_rv (append (reverse l_trg) l_rv))
              (repeat (1- (length l_pat)) (setq l_str (cdr l_str)))
            )
            (T
              (setq l_rv (cons (car l_str) l_rv))
            )
          )
          (setq l_str (cdr l_str))
          (setq tmp nil)
        )
        (vl-list->string (reverse l_rv))
      )
    )
  )
  (or
    (setq js (ssget "_I"))
    (setq js (ssget "_P"))
  )
  (cond
    (js
      (repeat (setq n (sslength js))
        (setq ename (ssname js (setq n (1- n))))
        (ade_odsetfield ename "FTTH_SUBS" "RUS_UNIT1" 0 (match_replace (ade_odgetfield ename "FTTH_SUBS" "RUS_UNIT1" 0) "'" ""))
      )
    )
  )
  (prin1)
))

You must adapt the red element to your use.

(ade_odsetfield ename "FTTH_SUBS" "RUS_UNIT1" 0 (match_replace (ade_odgetfield ename "FTTH_SUBS" "RUS_UNIT1" 0) "'" ""))