Author Topic: Problem of modify the dxf code 301 of FIELD  (Read 1754 times)

0 Members and 1 Guest are viewing this topic.

xiaocai2

  • Mosquito
  • Posts: 6
Problem of modify the dxf code 301 of FIELD
« on: November 07, 2022, 01:35:01 AM »
I wrote a routine to modify the "AcSm Sheet.Title" of the FIELD by replace the string of dxf code 301, It always append but not replace with the string to be modified, Anyone can help me? many thanks!


Code - Auto/Visual Lisp: [Select]
  1. (setq a (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_FIELDLIST"))))
  2. (setq l (vl-remove-if-not (function (lambda(x) (= (car x) 330))) (entget a)))
  3. (setq l (mapcar 'cdr l))
  4.             (if (and (cdr (assoc 2 (entget x)))  (vl-string-search "AcSm Sheet.Title" (cdr (assoc 2 (entget x)))))
  5.                 (progn
  6.                     ;;(setq ent x)
  7.                     (setq entlst (entget x))
  8.                     (setq entlst  (subst (cons 301 "SITE PLAN_test") (assoc 301 entlst) entlst))
  9.                     (entmod entlst)
  10.                     (princ (entget x)) (princ "\n")
  11.                 )
  12.             )
  13.          )
  14.          l
  15. )
« Last Edit: November 07, 2022, 01:42:55 AM by xiaocai2 »

d2010

  • Bull Frog
  • Posts: 323
Re: Problem of modify the dxf code 301 of FIELD
« Reply #1 on: November 14, 2022, 06:42:17 AM »
Why your test.dwg contain only one entity?
Can you insert  many entities with (dxf2 "AcSm Sheet.Title"), into insert            test.dwg?
You have one routine, named commander. This routine as defun,must send multiple commands with one char.
(D.Display   all )
(A.append   with LISpR14)
(B.append with Visual-Lisp)
(R.Replace)
(E.Erase)
                           
(pp_acsmsheet "D")
(pp_acsmsheet "R")
(pp_acsmsheet "S")
My Acad is broken.today I cannot continue Test.

Code - Auto/Visual Lisp: [Select]
  1. (Defun C:q2()
  2.  ;|d26000:0000000001|;  (setq;|a450|;
  3.          dfn_pp_v1chkR nil) ;|/d26000:0000000002|;  
  4.   (pp_xiaocai2sheet301tile_app)
  5. )
  6.  
  7.  
  8. (Defun asserte(mssg / $rr)
  9.  ;|d26000:0000000003|;  (setq;|a749|;
  10.          acad__assertNo (+ acad__assertNo 1)) (if (/= mssg nil) (setq;|a819|;
  11.          erprv erlsp
  12.          erlsp mssg)) ;|/d26000:0000000004|;
  13. erlsp)
  14.  
  15.  
  16. (Prompt "\nCommand.com=Q2[enter]\n")
  17. (Defun pp_xiaocai2sheet301tile_app( / )
  18.    (setq acad__assertNo 0)
  19.  
  20.  
  21.   ;;{$R (call_stas)}
  22. ;------------------------Stdcall nn_vmload
  23.   (setq _ax (nn_vmload ))
  24. ;------------------------
  25.  ;;{$R dfn_cad_amain_callend2}
  26.  
  27.  
  28.  ;|d26000:0000000005|;  (princ "\nEnd") ;|/d26000:0000000006|;  
  29. T)
  30.  
  31. (Defun nn_vmload(/ ask dyn)
  32.             (setq ask "D")
  33.      (while (/= ask "X") (progn
  34.             (pp_acsmsheet ask)
  35.             (setq ask (dfn_getx_readkey "[DARXP]" "\nAcmSheetCommand (a-append)(r-replace)(x-exit)(d-displayall)(p-princ)?:"))
  36.      )
  37.   )
  38. )
  39. ;;{$R pp_acsmsheet}
  40. (Defun pp_acsmsheet(nircmd / $rr allornot item xlog repstr entlst noe repp reps old cnt upx)
  41.   ;|d26000:0000000007|;   (vl_load_com ) (setq;|a4694|;
  42.          allornot (pp_sheetextarray )) (prompt "\nMaxCount....=") (if (and  allornot (listp allornot)) (progn (princ (itoa (length allornot))) (terpri ))) (if (=  nircmd "R") (progn (setq;|a4881|;
  43.          repstr (getstring T "\nEnter StrReplace(0.default)(1.skip):=")) (if (=  repstr "0") (setq;|a4955|;
  44.          repstr "SITE PLAN_test")) (if (/= repstr "1") (foreach xlog allornot (setq;|a5042|;
  45.          entlst (entget xlog)
  46.          entlst (subst (cons 301 repstr) (assoc 301 entlst) entlst))) (setq;|a5179|;
  47.          noe (entmod entlst))))) (if (=  nircmd "D") (progn (foreach xlog allornot (setq;|a5288|;
  48.          entlst (entget xlog)
  49.          noe (princ (assoc 301 entlst))
  50.          noe (grread ))))) (if (=  nircmd "P") (progn (foreach xlog allornot (setq;|a5489|;
  51.          entlst (entget xlog)
  52.          noe (princ (assoc 301 entlst)))) (grread ))) (if (=  nircmd "A") (progn (setq;|a5643|;
  53.          repp (getstring T "\nAppend prefix (1.skip)=")
  54.          cnt 0
  55.          reps (getstring T "\nAppend sufix  (nil.skip)=")) (if (or (>  (strlen reps) 0) (>  (strlen repp) 0)) (foreach xlog allornot (setq;|a5880|;
  56.          entlst (entget xlog)
  57.          upx (dfn_ent_dxf_01 entlst)
  58.          olds (assoc 301 entlst)
  59.          entlst (subst (strcat repp olds reps) olds entlst))) (setq;|a6091|;
  60.          cnt (+ cnt 1)
  61.          noe (list (entmod entlst) (princ "\rCount=") (princ (itoa cnt)))
  62.          noe (list (entupd olds) (grread ))))))  ;|/d26000:0000000008|;
  63. $rr)
  64. ;;{$E}
  65. ;;Inf:
  66. (defun dfn_getx_readkey(k574 t469 / retc kbd msg two chk lei item)
  67.   ;|d26000:0000000009|;   (setq;|a7970|;
  68.          retc (chr 0)
  69.          kbd (if (>  k574 "") k574 "")) (if (and  (/= t469 nil) (listp t469)) (foreach item t469 (princ item)) (if (=  (type t469) (read "STR")) (prompt t469) (prompt "\nByA:DragneAdrian2019=T469error<>Str:"))) (setq;|a8262|;
  70.          chk (if (>  (strlen kbd) 1) 0 1)) (progn  (while (=  chk 0) (progn (setq;|a8372|;
  71.          two 0) (while (/= two 2) (setq;|a8427|;
  72.          lei (grread )
  73.          two (car lei))) (setq;|a8506|;
  74.          retc (strcase (chr (cadr lei)))) (setq;|a8566|;
  75.          chk (if (>  kbd "") (if (wcmatch retc kbd) 1 0) 0))) )) (princ retc)
  76. retc)
  77. ;;{$R pp_sheetextarray}
  78. (Defun pp_sheetextarray(/ $rr all item tit ggr x)
  79.    (setq all (dfn_dict_dxf330))
  80.    (setq $rr nil)
  81.  
  82.  
  83.    (foreach x all (setq;|a9303|;
  84.          ggr (entget x)
  85.          tit (cdr (assoc 2 ggr))
  86.          $rr (if (and  tit (vl-string-search "AcSm Sheet.Title" tit)) (cons x $rr) $rr)))
  87. $rr)
  88. ;;{$E "Wait until press keys k"}
  89. ;;{$R vl_load_com}
  90. (defun vl_load_com(/ $rr)
  91.  (if (null con_modspace) (progn (vl-load-com) (prompt "\n\n")))
  92.  (setq vlax_true :Vlax-True
  93.        vlax_false :Vlax-False
  94.        kHomeRegistry "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD")
  95.  (setq con_acadapp (vlax-get-acad-object))
  96.  (setq con_acdoc (vla-get-activedocument con_acadapp))
  97.  (setq con_acdocUtility (vla-get-utility con_acdoc))
  98.  (setq con_modspace (vla-get-modelspace con_acdoc))
  99.  ;; set a reference to the current model space
  100. )
  101. ;;{$E}
  102. ;;{$R dfn_ent_dxf_01}
  103. (Defun dfn_ent_dxf_01 (a023 / $rr ff it00) ;_ASSERT_OK
  104.    (setq;|a10692|;
  105.          it00 (- 1)
  106.          $rr nil) (if a023 (progn (setq;|a10772|;
  107.          ff a023) (if (=  (type ff) (read "PICKSET")) (setq;|a10844|;
  108.          ff (ssname a023 0))) (setq;|a10894|;
  109.          $rr (if (=  (type ff) (read "ENAME")) (entget ff) (if (and (/= ff nil) (listp ff)) ff nil))))) (if (/= $rr nil) (setq;|a11088|;
  110.          $rr (cdr (assoc it00 $rr))))
  111. $rr)
  112. ;;{$E}
  113. (Defun dfn_dict_dxf330( /  $rr x ace lnk)
  114.  (setq ace (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_FIELDLIST"))))
  115.  (setq lnk (vl-remove-if-not (function (lambda(x) (= (car x) 330))) (entget ace)))
  116.  (setq $rr (mapcar 'cdr lnk))
  117. $rr)
  118. ;;{$E}
  119. ;;{$R coff_linkerarx}
  120.  
  121.  
« Last Edit: November 15, 2022, 01:32:54 PM by d2010 »