天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 63|回复: 0

attout导出N多个属性块的排序规则优化

[复制链接]
  • TA的每日心情
    开心
    5 天前
  • 签到天数: 49 天

    [LV.5]常住居民I

    185

    主题

    150

    回帖

    1695

    积分

    管理员

    积分
    1695
    发表于 2024-4-3 08:27:46 | 显示全部楼层 |阅读模式
    如题,attout命令,选择的属性块,如果直接框选属性块,属性块的顺序还是有一定的讲究,研究了一下,这个跟块的新建顺序以及方向都有关系,下面是总结:
    一、直接范围框选多个属性块是正序的情况:
    1、竖直阵列,必须是往从下往上阵列的情况下,框选中的新生成的属性块,在attout命令下导出,才会是从上往下。如果阵列的时候是从上往下的方向阵列,那么attout命令下导出的结果,刚好是倒序的;
    2、水平整列,情况第1点的类似,必须是右往左整列的情况下,attout导出则是从左到右为正序,反则如果是从左往右阵列,则结果就是倒序
    3、那么属性块的顺序被你随机打乱了之后,在进行排序,那么最终的结果,就是无序了,任何一种可能都有;

    针对以上情况,想问下明经的位置大佬,是否能实现框选范围内的属性块,选择集排序顺序是左到右 or 上到下 or 下到上 or右到左,最后一个场景就是,画一根曲线(多段线),在曲线路径上的属性块根据曲线,自定义哪一端为起始点,然后进行排序,并生成attout的txt文件。



    1. ;;;
    2. ;;;    ATTOUT.LSP
    3. ;;;    Created 4/24/98 by Randy Kintzley
    4. ;;;    Copyright ?1999 by Autodesk, Inc.
    5. ;;;
    6. ;;;    Your use of this software is governed by the terms and conditions of the
    7. ;;;    License Agreement you accepted prior to installation of this software.
    8. ;;;    Please note that pursuant to the License Agreement for this software,
    9. ;;;    "[c]opying of this computer program or its documentation except as
    10. ;;;    permitted by this License is copyright infringement under the laws of
    11. ;;;    your country.  If you copy this computer program without permission of
    12. ;;;    Autodesk, you are violating the law."
    13. ;;;
    14. ;;;    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
    15. ;;;    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
    16. ;;;    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
    17. ;;;    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
    18. ;;;    UNINTERRUPTED OR ERROR FREE.
    19. ;;;
    20. ;;;    Use, duplication, or disclosure by the U.S. Government is subject to
    21. ;;;    restrictions set forth in FAR 52.227-19 (Commercial Computer
    22. ;;;    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
    23. ;;;    (Rights in Technical Data and Computer Software), as applicable.
    24. ;;;
    25. ;;;  ----------------------------------------------------------------
    26. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    27. ;ATTOUT -
    28. ;Extracts attribute data from selected block inserts to a tab delimited file.
    29. ;
    30. ;;;attout--------------------------------------------------------------------------
    31. (defun c:AT ( / ss fna )
    32.         (acet-error-init '(nil 0))
    33.         (cond
    34.     ((not (setq        fna (strcat (getvar "mydocumentsprefix") "/"
    35.                                                                                         (vl-filename-base (getvar "dwgname"))
    36.                                                                                         ".xls"
    37.                                                                                 )
    38.                                         )
    39.      );not
    40.                         (princ "\nNo output file selected.")
    41.                 )
    42.                 ((not (setq ss (ssget '((0 . "INSERT") (66 . 1))))
    43.                  );not
    44.                         (princ "\nNo valid objects selected.")
    45.                 )
    46.                 (T
    47.                         (bns_attout fna ss)
    48.                 )
    49.         );cond close
    50.         (acet-error-restore)
    51.         (command "_ai_editcustfile" fna)
    52. );defun c:attout
    53. ;;;attoutf-------------------------------------------------------------------------
    54. (defun c:attoutf ( / ss fna );;限定块名
    55.         (acet-error-init '(nil 0))
    56.         (cond
    57.     ((not (setq        fna (strcat (getvar "mydocumentsprefix") "/"
    58.                                                                                         (vl-filename-base (getvar "dwgname"))
    59.                                                                                         ".xls"
    60.                                                                                 )
    61.                                         )
    62.      );not
    63.                         (princ "\nNo output file selected.")
    64.                 )
    65.                 ((not (setq ss (ssget "x" '((0 . "INSERT") (66 . 1) (2 . "PART-TAB"))))
    66.                  );not
    67.                         (princ "\nNo valid objects selected.")
    68.                 )
    69.                 (T
    70.                         (bns_attout fna ss)
    71.                 )
    72.         );cond close
    73.         (acet-error-restore)
    74. );defun c:attoutf
    75. ;;;attoutg-------------------------------------------------------------------------
    76. (defun c:attoutg ( / ss fna );;限定块名
    77.         (acet-error-init '(nil 0))
    78.         (cond
    79.     ((not (setq        fna (strcat (getvar "mydocumentsprefix") "/glass.xls"
    80.                                                                                 )
    81.                                         )
    82.      );not
    83.                         (princ "\nNo output file selected.")
    84.                 )
    85.                 ((not (setq ss (ssget "X" '((0 . "INSERT") (66 . 1) (2 . "GLASS MARKING"))))
    86.                  );not
    87.                         (princ "\nNo valid objects selected.")
    88.                 )
    89.                 (T
    90.                         (bns_attout fna ss)
    91.                 )
    92.         );cond close
    93.         (acet-error-restore)
    94.         (command "_ai_editcustfile" fna)
    95. );defun c:attoutg
    96. ;;;attoutp-------------------------------------------------------------------------
    97. (defun c:attoutp ( / ss fna );;限定块名
    98.         (acet-error-init '(nil 0))
    99.         (cond
    100.     ((not (setq        fna (strcat (getvar "mydocumentsprefix") "/panel.xls"
    101.                                                                                 )
    102.                                         )
    103.      );not
    104.                         (princ "\nNo output file selected.")
    105.                 )
    106.                 ((not (setq ss (ssget '((0 . "INSERT") (66 . 1) (2 . "PANELMARKING"))))
    107.                  );not
    108.                         (princ "\nNo valid objects selected.")
    109.                 )
    110.                 (T
    111.                         (bns_attout fna ss)
    112.                 )
    113.         );cond close
    114.         (acet-error-restore)
    115.         (command "_ai_editcustfile" fna)
    116. );defun c:attoutp
    117. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    118. ;function version of ATTOUT takes a filename and a selection set.
    119. (defun bns_attout ( fna ss / lst )
    120.         (if (and fna
    121.                                 ss
    122.                                 (setq lst (bns_attout_get_info ss))
    123.                         );and
    124.     (bns_attout_output fna lst)
    125.         );if
    126.         (princ)
    127. );defun bns_attout
    128. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    129. ;Takes a filename and a list of string data and writes it out.
    130. (defun bns_attout_output ( fna lst / n a fh)
    131.         (if (setq fh (open fna "w"))
    132.     (progn
    133.                         (acet-ui-progress-init "Writing output file" (length lst))
    134.                         (setq n 0)
    135.                         (repeat (length lst)
    136.                                 (write-line (nth n lst) fh)
    137.                                 (acet-ui-progress-safe n)
    138.                                 (setq n (+ n 1));setq
    139.                         );repeat
    140.                         (close fh)
    141.                         (acet-ui-progress-done)
    142.                         (if (setq a (findfile fna))
    143.                                 (princ (strcat "\nOutput file: "" a "" created."))
    144.                                 (acet-alert (strcat "\nOutput FAILED for file: "" fna ""."))
    145.                         );if
    146.     );progn then write the file
    147.     (progn
    148.                         (if fna
    149.                                 (acet-alert (strcat "*Error* could not open file ""
    150.                                                                                         fna
    151.                                                                                         "" for write. The file may be currently in use."
    152.                     )
    153.                                 );acet-alert then
    154.                                 (acet-alert "*Error* invalid filename.")
    155.                         );if
    156.     );progn else print the error.
    157.         );if
    158. );defun bns_attout_ouput
    159. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    160. ;bns_attout_get_info - retrieves the data from the block inserts in
    161. ;the selection set provided.
    162. ;
    163. (defun bns_attout_get_info ( ss / delim n j a lst lst2 lst3 lst4 na e1 blk hnd str)
    164.         (setq delim "\t"); the delimiter for the output file.
    165.         (acet-ui-progress-init "Searching for all attribute data" (sslength ss))
    166.         (setq n 0)
    167.         (repeat (sslength ss)
    168.                 (setq   na (ssname ss n)
    169.                         e1 (entget na)
    170.                         lst (acet-insert-attrib-get (list na 1))
    171.                         blk (cdr (assoc 2 e1))
    172.                         hnd (cdr (assoc 5 e1))
    173.                         lst3 (append lst3 (list (list hnd blk lst)))
    174.                 );setq
    175.                 (setq j 0)
    176.                 (repeat (length lst)
    177.                         (setq a (car (nth j lst)));setq
    178.                         (if (not (member a lst2))
    179.         (setq lst2 (append lst2 (list a)));setq
    180.                         );if
    181.                         (setq j (+ j 1));setq
    182.                 );repeat
    183.                 (acet-ui-progress-safe n)
    184.                 (setq n (+ n 1));setq
    185.         );repeat
    186.         (acet-ui-progress-done)
    187.         ;lst2 is now a list w/unique attrib tags
    188.         ;i.e. ("tag" "tag2" "tag3")
    189.         ;lst3 is a list of the form ((handle blockname ((tag value) (tag value)...)
    190.         ;                            (handle blockname ((tag value) (tag value)...)
    191.         ;                            ...
    192.         ;
    193.         ;                           )
    194.         (acet-ui-progress-init "Formatting attribute data for output" (length lst3))
    195.         (setq str (strcat "HANDLE" delim "BLOCKNAME"));setq
    196.         (setq n 0)
    197.         (repeat (length lst2)                             ;;;;build the header for spread sheet.
    198.                 (setq str (strcat str delim (nth n lst2)));setq
    199.                 (setq n (+ n 1))
    200.         );repeat
    201.         (setq lst4 (list str))
    202.         (setq n 0)
    203.         (repeat (length lst3)
    204.                 (setq  lst (nth n lst3)
    205.                         str (strcat "'"
    206.                                                 (car lst)  ;the handle
    207.                                                 delim
    208.                                                 (cadr lst) ;the blockname
    209.                                         );strcat
    210.                         lst (caddr lst)
    211.                 );setq
    212.                 (acet-ui-progress-safe n)
    213.                 (setq j 0)
    214.                 (repeat (length lst2)
    215.                         (setq a (nth j lst2)
    216.                                 a (cadr (assoc a lst))
    217.                         );setq
    218.                         (if (not a)
    219.                                 (setq a "<>")
    220.                         );if
    221.                         (setq str (strcat str delim a));setq
    222.                         (setq j (+ j 1));setq
    223.                 );repeat
    224.                 (setq lst4 (append lst4 (list str)))
    225.                 (setq n (+ n 1));setq
    226.         );repeat
    227.         (acet-ui-progress-done)
    228.         lst4
    229. );defun bns_attout_get_info
    230. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    231. ;ATTIN -
    232. ;Imports attribute data from selected file. The file must be of
    233. ;the same format as created with ATTOUT.
    234. ;
    235. (defun c:AI ( / fna lklay )
    236.         (acet-error-init (list
    237.                                                                                  (list "cmdecho" 0)
    238.                                                                                  0
    239.                                                                                  '(progn
    240.                                                                                                 (if lklay
    241.                                                                                                         (progn
    242.                                                                                                                 (acet-sysvar-set '("cmdecho" 0))
    243.                                                                                                                 (command "_.layer" "_lock" lklay "")
    244.                                                                                                                 (acet-sysvar-restore)
    245.                                                                                                         )
    246.                                                                                                 );if need to re-lock
    247.                                                                                                 (princ (strcat "\n" (itoa #bns_attin_modified) " Block inserts modified."))
    248.                                                                                         );progn
    249.                                                                          )
    250.         )
    251.         (acet-autoload '("yes_no.lsp" "(bns_get_yes_no a b)"))
    252.         (setq #bns_attin_modified 0)
    253.         (cond
    254.                 ((not (setq fna (acet-getfile
    255.                                                                                         "Enter input filename"
    256.                                                                                         (strcat (getvar "mydocumentsprefix")
    257.                                                                                                 (vl-filename-base (getvar "dwgname"))
    258.                                                                                                 ".xls"
    259.                                                                                         )
    260.                                                                                         "xls"
    261.                                                                                         1664
    262.                                                                                 )
    263.                                         )
    264.                  )
    265.                         (princ "\nNo input file selected.")
    266.                 );cond #1
    267.                 ((setq fna (findfile fna))
    268.                         (setq lklay (acet-layer-unlock-all))
    269.                         (if (equal 4 (logand 4 (getvar "cmdactive")))
    270.                                 (bns_attin fna nil);a script is running so no interactive placement
    271.                                 (bns_attin fna T);Allow interactive placement
    272.                         );if
    273.                         (if lklay
    274.                                 (command "_.layer" "_lock" lklay "")
    275.                         );if
    276.                         (princ (strcat "\n" (itoa #bns_attin_modified) " Block inserts modified."))
    277.                 );cond #2
    278.         );cond close
    279.         (acet-error-restore)
    280. );defun c:attin
    281. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    282. ;bns_attin takes a file name and a flag (interact) that specifies
    283. ;if the user should be prompted to select block inserts when unmatched
    284. ;data is found.
    285. ;
    286. (defun bns_attin ( fna interact / fh lst lst2 lst3 lst4 lst5 n j na e1 a delim ans )
    287.         (setq delim "\t")
    288.         (if (setq fh (open fna "r"))
    289.     (progn
    290.                         (princ "\nReading the input file...")
    291.                         (while (setq a (read-line fh))
    292.                                 (if (not lst)        ;change first record to upper case
    293.           (setq a (xstrcase a))
    294.                                 );if
    295.                                 (setq lst (cons (acet-str-to-list delim a) lst));setq
    296.                         );while
    297.                         (setq fh (close fh))
    298.                         (princ " Done.")
    299.                         (setq  lst (reverse lst)
    300.                                 lst2 (cdr lst) ;the data
    301.                                 lst (car lst) ;the column headers
    302.                         );setq
    303.                         (acet-ui-progress-init "Importing data" (length lst2))
    304.                         (setq n 0)
    305.                         (repeat (length lst2)
    306.                                 (setq lst3 (nth n lst2)
    307.                                         lst4 nil
    308.                                 );setq
    309.                                 (acet-ui-progress-safe n)
    310.                                 (setq j 0)                                 ;match the header row with the current record
    311.                                 (repeat (min (length lst) (length lst3))
    312.                                         (setq    a (list (nth j lst)
    313.                                                                                          (nth j lst3)
    314.                                                                                  );list
    315.                                                 lst4 (cons a lst4)
    316.                                         );setq
    317.                                         (setq j (+ j 1));setq
    318.                                 );repeat
    319.                                 (setq lst4 (reverse lst4));setq
    320.                                 (if (and (setq a (cadr (assoc "HANDLE" lst4)))
    321.                                                         (equal "'" (substr a 1 1))
    322.                                                 );and
    323.           (setq a (substr a 2))
    324.                                 );if
    325.                                 (if (and a
    326.                                                         (setq na (handent a))
    327.                                                         (setq e1 (entget na))
    328.                                                         (equal "INSERT" (cdr (assoc 0 e1)))
    329.                                                         (equal 1 (cdr (assoc 66 e1)))
    330.                                                         (or (not (assoc "BLOCKNAME" lst4))
    331.                                                                 (equal (xstrcase (cadr (assoc "BLOCKNAME" lst4)))
    332.                                                                         (xstrcase (cdr (assoc 2 e1)))
    333.                                                                 );equal
    334.                                                         );or
    335.                                                 );and
    336.           (progn
    337.                                                 (if (not (equal 8 (logand 8 (getvar "undoctl"))))
    338.                                                         (acet-undo-begin)
    339.                                                 );if
    340.                                                 (setq lst4 (vl-remove (assoc "BLOCKNAME" lst4) lst4)
    341.                                                         lst4 (vl-remove (assoc "HANDLE" lst4) lst4)
    342.                                                 );setq
    343.                                                 (if (acet-insert-attrib-set na lst4 nil)
    344.                                                         (setq #bns_attin_modified (+ #bns_attin_modified 1))
    345.                                                         (progn
    346.                 (if interact
    347.                                                                         (setq lst5 (cons lst4 lst5));setq add to interactive list.
    348.                                                                         (princ "\nNo matching attribute tags.")
    349.                 );if
    350.                                                         );progn else
    351.                                                 );if
    352.                                                 (acet-undo-end)
    353.           );progn then
    354.           (progn
    355.                                                 ;Print what's going on...
    356.                                                 (if (not interact)
    357.                                                         (cond
    358.                 ((not a)
    359.                                                                         (princ "\nNo Handle specification.")
    360.                 )
    361.                 ((not na)
    362.                                                                         (princ (strcat "\nNo entity with specified handle "" a "" exists."))
    363.                 )
    364.                 (T
    365.                                                                         (princ (strcat "\nSpecified entity: "" a "" has been deleted or is invalid. "))
    366.                 )
    367.                                                         );cond then non-interactive execution
    368.                                                         (setq lst5 (cons lst4 lst5));setq else gather a list of attribs with
    369.                                                         ;no insert home.
    370.                                                 );if
    371.                                         );progn else no home for this record
    372.                                 );if
    373.                                 (setq n (+ n 1));setq
    374.                         );repeat
    375.                         (acet-ui-progress-done)
    376.                         (if (and lst5
    377.                                                 interact
    378.                                                 (setq ans (bns_get_yes_no
    379.                                                                                                 (list "ATTIN - Select blocks?"
    380.                                                                                                         (strcat
    381.                                                                                                                 ""
    382.                                                                                                                 "\n    One or more records of data could not be"
    383.                                                                                                                 "\n   matched to block inserts within this drawing."
    384.                                                                                                                 "\n"
    385.                                                                                                                 "\n    Do you want to select the block inserts "
    386.                                                                                                                 "\n   and assign this data interactively?"
    387.                                                                                                         );strcat
    388.                                                                                                 );list
    389.                                                                                                 (list 40 10)
    390.                                                                                         );bns_get_yes_no
    391.                                                 );setq
    392.                                                 (equal ans 1)
    393.                                         );and
    394.                                 (progn
    395.           (princ "\nSelect the desired blocks to assign the data to and press ENTER when done.")
    396.           (bns_attin_interactive (reverse lst5))
    397.                                 );progn then
    398.                         );if
    399.     );progn then
    400.     (acet-alert "\nError opening input file for read.")
    401.         );if
    402. );defun bns_attin
    403. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    404. (defun bns_attin_interactive ( lst / na e1 )
    405.         (while lst
    406.                 (if (not (equal 8 (logand 8 (getvar "undoctl"))))
    407.                         (acet-undo-begin)
    408.                 );if
    409.                 (bns_print_att_list (car lst))
    410.                 (princ "\nPress [Enter] to skip or [Esc] to finish.")
    411.                 (if (and (setq na (acet-ui-single-select '((0 . "INSERT") (66 . 1)) nil))
    412.           (setq e1 (entget na))
    413.                                 );and
    414.                         (progn
    415.                                 (if (acet-insert-attrib-set na (car lst) nil)
    416.           (setq #bns_attin_modified (+ #bns_attin_modified 1)
    417.                                                 lst (cdr lst)
    418.           );setq
    419.           (acet-alert (strcat "\nNo matching attribute tags were found on that "
    420.                                                                                                 "block insert. \nTry another block insert."
    421.                                                                                         );strcat
    422.           );acet-alert
    423.                                 );if
    424.                         );progn then
    425.                         (setq lst (cdr lst));setq
    426.                 );if
    427.                 (acet-undo-end)
    428.         );while
    429. );defun bns_attin_interactive
    430. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    431. (defun bns_print_att_list ( lst / sp n a b j k)
    432.         (setq lst (cons (list "---" "-----") lst)
    433.                 lst (cons (list "TAG" "VALUE") lst)
    434.                 sp "    "
    435.                 sp (strcat sp sp sp sp sp sp sp sp)
    436.                 sp (strcat sp sp sp sp sp sp sp sp)
    437.                 j 0
    438.                 k 0
    439.                 n 0
    440.         );setq
    441.         (repeat (length lst)
    442.                 (setq a (nth n lst)
    443.                         b (cadr a)
    444.                         a (car a)
    445.                         j (max (strlen a) j)
    446.                         k (max (strlen b) k)
    447.                 );setq
    448.                 (setq n (+ n 1));setq
    449.         );repeat
    450.         (princ "\n")
    451.         (setq j (+ j 2)
    452.                 k (+ k 2)
    453.         );setq
    454.         (setq n 0)
    455.         (repeat (length lst)
    456.                 (setq a (nth n lst)
    457.                         b (cadr a)
    458.                         a (car a)
    459.                 );setq
    460.                 (if (not (equal b "<>"))
    461.                         (progn
    462.                                 (setq a (strcat a
    463.                                                                         (substr sp 1 (max 0 (- j (strlen a))))
    464.                                                                 );strcat
    465.                                         b (strcat b
    466.                                                         (substr sp 1 (max 0 (- k (strlen b))))
    467.                                                 );strcat
    468.                                         a (strcat "\n " a b)
    469.                                 );setq
    470.                                 (princ a)
    471.                         );progn then
    472.                 );if
    473.                 (setq n (+ n 1));setq
    474.         );repeat
    475.         n
    476. );defun bns_print_att_list
    477. ;;;ACET-GETFILE----------------------------------------------------------------------
    478. (defun acet-getfile (title file lst no. / drv)
    479.   (setq drv (atof (substr (getvar "acadver") 1 4)))
    480.   (if (>= drv 16.2)
    481.     (acet-ui-getfile title file lst "Acet:Att" no.)
    482.     (acet-ui-getfile title file lst no.)
    483.   )
    484. )
    485. (acet-autoload2        '("Yes_no.lsp"        (bns_get_yes_no lst size)))
    486. (princ)
    复制代码

     

     

     

     

    attout导出N多个属性块的排序规则优化
    哎...膜结构车棚,签到来了1...
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网_中国空间膜结构协会

    GMT+8, 2024-5-16 06:22 , Processed in 0.059448 second(s), 21 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表