Author Topic: Change the value of a PartRef in AutoCAD Mechanical  (Read 396 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 344
Change the value of a PartRef in AutoCAD Mechanical
« on: July 02, 2024, 02:21:36 AM »
Hi,
I wrote the following lisp function to change the value of an attribute of an AutoCAD Mechanical PartRef.
Unfortunately, I haven't used the lists associated with DXF properties and the ENTMOD function for years and I'm a bit rusty.
Can you help me?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:TestScrivi ()
  2.   (setq etichetta "DESCR")
  3.   (setq nuovovalore "XXX")
  4.   (setq ent (car (entsel "\nSelect PartRef: ")))
  5.   (if ent
  6.     (progn
  7.       (setq entlist (entget ent))
  8.       (setq entlist_completa entlist)
  9.       (setq NomeEl (cdr (assoc '330 entlist_completa)))
  10.       (setq entlist (entget (cdr (assoc '330 entlist))))
  11.      
  12.       (setq Dxf_Completo '())
  13.       (setq Dxf_ParteDati '())
  14.       (setq lista330 nil)
  15.  
  16.       ;Start creation of part list containing data
  17.       (setq n 0)
  18.       (setq coppia (nth n entlist))
  19.       (while (/= coppia nil)
  20.         (progn
  21.           (if (= (cdr coppia) etichetta)
  22.             (progn
  23.               (setq Dxf_ParteDati (cons coppia Dxf_ParteDati)) ;scrive etichetta
  24.               (setq n (+ n 1))
  25.               (setq coppia (nth n entlist))
  26.               (setq Dxf_ParteDati (cons (cons 2 nuovovalore) Dxf_ParteDati)) ;scrive valore
  27.             )
  28.             (setq Dxf_ParteDati (cons coppia Dxf_ParteDati))
  29.           )
  30.           ;--
  31.           (setq n (+ n 1))
  32.           (setq coppia (nth n entlist))
  33.         )
  34.       )
  35.       (setq Dxf_ParteDati (reverse Dxf_ParteDati))
  36.       (setq Dxf_ParteDati (assoc 330 Dxf_ParteDati))
  37.       ;End creation of part list containing data
  38.  
  39.       (princ "\n0A")
  40.       ;Start creating complete list
  41.       (setq n 0)
  42.       (setq coppia (nth n entlist_completa))
  43.       (while (/= coppia nil)
  44.         (progn
  45.           (if (and (= (car coppia) 330) (= lista330 nil))
  46.             (progn
  47.               (progn
  48.                 (alert "sono qui")
  49.                 (setq NomeEl (cdr coppia))
  50.                 (princ "\n0C")
  51.                 (setq Dxf_Completo (append Dxf_Completo (list Dxf_ParteDati)))
  52.                 (princ "\n0D")
  53.               )
  54.               (setq lista330 T)
  55.             )
  56.             (progn
  57.               (princ "\n0E")
  58.               (setq Dxf_Completo (cons coppia Dxf_Completo))
  59.               (princ "\n0G")
  60.             )
  61.           )
  62.           ; --
  63.           (setq n (+ n 1))
  64.           (setq coppia (nth n entlist_completa))
  65.         )
  66.       )
  67.       (princ "\n0G")
  68.       (setq Dxf_Completo (reverse Dxf_Completo))
  69.       ;End creating complete list
  70.      
  71.       (princ "\n1")
  72.       (entmod Dxf_Completo)
  73.       (princ "\n2")
  74.       (entupd NomeEl)
  75.       (princ "\n3")
  76.      
  77.       (prompt "\nOk.")
  78.     )
  79.     (prompt "\nNo Selected.")
  80.   )
  81.   (princ)
  82. )
  83.  


Unfortunately it doesn't work because checking the object data after starting the function is unchanged.
To carry out the tests, use the attached file in AutoCAD Mechanical, as in AutoCAD Full the drawing does not show any objects.

I hope for your help.

edit @kerry : add AutoLisp code formatting tag [code=cadlisp-7]
« Last Edit: July 02, 2024, 05:05:38 AM by kdub_nz »