malkis 发表于 2022-7-5 17:54:35

初学者问题,显示/隐藏

你好论坛
我刚刚开始学习lisp,并在学习过程中创建了一些小程序。我有一些VBA和C++的基本知识,但我注意到lisp是一种完全不同的野兽。
目前,我正试图找出如何为一个布局创建一个脚本,其中包含几个块,这些块将根据设置的日期隐藏或可见。
我知道可以使用层、过滤器和层状态来执行其中的一些操作,但我想尝试一下。
 
我的想法是在每个blocks注释字段中输入一个from/to-date作为标志。
然后,我将让用户提供一个日期,让脚本在块之间循环,并将每个块放在显示/不显示中。
 
这是我到目前为止一直在想的,但我仍然没有找到隐藏/显示块的方法。
代码中也缺少一些布尔运算,但我可以自己输入。
非常感谢您的帮助
 
(defun C:cblk ( / blk check cmnt date_from date_to entity obj objid)
(vl-load-com)

(setq blk (tblnext "BLOCK" T))

;loop through the blocks
(while blk
(setq check (assoc 0 blk)

;read comment in block
cmnt (cdr(assoc 4 blk))
entity(cdr(assoc -2 blk))

;extract dates from block comment
date_from (substr cmnt 1 10)
date_to (substr cmnt 12 21)

;put vla-object in obj
obj (vlax-ename->vla-object entity)

; Line below is intended to hide/show the block but doesn't work
;(vla-put-Visible obj :vlax-false)
      
blk (tblnext "BLOCK")
) ;_ end setq
) ;_ end while

(princ)
);defun
(princ)

marko_ribar 发表于 2022-7-5 18:04:19

我们看不到您如何使用日期信息作为显示/隐藏操作的标志。。。示例DWG与2个这样的块将是很好的和解释ab使用日期信息。。。

malkis 发表于 2022-7-5 18:11:55

Oki。
 
日期在描述区域中设置:

 
 
运行脚本时,请尝试附加的dwg,并查看date\u from和date\u to变量。
块测试。图纸

marko_ribar 发表于 2022-7-5 18:14:02

如果date_from在两个街区内相同怎么办。。。第一个显示的是date_到更早的那个?您必须以某种方式对块进行排序。。。

marko_ribar 发表于 2022-7-5 18:24:18

如果我在最后一句话中是正确的,并且你们有支持ISOLATEOBJECTS命令的ACAD,也许像这样的东西可能就是答案。。。
 
(defun c:showblkbydate ( / remchar bl ss i )

(vl-load-com)

(defun remchar ( char str / strn ch )
   (setq strn "")
   (while (/= str "")
   (setq ch (substr str 1 1))
   (if (= ch char)
       (setq ch "")
   )
   (setq str (substr str 2))
   (setq strn (strcat strn ch))
   )
   strn
)

(vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
   (if
   (and
       (not (wcmatch (strcase (vla-get-name b)) "*MODEL*,*PAPER*"))
       (= (vla-get-isxref b) :vlax-false)
       (/= (vla-get-comments b) "")
   )
   (setq bl (cons (cons (vla-get-comments b) b) bl))
   )
)
(setq bl
   (vl-sort bl '(lambda ( a b )
   (if (= (atoi (remchar "-" (substr (car a) 1 10))) (atoi (remchar "-" (substr (car b) 1 10))))
       (< (atoi (remchar "-" (substr (car a) 12))) (atoi (remchar "-" (substr (car b) 12))))
       (< (atoi (remchar "-" (substr (car a) 1 10))) (atoi (remchar "-" (substr (car b) 1 10))))
   ))
   )
)
(if bl
   (foreach b bl
   (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 (vla-get-name (cdr b))))))
   (if ss
       (repeat (setq i (sslength ss))
         (prompt "\nENTER TO CONTINUE...")
         (command "_.ISOLATEOBJECTS" (ssname ss (setq i (1- i))) "")
         (while (progn (setq gr (grread nil)) (if (or (equal gr '(2 13)) (equal gr '(2 32))) (setq gr nil) t)))
         (command "_.UNISOLATEOBJECTS")
       )
   )
   )
)
(princ)
)
HTH,M.R。

