woodman78 发表于 2022-7-5 19:50:50

绘图图例例程

大家好,
我正在创建一个例程,该例程将检查图形中的某些层,如果它们存在,则将相应的块添加到图形中。这些对应的块是图形的图例项。请参阅所附图片。
 
我有这个代码,我在这个网站上找到,并修改为插入一个特定的块,如果一个特定的层存在。我可以将所有图层添加到我要检查的层列表中,但如何将相应的块名列表添加到图形中?
 
如果能帮上忙,我将不胜感激。谢谢
(defun c:LegendBatch (/ laylist)

(setq laylist '("CCC_LAYOUT_PROPOSED_Carriageway_Hatch" ))

;(command "_.LAYER" "_Unlock" "0" "_ON" "0" "_Thaw" "0" "_Set" "0")
(foreach l laylist
   (if (tblsearch "LAYER" l)
                        (if (setq pt (setq INPT (getpoint "\nPick Insertion Point: ")))
                (command "_.-insert" "Proposed Footpath" INPT "1" "1" "0")))   
;(command "_Unlock" l "_Thaw" l "_On" l)
       (princ)))
(command "")

(prin1))
 

woodman78 发表于 2022-7-5 20:00:38

我试着这样做,但有些事情不对劲:
(defun c:LegendBatch (/ laylist INPT block)

(setq laylist '("CCC_LAYOUT_PROPOSED_Carriageway_Hatch" "CCC_LAYOUT_PROPOSED_Tactile_Paving_Yellow_Hex_Hatch"))

(foreach l laylist
(cond       ((= l "CCC_LAYOUT_PROPOSED_Carriageway_Hatch")(= block "Proposed Footpath"))
        ((= l "CCC_LAYOUT_PROPOSED_Tactile_Paving_Yellow_Hex_Hatch")(= block "Proposed Tactile Paving (Yellow)"))
)
   (if (tblsearch "LAYER" l)
                        (if (setq pt (setq INPT (getpoint "\nPick Insertion Point: ")))
                (command "_.-insert" block INPT "1" "1" "0")))   
       (princ)))
(command "")
(prin1))
 
我想说的是,如果l是A层,那么将块A添加到图形中,如果l是B层,那么将块B添加到图形中。我现在设置它的方式无法工作,因为它将在添加块之前循环所有层。

woodman78 发表于 2022-7-5 20:03:16

这是我最近的一次尝试,但似乎也不起作用。
 
(defun c:LegendBatch (/ INPT)

;******************************************************************
(if (not (tblsearch "LAYER" "CCC_LAYOUT_PROPOSED_Carriageway_Hatch"))
(setq INPT (getpoint "\nPick Insertion Point: "))
                   (command "_.-insert" "Proposed Footpath" INPT "1" "1" "0"))
;******************************************************************
(if (not (tblsearch "LAYER" "CCC_LAYOUT_PROPOSED_Tactile_Paving_Yellow_Hex_Hatch"))
(setq INPT (getpoint "\nPick Insertion Point: "))
        (command "_.-insert" "Proposed Tactile Paving (Yellow)" INPT "1" "1" "0"))
;******************************************************************
       (princ))

 
谁能指出我哪里出了错?我更喜欢使用laylist方法,因为它可能更有效。

Tharwat 发表于 2022-7-5 20:09:30

 
您需要先了解IF函数。

woodman78 发表于 2022-7-5 20:17:21

谢谢塔瓦。
 
我按照建议查看了链接。
 
我已将代码修改为:
(defun c:LegendBatch (/ laylist b l)

(setq laylist '("CCC_LAYOUT_PROPOSED_Carriageway_Hatch" "CCC_LAYOUT_PROPOSED_Tactile_Paving_Yellow_Hex_Hatch"))

(foreach l laylist
   (if (tblsearch "LAYER" l)
        (if (= l "CCC_LAYOUT_PROPOSED_Carriageway_Hatch" (= b "Proposed Footpath")))
        (if (= l "CCC_LAYOUT_PROPOSED_Tactile_Paving_Yellow_Hex_Hatch" (= b "Proposed Tactile Paving (Yellow)")))
                        (if (setq pt (setq INPT (getpoint "\nPick Insertion Point: ")))
                (command "_.-insert" b INPT "1" "1" "0")))   
       (princ)))
(command "")

(prin1))
 
它插入第一个块,但不插入第二个块。我错过了什么?

Tharwat 发表于 2022-7-5 20:23:31

 
IF函数仍然有很多错误
 
仔细看看下面的写作方法。[未经测试]
 
您可以向列表中添加图层名和块名的组合,就像我在下面的示例中所做的那样。
 
试试看,让我知道。
 


(setq laylist '(("CCC_LAYOUT_PROPOSED_Carriageway_Hatch"
                "Proposed Footpath"
               )
               ("CCC_LAYOUT_PROPOSED_Tactile_Paving_Yellow_Hex_Hatch"
                "Proposed Tactile Paving (Yellow)"
               )
            )
)
(foreach l laylist
(if (and (tblsearch "LAYER" (car l))
          (tblsearch "BLOCK" (cadr l))
   )
   (command "_.-INSERT" (cadr l) "\\" "1" "1" "0")
)
)



woodman78 发表于 2022-7-5 20:28:50

塔尔瓦特,
 
这非常有效,唯一的例外是它只插入图形中已经存在的块。如何绕过
并迫使其从支撑路径位置插入块?
 
谢谢

Tharwat 发表于 2022-7-5 20:36:51

很好,
 
是的,当然可能,这样试试。
 
6

woodman78 发表于 2022-7-5 20:39:54

谢谢塔瓦。这实现了一个梦想。

Tharwat 发表于 2022-7-5 20:47:21

 
太好了,非常欢迎你。
页: [1] 2
查看完整版本: 绘图图例例程