manddarran 发表于 2022-7-6 11:21:21

用于编辑的自动DCL创建者

我发现这个lisp非常好用,除了我们的一些属性中有引号。
 
这是代码,我已经附上了dwg和jpg的我所说的错误。
 
;;;DCLATT.LSP
;This program is for demonstration and tutorial purposes only.

;This program, using Visual Lisp will extract attributes from
;a block and display them in a dialog box.
;The dialog box will be created "on the fly" with the relevant
;number of edit boxes ;to suit the number of attributes within
;the block.
;The new attribute data will then be retrieved from the dialog
;and the block updated.
;Written by Kenny Ramage - May 2002
;afralisp@mweb.com.na
;http://www.afralisp.com

;Usage :
;Load by typing (load "DCLATT") at the command prompt.
;Type DCLATT at the command prompt to run.
;Select any block containing attributes.
;Replace any of the values in the text boxes to updated
;the attributes.

;Dependencies : None that I know of.
;Not much in the way of error checking I'm afraid.

;Limitations : Will only edit a certain number of attributes.
;System dependent.
;I don't recommend more than 10.
;I've had up to 14 on my display.


(prompt "\nType DCLATT to run.....")
(defun c:dclatt ( / theblock thelist n taglist
txtlist lg fname fn nu dcl_id l relist)
;load the visual lisp extensions
(vl-load-com)
;get the entity and entity name
(setq theblock (car (entsel)))
;convert to vl object
(setq theblock (vlax-ename->vla-object theblock))
;check if it's a block
(if (= (vlax-get-property theblock 'ObjectName)
"AcDbBlockReference")
;if it is, do the following
(progn
;check if it has attributes
(if (= (vlax-get-property theblock
'HasAttributes) :vlax-true)
;if it has attributes, do the following
(progn
;get the attributes
(getatt theblock)
;create the dialog
(create_dialog)
;run the dialog
(run_the_dialog)
;update the attributes
(upatt)
);progn
;No attributes, inform the user
(alert "This Block has No Attributes!!
- Please try again.")
);if
);progn
;it's not a block, inform the user
(alert "This is not a Block!! - Please try again.")
);if
(princ)
);defun

(defun getatt (enam)
;retrieve the attributes
(setq thelist (vlax-safearray->list
(variant-value
(vla-getattributes enam))))
;process each attribute
(foreach n thelist
;get the tag attribute data
(setq taglist (cons (vla-get-tagString n) taglist)
;get the text attribute data
txtlist (cons (vla-get-textString n) txtlist)
;how many attributes?
lg (length taglist)
);setq
);foreach
;reverse the lists
(setq taglist (reverse taglist)
txtlist (reverse txtlist))
);defun

(defun create_dialog ()
;create a temp DCL file
(setq fname (vl-filename-mktemp "dcl.dcl"))
;open it to write
(setq fn (open fname "w"))
;write the dialog header coding
(write-line "temp : dialog { label = \"Edit Attributes\";" fn)
;reset the incremental control number
(setq nu 0)
;start the loop to create the edit boxes
(repeat lg
;create the edit boxes
(write-line ": edit_box {" fn)
(setq l (strcat "\"" "eb" (itoa nu) "\"" ";"))
(write-line (strcat "key = " l) fn)
(setq l (nth nu taglist))
(write-line (strcat "label = " "\"" l "\"" ";") fn)
(setq l (nth nu txtlist))
(write-line (strcat "value = " "\"" l "\"" ";") fn)
(write-line "alignment = centered; edit_width = 20; }" fn)
;increment the counter
(setq nu (1+ nu))
);repeat
;ok and cancel button
(write-line "ok_only; }" fn)
;close the temp DCL file
(close fn)
);defun

(defun run_the_dialog ()
;load the dialog file and definition
(setq dcl_id (load_dialog fname))
(if (not (new_dialog "temp" dcl_id))
(exit )
);if
(mode_tile "eb0" 2)
;if the OK button is selected
(action_tile "accept" "(retatt)")
;start the dialog
(start_dialog)
;unload the dialog
(unload_dialog dcl_id)
;delete the temp DCL file
(vl-file-delete fname)
);defun

(defun retatt ()
;reset the increment counter
(setq nu 0)
start the loop
(repeat lg
;retrieve the tile value
(setq l (get_tile (strcat "eb" (itoa nu))))
;add it to the list
(setq relist (cons l relist))
;increment the counter
(setq nu (1+ nu))
);repeat
(setq relist (reverse relist))
;close the dialog
(done_dialog)
);defun

(defun upatt ()
;reset the increment counter
(setq nu 0)
;start the loop
(repeat lg
;update the attribute
(vla-put-textstring (nth nu thelist) (nth nu relist))
;increment the counter
(setq nu (1+ nu))
);repeat
;update the block
(vla-update theblock)
);defun

;clean loading
(princ)

;End of ATTDCL.LSP


TTL2.DWG

dclatt。lsp

Lee Mac 发表于 2022-7-6 11:25:35

为什么不双击属性块?还是这个Lisp程序在做什么?
 
此外,如果有帮助的话,我不久前写了这篇文章:
ddatte2.lsp

manddarran 发表于 2022-7-6 11:31:05

是的,这很管用,但这让它变得更简单、更干净。会给你一个旋转。

manddarran 发表于 2022-7-6 11:32:57

完美的谢谢。

Lee Mac 发表于 2022-7-6 11:36:10

不客气。

alanjt 发表于 2022-7-6 11:40:11

那普通的旧AttEdit(或ATE)呢?
 
此外,如果按住control键并双击属性(在较新版本中),它将打开一行在位属性编辑器。

Lee Mac 发表于 2022-7-6 11:44:22

更简洁一点:
 

;; QuickEdit~Lee Mac~20.04.10
(defun c:qe (/ e dc el c v )
(while (and (setq e (car (nentsel))) (<= 0 (setq dc (load_dialog "ACAD"))))
   (if (and (wcmatch (cdr (assoc 0 (setq el (entget e)))) "TEXT,ATTRIB")
            (setq v(cdr (assoc 1 el)) c v) (new_dialog "acad_txtedit" dc))
   (progn
       (set_tile "text_edit" v)
       (action_tile "text_edit" "(setq v $value)")
       (action_tile "cancel"    "(setq v c)")
       (start_dialog)
       (entupd (cdr (assoc -1 (entmod (subst (cons 1 v) (assoc 1 el) el)))))))
   (unload_dialog dc))
(princ))

Lee Mac 发表于 2022-7-6 11:49:18

好悲痛。#$%#@%#$%的不同之处在于,相同的命令。。。。。
 
Thx Lee成功了。几个月来,我一直在断断续续地处理这个问题。我试过^c^c\u atte,也试过^c^c\u ddatte。

manddarran 发表于 2022-7-6 11:51:16

在向下拉菜单、双击操作等添加选项时,为了避免任何可能的问题,请始终使用命令名而不是命令别名。

Lee Mac 发表于 2022-7-6 11:56:27

是的。只是要确定哪一个是别名。
页: [1] 2
查看完整版本: 用于编辑的自动DCL创建者