找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 434|回复: 5

[每日一码] 获取AUTOCAD表格单元格属性

[复制链接]

已领礼包: 40个

财富等级: 招财进宝

发表于 2021-1-16 19:27:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

  1. ; Get*  - (tableobj method) gets the property for the specified row
  2. ; Get*2 - (tableobj method) gets the property for the specified cell

  3. ; GetTextHeight Method (ActiveX) - Returns the text height for the specified row type.
  4. ; RetVal = object.GetTextHeight(rowType)

  5. ; GetTextHeight2 Method (ActiveX) - Gets the text height for a cell.
  6. ; RetVal = object.GetTextHeight2(nRow, nCol, nContent) ; VBA: RetVal = object.GetTextHeight2(strCellStyle)

  7. ; Extracting the properties from a picked table cell into assoc list.
  8. ; For easier understanding and table manipulation
  9. ; Usage: VLIDE's console -> (TableCell_ExtractProps) -> Inspect -> Pretty Print & Dig into the inspect window
  10. (defun TableCell_ExtractProps ( / _hit-test GetAcadTableObjects )
  11.   
  12.   (defun _hit-test ( pt lst ) ; Lee Mac
  13.     (if (and (vl-consp pt) (vl-every 'numberp pt))
  14.       (vl-some
  15.         (function
  16.           (lambda ( o / r c )
  17.             (if (eq :vlax-true (vla-HitTest o (vlax-3D-point (trans pt 1 0)) (vlax-3D-point (trans (getvar 'VIEWDIR) 1 0)) 'r 'c)) (list o r c) )
  18.           )
  19.         )
  20.         lst
  21.       )
  22.     )
  23.   ); defun _hit-test
  24.   
  25.   (defun GetAcadTableObjects ( / SS i o L )
  26.     (if (setq SS (ssget "X" '((0 . "ACAD_TABLE")))) (repeat (setq i (sslength SS)) (setq L (cons (setq o (vlax-ename->vla-object (ssname SS (setq i (1- i))))) L)) ))
  27.   )
  28.   
  29.   (
  30.     (lambda ( / RowEnums GridEnums CEMenums MARenums cell tblobj crow ccol r )
  31.       
  32.       ; I'll check on the "GetDataType" and "GetCellDataType" later
  33.       
  34.       ; NOTE: Excluded the methods that require this argument (Because I have no idea what is this)
  35.       ; But I guess that its the CellTextStyle's name [STR] argument, reading from the "GetTextHeight2 Method (ActiveX)" documentation
  36.       ; nContent
  37.       ; Access: Input-only
  38.       ; Type: Long
  39.       ; The content index in the table cell.
  40.       
  41.       
  42.       (setq RowEnums '(acDataRow acHeaderRow acTitleRow acUnknownRow)) ;  AcRowType enum
  43.       (setq GridEnums
  44.         '(
  45.           acHorzBottom      ; Top or bottom horizontal grid line, based on the flow direction.
  46.           acHorzInside      ; All horizontal grid lines, excluding the top and bottom lines.
  47.           acHorzTop         ; Top or bottom horizontal grid line, based on the flow direction.
  48.           acInvalidGridLine ; An invalid grid line.
  49.           acVertInside      ; All the vertical grid lines, excluding the farthest left and farthest right grid lines.
  50.           acVertLeft        ; Farthest left grid line.
  51.           acVertRight       ; Farthest right grid line.
  52.         )
  53.       ); setq GridEnums
  54.       
  55.       (setq CEMenums ; Type: AcCellEdgeMask enum
  56.         '(
  57.           acBottomMask ; Bottom edge index of the cell.
  58.           acLeftMask   ; Left edge index of the cell.
  59.           acRightMask  ; Right edge index of the cell.
  60.           acTopMask    ; Top edge index of the cell.
  61.         )
  62.       ); setq CEMenums
  63.       
  64.       (setq MARenums ; AcCellMargin enum
  65.         '(
  66.           acCellMarginBottom
  67.           acCellMarginHorzSpacing
  68.           acCellMarginLeft
  69.           acCellMarginRight
  70.           acCellMarginTop
  71.           acCellMarginVertSpacing
  72.         )
  73.       ); setq MARenums
  74.       
  75.       (and
  76.         (setq cell (_hit-test (getpoint "\nPick table cell: ") (GetAcadTableObjects))) ; returns smth like: (#<VLA-OBJECT IAcadTable 000000a23c0b7e48> 2 0)
  77.         (mapcar 'set '(tblobj crow ccol) cell)
  78.         (setq r
  79.           (append
  80.             
  81.             
  82.             ; GetAlignment (1)
  83.             ; GetBackgroundColor (1)
  84.             ; GetBackgroundColorNone (1)
  85.             ; GetBreakHeight (1)
  86.             ; GetColumnName (1)
  87.             ; GetColumnWidth (1)
  88.             ; GetContentColor (1)
  89.             ; GetFormat (1)
  90.             ; GetMinimumColumnWidth (1)
  91.             ; GetMinimumRowHeight (1)
  92.             ; GetRowHeight (1)
  93.             ; GetRowType (1)
  94.             ; GetTextHeight (1)
  95.             ; GetTextStyle (1)            
  96.             (mapcar
  97.               (function
  98.                 (lambda (mtd)
  99.                   (cons mtd
  100.                     (mapcar
  101.                       (function
  102.                         (lambda (enum / tmp)
  103.                           (if (not (vl-catch-all-error-p (setq tmp (vl-catch-all-apply 'vlax-invoke-method (list tblobj mtd (eval enum))))))
  104.                             (cons enum tmp)
  105.                             (cons enum (strcat "Error: " (vl-catch-all-error-message tmp)))
  106.                           ); if
  107.                         ); lambda (enum)
  108.                       ); function
  109.                       RowEnums
  110.                     ); mapcar
  111.                   ); list
  112.                 ); lambda (mtd)
  113.               ); function
  114.               '(GetAlignment
  115.                 GetBackgroundColor
  116.                 GetBackgroundColorNone
  117.                 GetContentColor
  118.                 GetFormat
  119.                 GetTextHeight
  120.                 GetTextStyle
  121.               ); list
  122.             ); mapcar
  123.             (mapcar
  124.               (function
  125.                 (lambda (mtd / tmp)
  126.                   (if (not (vl-catch-all-error-p (setq tmp (vl-catch-all-apply 'vlax-invoke-method (list tblobj mtd ccol)))))
  127.                     (cons mtd tmp)
  128.                     (cons mtd (strcat "Error: " (vl-catch-all-error-message tmp)))
  129.                   ); if
  130.                 ); lambda
  131.               ); function
  132.               '(GetColumnName
  133.                 GetColumnWidth
  134.                 GetMinimumColumnWidth
  135.               ); list
  136.             ); mapcar
  137.             (mapcar
  138.               (function
  139.                 (lambda (mtd / tmp)
  140.                   (if (not (vl-catch-all-error-p (setq tmp (vl-catch-all-apply 'vlax-invoke-method (list tblobj mtd crow)))))
  141.                     (cons mtd tmp)
  142.                     (cons mtd (strcat "Error: " (vl-catch-all-error-message tmp)))
  143.                   ); if
  144.                 ); lambda
  145.               ); function
  146.               '(GetRowType
  147.                 GetRowHeight
  148.                 GetMinimumRowHeight
  149.               ); list
  150.             ); mapcar
  151.             
  152.             
  153.             ; GetAttachmentPoint (2)
  154.             ; GetAutoScale (2)
  155.             ; GetBlockRotation (2)
  156.             ; GetBlockScale (2)
  157.             ; GetBlockTableRecordId (2)
  158.             ; GetCellAlignment (2)
  159.             ; GetCellBackgroundColor (2)
  160.             ; GetCellBackgroundColorNone (2)
  161.             ; GetCellContentColor (2)
  162.             ; GetCellFormat (2)
  163.             ; GetCellState (2)
  164.             ; GetCellStyle (2)
  165.             ; GetCellStyleOverrides (2)
  166.             ; GetCellTextHeight (2)
  167.             ; GetCellTextStyle (2)
  168.             ; GetCellType (2)
  169.             ; GetCellValue (2)
  170.             ; GetContentLayout (2)
  171.             ; GetContentType (2)
  172.             ; GetFieldId (2)
  173.             ; GetGridColor (2)
  174.             ; GetGridLineWeight (2)
  175.             ; GetGridVisibility (2)
  176.             ; GetText (2)
  177.             ; GetTextRotation (2)
  178.             ; IsContentEditable (2)
  179.             ; IsEmpty (2)
  180.             ; IsFormatEditable (2)
  181.             ; IsMergeAllEnabled (2)
  182.             (mapcar
  183.               (function
  184.                 (lambda (mtd / tmp)
  185.                   (if (not (vl-catch-all-error-p (setq tmp (vl-catch-all-apply 'vlax-invoke-method (append (list tblobj mtd) (cdr cell))))))
  186.                     (cons mtd tmp)
  187.                     (cons mtd (strcat "Error: " (vl-catch-all-error-message tmp)))
  188.                   ); if
  189.                 ); lambda
  190.               ); function
  191.               '(GetAttachmentPoint
  192.                 GetAutoScale
  193.                 GetBlockRotation
  194.                 GetBlockScale
  195.                 GetBlockTableRecordId
  196.                 GetCellAlignment
  197.                 GetCellBackgroundColor
  198.                 GetCellBackgroundColorNone
  199.                 GetCellContentColor
  200.                 GetCellFormat
  201.                 GetCellState
  202.                 GetCellStyle
  203.                 GetCellStyleOverrides
  204.                 GetCellTextHeight
  205.                 GetCellTextStyle
  206.                 GetCellType
  207.                 GetCellValue
  208.                 GetContentLayout
  209.                 GetContentType
  210.                 GetFieldId
  211.                 GetText
  212.                 GetTextRotation
  213.                 IsContentEditable
  214.                 IsEmpty
  215.                 IsFormatEditable
  216.                 IsMergeAllEnabled
  217.               ); list
  218.             ); mapcar
  219.             
  220.             (mapcar
  221.               (function
  222.                 (lambda (mtd)
  223.                   (cons mtd
  224.                     (mapcar
  225.                       (function
  226.                         (lambda (enum)
  227.                           (cons enum
  228.                             (mapcar
  229.                               (function
  230.                                 (lambda ( genum / tmp ) ; object.Method(gridLineType, rowType)
  231.                                   (if (not (vl-catch-all-error-p (setq tmp (vl-catch-all-apply 'vlax-invoke-method (list tblobj mtd (eval genum) (eval enum))))))
  232.                                     (list genum tmp)
  233.                                     (list genum (strcat "Error: " (vl-catch-all-error-message tmp)))
  234.                                   ); if
  235.                                 ); lambda ( genum )
  236.                               ); function
  237.                               GridEnums
  238.                             ); mapcar
  239.                           ); cons
  240.                         ); lambda (enum)
  241.                       ); function
  242.                       RowEnums ; GridEnums
  243.                     ); mapcar
  244.                   ); list
  245.                 ); lambda (mtd)
  246.               ); function
  247.               '(GetGridColor
  248.                 GetGridLineWeight
  249.                 GetGridVisibility
  250.               ); list
  251.             ); mapcar
  252.             
  253.             
  254.             ; GetAutoScale2 (3)
  255.             ; GetBlockAttributeValue (3) ; RetVal = object.GetBlockAttributeValue(row, col, attdefId) ; - I do this, but not in this code, hehe
  256.             ; GetBlockTableRecordId2 (3)
  257.             ; GetCellExtents (3)
  258.             ; GetCellGridColor (3)
  259.             ; GetCellGridLineWeight (3)
  260.             ; GetCellGridVisibility (3)
  261.             ; GetContentColor2 (3)
  262.             ; GetDataFormat (3)
  263.             ; GetDataType (3) ; EXCLUDED!!!
  264.             ; GetFieldId2 (3)
  265.             ; GetFormula (3)
  266.             ; GetGridColor2 (3)
  267.             ; GetGridDoubleLineSpacing (3)
  268.             ; GetGridLineStyle (3)
  269.             ; GetGridLinetype (3)
  270.             ; GetGridLineWeight2 (3)
  271.             ; GetGridVisibility2 (3)
  272.             ; GetHasFormula (3)
  273.             ; GetMargin (3)
  274.             ; GetOverride (3)
  275.             ; GetRotation (3)
  276.             ; GetScale (3)
  277.             ; GetTextHeight2 (3)
  278.             ; GetTextString (3)
  279.             ; GetTextStyle2 (3)
  280.             ; GetValue (3)
  281.             (list
  282.               (cons 'GetCellExtents
  283.                 (mapcar
  284.                   (function
  285.                     (lambda (b / tmp)
  286.                       (if (not (vl-catch-all-error-p (setq tmp (vl-catch-all-apply 'vlax-invoke-method (append (list tblobj 'GetCellExtents) (cdr cell) (list b))))))
  287.                         (cons b tmp)
  288.                         (cons b (strcat "Error: " (vl-catch-all-error-message tmp)))
  289.                       ); if
  290.                     ); lambda
  291.                   ); function
  292.                   '(:vlax-true :vlax-false) ; bOuterCell
  293.                 ); mapcar
  294.               ); cons
  295.             ); list
  296.             
  297.             (mapcar
  298.               (function
  299.                 (lambda (mtd)
  300.                   (cons mtd
  301.                     (mapcar
  302.                       (function
  303.                         (lambda (enum / tmp ) ; object.Method(row, col, edge)
  304.                           (if (not (vl-catch-all-error-p (setq tmp (vl-catch-all-apply 'vlax-invoke-method (append (list tblobj mtd) (cdr cell) (list (eval enum)))))))
  305.                             (cons enum tmp)
  306.                             (cons enum (strcat "Error: " (vl-catch-all-error-message tmp)))
  307.                           ); if
  308.                         ); lambda (enum)
  309.                       ); function
  310.                       CEMenums
  311.                     ); mapcar
  312.                   ); list
  313.                 ); lambda (mtd)
  314.               ); function
  315.               '(GetCellGridColor
  316.                 GetCellGridLineWeight
  317.                 GetCellGridVisibility
  318.               ); list
  319.             ); mapcar
  320.             
  321.             (mapcar
  322.               (function
  323.                 (lambda (mtd)
  324.                   (cons mtd
  325.                     (mapcar
  326.                       (function
  327.                         (lambda (enum / tmp ) ; object.Method(nRow, nCol, nGridLineType)
  328.                           (if (not (vl-catch-all-error-p (setq tmp (vl-catch-all-apply 'vlax-invoke-method (append (list tblobj mtd) (cdr cell) (list (eval enum)))))))
  329.                             (cons enum tmp)
  330.                             (cons enum (strcat "Error: " (vl-catch-all-error-message tmp)))
  331.                           ); if
  332.                         ); lambda (enum)
  333.                       ); function
  334.                       GridEnums
  335.                     ); mapcar
  336.                   ); list
  337.                 ); lambda (mtd)
  338.               ); function
  339.               '(GetGridColor2
  340.                 GetGridDoubleLineSpacing
  341.                 GetGridLineStyle
  342.                 GetGridLinetype
  343.                 GetGridLineWeight2
  344.                 GetGridVisibility2
  345.               ); list
  346.             ); mapcar
  347.             
  348.             (list
  349.               (cons 'GetMargin
  350.                 (mapcar
  351.                   (function
  352.                     (lambda (enum / tmp ) ; object.GetMargin(nRow, nCol, nMargin)
  353.                       (if (not (vl-catch-all-error-p (setq tmp (vl-catch-all-apply 'vlax-invoke-method (append (list tblobj 'GetMargin) (cdr cell) (list (eval enum)))))))
  354.                         (cons enum tmp)
  355.                         (cons enum (strcat "Error: " (vl-catch-all-error-message tmp)))
  356.                       ); if
  357.                     ); lambda (enum)
  358.                   ); function
  359.                   MARenums
  360.                 ); mapcar
  361.               ); cons
  362.             ); list
  363.             
  364.             ; GetBlockAttributeValue2 (4) ; RetVal = object.GetBlockAttributeValue2(nRow, nCol, nContent, blkId) ; - I do this, but not in this code, hehe
  365.             ; GetCellDataType (4)
  366.             ; GetCustomData (4)
  367.             ; GetSubSelection (4)
  368.             ; HitTest (4)
  369.             ; MergeCells (4)
  370.             ; MoveContent (4)
  371.             ; SetAutoScale2 (4)
  372.             ; SetBlockAttributeValue (4)
  373.             ; SetBlockTableRecordId (4)
  374.             ; SetCellDataType (4)
  375.             ; SetCellGridColor (4)
  376.             ; SetCellGridLineWeight (4)
  377.             ; SetCellGridVisibility (4)
  378.             ; SetCellValueFromText (4)
  379.             ; SetContentColor2 (4)
  380.             ; SetCustomData (4)
  381.             ; SetDataFormat (4)
  382.             ; SetFormula (4)
  383.             ; SetGridColor2 (4)
  384.             ; SetGridDoubleLineSpacing (4)
  385.             ; SetGridLineStyle (4)
  386.             ; SetGridLinetype (4)
  387.             ; SetGridLineWeight2 (4)
  388.             ; SetGridVisibility2 (4)
  389.             ; SetMargin (4)
  390.             ; SetOverride (4)
  391.             ; SetRotation (4)
  392.             ; SetScale (4)
  393.             ; SetSubSelection (4)
  394.             ; SetTextHeight2 (4)
  395.             ; SetTextString (4)
  396.             ; SetTextStyle2 (4)
  397.             ; SetValue (4)
  398.             ; UnmergeCells (4)
  399.             
  400.             ; Looks like the 4-argument requiring methods, only apply values (there are few that obtain 'things', but ATM I excluded them)
  401.             
  402.           ); append
  403.         ); setq r
  404.         
  405.       ); and
  406.       r
  407.     ); lambda
  408.   )

  409. ); defun TableCell_ExtractProps
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 418个

财富等级: 日进斗金

发表于 2021-1-16 20:09:43 | 显示全部楼层
N版出手,必定不凡。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 604个

财富等级: 财运亨通

发表于 2021-1-16 20:55:50 | 显示全部楼层
这个与版本有关,05是起步
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 418个

财富等级: 日进斗金

发表于 2021-1-16 21:31:09 | 显示全部楼层
VLISP关于Table的程序介绍相对较少,希望看到N版此类的程序。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 6202个

财富等级: 富甲天下

发表于 2021-1-17 08:57:52 | 显示全部楼层
谢谢楼主的分享,楼主辛苦了
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 3904个

财富等级: 富可敌国

发表于 2021-1-17 09:08:35 | 显示全部楼层

谢谢楼主的分享
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-4-20 06:14 , Processed in 0.275744 second(s), 38 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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