Author Topic: Error after making field, referred to the Xref  (Read 2812 times)

0 Members and 1 Guest are viewing this topic.

frostmourn

  • Mosquito
  • Posts: 4
Error after making field, referred to the Xref
« on: September 30, 2015, 11:28:08 AM »
Hello all. I have got a problem during working with external references. Here the file AC-11 was used in the file AC-22 as attached Xref. Then doing the following code in it:
 
Code - Auto/Visual Lisp: [Select]
  1. (defun c:123 ( /  LST adoc str_lst)
  2.         (vl-load-com)
  3.         (vlax-for x
  4.                 (vla-get-blocks adoc)
  5.                 (if (equal (vla-get-isxref x) :vlax-true) (setq LstXref (cons x LstXref)))
  6.         )
  7.         (foreach x
  8.                 (get-block-contents (car LstXref))
  9.                 (if (wcmatch (vla-get-objectname x) "*Text")
  10.                         (setq LST (cons x LST))
  11.                 )
  12.         )
  13.         (setq str_lst
  14.                 (mapcar
  15.                         '(lambda (x)
  16.                                         (LM:ConstructFieldString x "TextString" "")
  17.                         )
  18.                         LST
  19.                 )
  20.         )
  21.         (foreach x
  22.                 (sstolist_vla (ssget "_X" '((8 . "Specification") (0 . "TEXT"))))
  23.                 (vla-put-textstring x (car str_lst))
  24.                 (setq str_lst (cdr str_lst))
  25.                 x
  26.         )
  27.         (vla-regen adoc acActiveViewport)
  28. )
  29.  
  30. ;; LM:ConstructFieldString
  31. (
  32.     (lambda ( )
  33.         (vl-load-com)
  34.         (if (null acdoc)
  35.             (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
  36.         )
  37.         (eval
  38.             (list 'defun 'LM:ConstructFieldString '(ent prop format / ent )
  39.                 (list 'if 'ent
  40.                     (list 'strcat "%<\\AcObjProp Object(%<\\_ObjId "
  41.                         (if
  42.                             (and
  43.                                 (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
  44.                                 (vlax-method-applicable-p (vla-get-utility acdoc) 'getobjectidstring)
  45.                             )
  46.                             (list 'vla-getobjectidstring (vla-get-utility acdoc) 'ent ':vlax-false)
  47.                            '(itoa (vla-get-objectid ent))
  48.                         )
  49.                         ">%)." 'prop '(if (not (eq "" format)) (strcat " \\f \"" format "\">%") ">%")
  50.                     )
  51.                 )
  52.             )
  53.         )
  54.     )
  55. )
  56.  
  57. (defun sstolist_vla (ss / i lst)
  58.         (setq i 0)
  59.         (if ss
  60.                 (repeat (sslength ss)
  61.                         (setq lst (append lst (list (vlax-ename->vla-object (ssname ss i)))) i (1+ i))
  62.                 );end of repeat
  63.         )
  64.         lst
  65. )
  66.  
  67. (defun get-block-contents (ent / def res _kpblc-conv-vla-to-list)
  68.                           ; exam: (get-block-contents (car (entsel "\n&#1042;&#1099;&#1073;&#1077;&#1088;&#1080;&#1090;&#1077; &#1073;&#1083;&#1086;&#1082;")))
  69.    (defun _kpblc-conv-vla-to-list (value / res)
  70.      (cond ((listp value) (mapcar (function _kpblc-conv-vla-to-list) value))
  71.           ((= (type value) 'variant) (_kpblc-conv-vla-to-list (vlax-variant-value value)))
  72.           ((= (type value) 'safearray)
  73.            (if (>= (vlax-safearray-get-u-bound value 1) 0)
  74.              (_kpblc-conv-vla-to-list (vlax-safearray->list value))
  75.              ) ;_ end of if
  76.            )
  77.           ((and (= (type value) 'vla-object) (vlax-property-available-p value 'count))
  78.            (vlax-for sub value (setq res (cons sub res))) ;_ end of vlax-for
  79.            )
  80.           (t value)
  81.           ) ;_ end of cond
  82.     ) ;_ end of defun
  83.  
  84.   (cond ((and ent
  85.               (= (type ent) 'ename)
  86.               (= (cdr (assoc 0 (entget ent))) "INSERT")
  87.               ) ;_ end of and
  88.          (setq res (get-block-contents (vlax-ename->vla-object ent)))
  89.          )
  90.         ((and ent (= (type ent) 'vla-object) (wcmatch (strcase (vla-get-objectname ent)) "*BLOCK*"))
  91.                         (setq def (vla-item (vla-get-blocks (vla-get-document ent)) (vla-get-name ent)))
  92.                         (setq res ; (list
  93.                                 ((lambda (/ _lst) (vlax-for subent def (setq _lst (cons subent _lst))) (reverse _lst)))
  94.                           ; (_kpblc-conv-vla-to-list (vla-getattributes ent))
  95.                           ; (_kpblc-conv-vla-to-list (vla-getconstantattributes ent))
  96.                           ; ) ;_ end of list
  97.                         )
  98.         )
  99.         ) ;_ end of cond
  100.   res
  101. )
As a result we are obtaining a list of field codes, refering to the text entities on a specified layer in the Xref. And now if we paste codes to the texts in AC-22 trying to make working field, then after saving drawing will constantly get an error window - "recommended to do RECOVER procedure" (don't remember right wording).
I have tried to paste only textstrings; to process a simple block instead of Xref - all is good. Also tried using of Acad2016, saving in old versions, no matter. After re-opening file works correctly, audit shows 0 errors. Fields are the necessary condition here. :-( Can anybody give a solution or explanation at least? Will be happy even could to set off an error window.
System - Autocad 2010 x64 sp3 rus, SPDSGraphics 8.0, windows 7 pro x64 sp1. Thanks in advance.
Sorry for probably mistakes.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Error after making field, referred to the Xref
« Reply #1 on: September 30, 2015, 11:43:13 AM »
Not related to your code but ... first thing I see you should not be doing is putting special characters in your file names.

This is the dl'd file I see .. something weird going on.


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

frostmourn

  • Mosquito
  • Posts: 4
Re: Error after making field, referred to the Xref
« Reply #2 on: October 01, 2015, 04:24:14 AM »
Hmm, very strange... I see ordinary letters. It's something related with cyrillic encoding, I think.
Ok, here are files with only numbers using (by the way, it had no effect according to my problem...).
« Last Edit: October 01, 2015, 04:32:12 AM by frostmourn »