带循环和/
希望我能很好地解释这一点,我已经在这几个星期了。我为块属性创建了一个自动编号lisp例程,该例程具有起始值、增量、正向或反向插入顺序,因此我可以使用特定方案对块进行自动编号。我从事布线和电气系统的工作。我现在的问题是,我为需要自动编号的设备创建了新的块,但它们需要类似于X3-1的方案,其中X3是别名,-1是导线位置。我可以在导线位置上有#1-24,然后下一个块需要从X4-1开始,再次通过24。我如何向lisp中添加循环和范围来实现这一点,或者有人有其他想法吗?我们使用数百种设备,所以像我这样用手数数是不现实的。如有任何意见,我们将不胜感激。谢谢 欢迎来到CADTutor niccoleleaf我的增量编号套件对你有帮助吗? 李,谢谢你的回复,顺便说一句,我是一个超级粉丝。我确实试过了,但不幸的是,它不允许我编辑现有属性,也不允许我创建范围。让我举一个我想做的事情的例子,见附件。想象一下顶部的区块,有23个,编号为C3-1到C3-24,然后下面是另一组区块,需要编号为C4-1到C4-24。该块包含属性/块,其中已包含C3-1编号,但可以编辑,因此我无法放置文本,我需要能够根据插入顺序编辑属性和编号。指块顶部的白色文本。希望这有帮助。
非常感谢niccoleleaf,我很高兴你是我作品的粉丝!
我的增量编号套件程序确实提供了一个替换选项,可以在文本放置期间通过在命令行上按“R”来访问;尽管这样做不合适,但该任务可能需要专用的自定义程序。 我又玩了一些,我明白你的意思,但是,我需要在以后的修订中对它们进行批量编辑的能力,以相同的格式对所有块重新编号,而不是在插入时进行。你怎么认为? 这就是我目前用来对其他属性之一进行编号的方法,我可以放入前缀加-001,它根据插入顺序或反向插入顺序无限编号。我的最终目标是复制和修改它,使另一个例程中包含范围/循环功能,这样我就可以运行命令,选择属性,并根据我的要求生成质量数。
(defun C:ATTINC()
;;;--- Get an attributes value
(defun getAttData(en / enlist blkType group66 attData)
;;;--- Get the DXF group codes of the entity
(setq enlist(entget en))
(setq attData (list))
;;;--- Check to see if the block's attribute flag is there
(if(cdr(assoc 66 enlist))
(progn
;;;--- Get the entity name
(setq en(entnext en))
;;;--- Get the entity dxf group codes
(setq enlist(entget en))
;;;--- Get the type of block
(setq blkType (cdr(assoc 0 enlist)))
;;;--- If group 66 then there are attributes nested inside this block
(setq group66(cdr(assoc 66 enlist)))
;;;--- Loop while the type is an attribute or a nested attribute exist
(while(or (= blkType "ATTRIB")(= group66 1))
;;;--- Get the block type
(setq blkType (cdr(assoc 0 enlist)))
;;;--- Check to see if this is an attribute
(if(= blkType "ATTRIB")
;;;--- Save the tag of the attribute
(setq attData(append attData(list (cdr(assoc 2 enlist)))))
)
;;;--- Get the next sub-entity
(setq en(entnext en))
;;;--- Get the dxf group codes of the next sub-entity
(setq enlist(entget en))
;;;--- Get the block type of the next sub-entity
(setq blkType (cdr(assoc 0 enlist)))
;;;--- See if the dxf group code 66 exist.if so, there are more nested attributes
(setq group66(cdr(assoc 66 enlist)))
)
)
)
attData
)
;;;--- Get an attributes value
(defun replaceAtt(en tagName str / enlist blkType group66)
;;;--- Get the DXF group codes of the entity
(setq enlist(entget en))
;;;--- Check to see if the block's attribute flag is there
(if(cdr(assoc 66 enlist))
(progn
;;;--- Get the entity name
(setq en(entnext en))
;;;--- Get the entity dxf group codes
(setq enlist(entget en))
;;;--- Get the type of block
(setq blkType (cdr(assoc 0 enlist)))
;;;--- If group 66 then there are attributes nested inside this block
(setq group66(cdr(assoc 66 enlist)))
;;;--- Loop while the type is an attribute or a nested attribute exist
(while(or (= blkType "ATTRIB")(= group66 1))
;;;--- Get the block type
(setq blkType (cdr(assoc 0 enlist)))
;;;--- Check to see if this is an attribute
(if(= blkType "ATTRIB")
;;;--- If the attribute value matches....
(if(= tagName (cdr(assoc 2 enlist)))
(progn
;;;--- Substitute the dxf group codes
(setq enlist(subst (cons 1 str)(assoc 1 enlist)enlist))
(entmod enlist)
(entupd en)
)
)
)
;;;--- Get the next sub-entity
(setq en(entnext en))
;;;--- Get the dxf group codes of the next sub-entity
(setq enlist(entget en))
;;;--- Get the block type of the next sub-entity
(setq blkType (cdr(assoc 0 enlist)))
;;;--- See if the dxf group code 66 exist.if so, there are more nested attributes
(setq group66(cdr(assoc 66 enlist)))
)
)
)
)
;;;--- Function to save the dialog box settings
(defun saveVars(/ index retList readlist count item)
;;;--- Save the input from the SELECTPLOTTER.dcl file
(setq retList(list))
(setq readlist(get_tile "attdata"))
(setq count 1)
(while (setq item (read readlist))
(setq retlist(append retList (list (nth item attData))))
(while (and (/= " " (substr readlist count 1))
(/= "" (substr readlist count 1)))
(setq count (1+ count))
)
(setq readlist (substr readlist count))
)
(if(= retList nil)
(setq tagName nil)
(setq tagName (car retList))
)
(setq str(get_tile "startstr"))
(setq inc(atoi(get_tile "increment")))
(setq order1(atoi(get_tile "order1")))
(setq order2(atoi(get_tile "order2")))
)
;;;--- Function to increment a string
;;; str = a string
;;; inc = an integer
;;;
;;; Examples (incStr "A100") would return "A101" if inc is set to 1
;;; (incStr "A01")would return "A11"if inc is set to 10
(defun incStr(str inc)
;;;--- Set up some variable defaults
(setq strPart "" numPart "" chkStr str flag T)
;;;--- While there are characters left in the string to check
(while(/= chkStr "")
;;;--- Get the last character in the string
(setq ch(substr chkStr (strlen chkStr)))
;;;--- If the flag is clear continue on...
(if(= flag T)
(progn
;;;--- If the character to check matches a numerical string value....
(if(member ch (list "1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "."))
;;;--- Add the numerical string value to the number portion
(setq numPart(strcat ch numPart))
;;;--- Else set the flag to nil because the rest of the string is letters
(setq flag nil strPart chkStr)
)
)
)
;;;--- Drop the last character off the string
(setq chkStr(substr chkStr 1 (- (strlen chkStr) 1)))
)
;;;--- See how many characters make up the numerical string portion
(setq numLen(strlen numPart))
;;;--- Convert the numerical to a string, add the increment, and convert back to a string
(setq numStr (itoa(+ (atoi numPart) inc)))
;;;--- If the converted string is less characters than the original, prefix with zeros
(while(< (strlen numStr) numLen)
(setq numStr(strcat "0" numStr))
)
;;;--- Put the string back together
(setq str(strcat strPart numStr))
)
;;;--- Main application
;;;--- Let the user select the block
(if(setq ent(entsel "\n Select Block: "))
(progn
;;;--- Get the entity name from the entity selection
(setq en(car ent))
;;;--- Get the dxf group codes of the entity
(setq enlist(entget en))
;;;--- Make sure this is a block entity
(if(= "INSERT" (cdr(assoc 0 enlist)))
(progn
;;;--- Get the name of the block
(setq blkName(cdr(assoc 2 enlist)))
;;;--- If attribute information is found in the block
(if(setq attData(getAttData en))
(progn
;;;--- Put up the dialog box
(setq dcl_id (load_dialog "ATTINC.dcl"))
;;;--- Make sure the DCL file loaded
(if (not (new_dialog "ATTINC" dcl_id))
(progn
(alert "Could not find the ATTINC.DCL file!")
(exit)
)
)
;;;--- Add the list to the dialog box
(start_list "attdata" 3)
(mapcar 'add_list attData)
(end_list)
;;;--- Set a default selection
(set_tile "attdata" "0")
;;;--- If an action event occurs, do this...
(action_tile "okay""(saveVars)(setq ddiag 1)(done_dialog)")
(action_tile "cancel""(setq ddiag 2)(done_dialog)")
;;;--- Display the dialog box
(start_dialog)
;;;-- Unload the dialog box
(unload_dialog dcl_id)
;;;--- Start the routine
(if(= ddiag 1)
(progn
;;;--- Display a message
(princ "\n Gathering all blocks named ")(princ blkName) (princ " .....")
;;;--- Get the blocks
(if(setq eset(ssget "X" (list (cons 0 "INSERT")(cons 2 blkName))))
(progn
(princ "\n Manipulating data .....")
;;;--- While entities exist in the selection set...
(while (> (sslength eset) 0)
;;;--- If insertion order is to be used...
(if(= order1 1)
;;;--- Get the first entity in the selection set
(setq en(ssname eset 0))
;;;--- Else use reverse order and get the last entity in the selection set
(setq en(ssname eset (- (sslength eset)1)))
)
;;;--- Replace the value of the tag
(replaceAtt en tagName str)
;;;--- Increment the value for the next attribute
(setq str(incStr str inc))
;;;--- Remove the entity from the selection set
(ssdel en eset)
)
)
)
)
)
)
(alert "The block selected does not contain attributes!")
)
)
(alert "The entity selected is not a block!")
)
)
(alert "No block selected!")
)
(princ)
)
_____________________________________
地址:
ATTINC : dialog {
label = "AttInc";
: column {
: column {
: list_box{
label ="Select Tag Name";
key = "attdata";
height = 15;
width = 45;
multiple_select = false;
fixed_width_font = false;
}
}
: column {
: edit_box{
key = "startstr";
label = "Start Value:";
edit_width = 8;
value= "A001";
}
: edit_box{
key = "increment";
label = "Increment:";
edit_width = 8;
value= "1";
}
: radio_button {
label = "Insertion order";
key = "order1";
value= "0";
}
: radio_button {
label = "Reverse insertion order";
key = "order2";
value = "1";
}
}
: column {
: boxed_row {
: button {
key = "okay";
label = "Okay";
is_default = true;
}
: button {
key = "cancel";
label = "Exit";
is_default = false;
is_cancel = true;
}
}
}
}
}
再次感谢
X1-1之前是什么,如果我理解的话,你可以在X24-24之后有别名X25-1,或者我错了,在X24-24之后和X1-1之前应该是Y1-1,W24-24。。。首先,A1-1之前是什么(我想没有什么-这是起始字符串)。。。
你是对的,X25-1将在X24-24之后,后缀是唯一一个范围限制高达24的东西。A1-1之前不会出现任何东西,A1表示第一个设备 我想你没有完全理解我。。。你什么时候更改别名-在什么数字X之后-24来Y1-1? 实际上,你根本不需要更改字母,设备的约定是提前制定的,将一直使用,因此如果它从B1-1开始,每个约定都将是Bx xx
页:
[1]
2