ReMark 发表于 2022-7-5 18:26:00

修改块和更改文件日期时会发生什么情况?

malkis 发表于 2022-7-5 18:31:19

马尔科·里巴:好的。非常感谢。
看来我还有很多东西要学。
明天我回来工作的时候,我会看看你的剧本。
 
备注:没关系。我的目的是跟踪描述字段中的日期,因此如果您更新块并且不触摸描述,应该可以吗?
 
顺便问一下,你们能推荐一本好的LISP书吗?

BIGAL 发表于 2022-7-5 18:38:15

在我看来,最好将块层更改为关闭/打开,就像备注一样,你仍然有一个主控件,隐藏块意味着你看不到它,我可以看到复制块的一些问题,因为无法看到它已经存在。
 
如果你有kindle,我为VLisp买了4本书,每本大约8美元。Google lisp+David Stein。

malkis 发表于 2022-7-5 18:43:20

我一直在逐步阅读脚本,并试图理解它的内部工作原理(仍在早期)。
 
假设我们正在使用我先前附加的dwg。
我希望用户在脚本中输入日期,在本例中为2016-08-01。
这意味着“区块1”的日期范围设置为2016-01-01;2016年12月31日应可见。
“区块2”,其日期范围设置为2016-01-01;2016-06-31不应可见,因为2016-08-01不在其日期范围内。
希望这能更好地解释情况
 
我还想指出,这个脚本将在工厂布局中使用,在工厂布局中,我们只使用唯一的块,因此,如果重复出现问题,这不会是一个问题。

marko_ribar 发表于 2022-7-5 18:54:10

试试这个,也更新了我以前的代码。。。
 

(defun c:showblkbydate ( / remchar date bl ss i )

(vl-load-com)

(defun remchar ( char str / strn ch )
   (setq strn "")
   (while (/= str "")
   (setq ch (substr str 1 1))
   (if (= ch char)
       (setq ch "")
   )
   (setq str (substr str 2))
   (setq strn (strcat strn ch))
   )
   strn
)

(initget 1)
(setq date (getstring "\nSpecify range check date ex. \"2016-08-01\" : "))
(vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
   (if
   (and
       (not (wcmatch (strcase (vla-get-name b)) "*MODEL*,*PAPER*"))
       (= (vla-get-isxref b) :vlax-false)
       (/= (vla-get-comments b) "")
   )
   (setq bl (cons (cons (vla-get-comments b) b) bl))
   )
)
(setq bl
   (vl-sort bl '(lambda ( a b )
   (if (= (atoi (remchar "-" (substr (car a) 1 10))) (atoi (remchar "-" (substr (car b) 1 10))))
       (< (atoi (remchar "-" (substr (car a) 12))) (atoi (remchar "-" (substr (car b) 12))))
       (< (atoi (remchar "-" (substr (car a) 1 10))) (atoi (remchar "-" (substr (car b) 1 10))))
   ))
   )
)
(setq bl
   (vl-remove-if-not '(lambda ( x )
   (< (atoi (remchar "-" (substr (car x) 1 10))) (atoi (remchar "-" date)) (atoi (remchar "-" (substr (car x) 12))))
   )
   bl
   )
)
(if bl
   (foreach b bl
   (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 (vla-get-name (cdr b))))))
   (if ss
       (repeat (setq i (sslength ss))
         (prompt "\nENTER TO CONTINUE...")
         (command "_.ISOLATEOBJECTS" (ssname ss (setq i (1- i))) "")
         (while (progn (setq gr (grread nil)) (if (or (equal gr '(2 13)) (equal gr '(2 32))) (setq gr nil) t)))
         (command "_.UNISOLATEOBJECTS")
       )
   )
   )
)
(princ)
)

 
M、 R。
页: [1] 2
查看完整版本: 初学者问题,显示/隐藏