使用autolisp

时间:2017-01-24 01:44:12

标签: lisp cell autocad autolisp

如果比较成功,我希望从存储在绘图表或表对象中的信息的比较中提取某些信息,如果比较成功则将相关值存储到变量中。我是Visual lisp或Auto Lisp的新手。那么请你帮我解决这个问题,并一步一步地解释我。

Example of table

例如,如果我的表位于第一列 D1 ,我想将信息存储在它旁边的下三列中,但是在同一行中。

enter image description here

因此,在此示例中, 132156 432 y 11 要存储在三个不同变量或数组中的数字。请帮助我并逐步解释我可能的解决方案,我是Lisp的新手

1 个答案:

答案 0 :(得分:1)

首先你需要得到桌子。您可以要求用户选择一个,例如:

(setq table (vlax-ename->vla-object (car (entsel ))) )

如果用户不想选择,您应该记住捕获错误。 此外,您应该检查用户是否选择表而不是其他一些enity。但现在让我们想象一下用户选择表格 所以现在你可以试试这个

(setq columns (vlax-get-property table 'Columns))
(setq rows (vlax-get-property table 'rows))

(setq row 1 )   ; 0 is header
(repeat rows
    (setq vals nil)
    (setq column 0)
    (setq txtval (vlax-invoke-method table 'GetText row column ))
        ; now we have value from first cell in row.
        ; and now You can go at least two ways. 
        ; 1 check value and make Your analyse, read values from other columns or anything You need
        ; 2 build array of all values from all cells and after that analyse only array of texts (remove dependency from object table)
        ; for this sample I choose 1 way.
    (if (= txtval "D1") (progn          
        (repeat 3 ; because You "want to store the information in the next three columns"
            (setq column (1+ column))
            (setq vals ( append vals (list (vlax-invoke-method table 'GetText row column ))))
        )
    ))
    (if (not (null vals )) (progn
        (setq arrayOfVals (append arrayOfVals (list vals)))
    ))
    (setq row (1+ row ))
)

(print arrayOfVals)