匹配最新属性v
Commandobill不久前写了一些代码。我需要调整一下。下面的蓝色代码需要更改,我正在绞尽脑汁。我需要REV块中最高REV属性的值进入“REV”属性,而不是手动替换属性值。代码当前查找最高的REV属性,但随后用手动文本替换。为了取代蓝色,我需要一些类似的东西:
(cb:replaceAttributeValue“REV”(最高REV的属性值,例如:5表示REV5)(vlax ename->vla object x))
大部分代码已经在这里了,它只是让cb:replaceAttributeValue函数将“REV”的属性值与revblock中最高REV的属性值匹配(例如,属性REV 5为5)。
(vl load com)
(defun c:test11(/blockSS blockList attName attNumber)
(如果
(setq blockSS(ssget“X”(列表(cons 0“插入”)(cons-4“”))
(程序
(setq区块列表(mapcar’cadr(ssnamex blockSS)))
(setq attName(vla get tagstring(car(cb:matchAtts“REV”“REV”(vlax ename->vla object(car blockList)ϞϞ))))
(setq attNumber(substr attName(strlen attName)1))
(mapcar’(λ(x))
(cb:replaceAttributeValue(strcat“DATE”attNumber)“15年6月29日”(vlax ename->vla object x))
(cb:replaceAttributeValue(strcat“DESC”attNumber)“基线更新-101/111翻新”(vlax ename->vla object x)))
区块列表)
))
(普林斯)
)
(defun cb:matchAtts(baseAttName attPrefix Blk/)
(setq baseAtt(car(vl remove if not’(lambda(x)(=baseAttName(vla get tagstring x))))(cb:variantToList(vla getattributes Blk ()))))
(如果不是,则vl移除’(λ(x)
(和
(wcmatch(vla get tagstring x)(strcat attPrefix“*”)
(非(eq(vla get tagstring x)baseAttName))
(等式(vla get textstring x)(vla get textstring baseAtt))
))
(cb:variantToList(vla getattributes Blk)))
)
(defun cb:variantToList(theVariant/)
(如果(='变体(键入变体))
(vlax safearray->列表(vlax variant value theVariant))
无
)
)
;;;;;替换属性值;;;;;;;;;
;;;;;签字人:CommandoBill;;;;;;;;;;;;;;;;;
;;;;;01/24/15;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;向该函数发送一个块,其中包含要用新值替换的属性
;;;;attName=要替换其值的属性的名称
;;;;attNewVal=属性中需要的新值
;;;;Blk=属性所在块的vla对象验证
(defun cb:replaceAttributeValue(attName attNewVal Blk/)
(mapcar’(λ(x)(if(=attName(vla get tagstring x))
(vla put textstring x attNewVal))(cb:variantToList(vla getattributes Blk)))
(普林斯)
) (cb:replaceAttributeValue (strcat "DATE" attNumber) "29-JUN-15" (vlax-ename->vla-object x)) <p> </p><p>The above code replaces the attribute value (strcat "DATE" attNumber), which could be an attribute with the tag DATE1, or DATE2, or DATE3, ect. depending on which line in the revision block has the most current revision.</p><p> </p><p>What I want to do is replace attribute REV with the attribute value in (strcat "REV" attNumber). For this particular title block, let's say this attribute is REV5 and the value is 12. I need to pass the value of REV5 (12) to REV so they both say 12. Currently the value of REV is most likely X by default because the routine I use to swap title blocks doesn't know what REV should be.</p> 发布dwg,两块标题栏和修订栏? 大阿尔,
谢谢你善良的先生。我目前没有访问实际文件的权限,但我重新创建了一个快速的临时标题栏,它应该足以证明概念。
右下角有一个REV属性,显示当前图形的REV。
上面有REV块。它可以容纳6个版本。每个属性都被命名为REV1、REV2到REV6。目前,我将图形设置为第5版,并在REV5属性中添加了值5。事实上,这个值可以是任何值,因为只有6个可能的修订版本,例如,图纸可以在REV5位置达到修订版100,但我只是保持简单。
也就是说,我需要获得最新版本或最新版本属性值的代码(在本例中,REV5为5),并在右下角的REV属性中设置相同的值。我确实有成千上万的图纸,其中旧标题栏在右下角没有REV属性。
我在本线程开头发布的代码中的cb:matchAtts子函数似乎可以找到最新版本。我认为需要调整的是cb:replaceAttributeValue子函数。目前,它将REV处的值替换为REV5,即标记名,在本例中,它需要是属性(5)的实际值。 从零开始要容易得多。作为测试,它只执行一个布局,但可以很容易地修改以检查所有布局。只有一个错误检查您没有超过1个块。
; daballz lisp
; by Alan H june 2017
; hard coded for the block
(defun c:daballz( / blockss x y atts obj tagname lookfor revtemp)
(setq blockSS (ssget "X" (list (cons 0 "INSERT") (cons -4 "<xor") (cons 2 "Drawing_Sheet_22x34") (cons 2 "Drawing_Sheet_22x34-H") (cons -4 "xor>"))))
(if (> 1 (setq x (sslength blockss))) ; make sure only one title block
(progn
(Alert "You have more than 1 title block on this page\n\nprogram will exit")
(exit) ; hard coded exit not vey gracefull
)
(princ "ok") ; dummy statement
)
(setq obj (vlax-ename->vla-object (ssname blockss 0))) ; get the 1st obj inside the selection set
(setq atts (reverse(vlax-invoke obj'getattributes))) ; get all the attributes and convert to a list
(setq x 1)
(repeat (setq y (length atts )) ; loop for all attributes
(setq lookfor (strcat "REV" (rtos x 2 0))) ; add a number as a string to "REV"
(setq tagname (vla-get-tagstring (nth(setq y (- y 1))atts))) ; get attribute 1 at a time
(if (= tagnamelookfor) ; check for match tag names
(setq revtemp (vla-get-textstring (nthyatts))) ; if true set temp value repeat for highest number
)
(if(and (/=revtemp "" )(< x 7)) ; double check for a blank field and no more than 6 revisions
(progn
(setq revval revtemp)
(setq x (+ x 1))
(setq revtemp "") ; needed to make sure resets inside loop
)
)
)
(setq lookfor"REV" ) ; destination tag name
(repeat(setq y (length atts )) ; loop through the attributes
(setq tagname (vla-get-tagstring (nth(setq y (- y 1))atts))) ; get tagstring of a attribute
(if (= tagname lookfor) ; test for match
(vla-put-textstring (nthyatts) revval) ; if match change value
)
)
)
(c:daballz)
我的朋友,真是了不起的作品。它现在正在工作。我不得不调整一下,但在日常生活中,大部分的逻辑是我一直在努力解决的。再次感谢。 现在,我在AutoCAD 2014中的实际标题栏上运行此操作,并得到以下错误:
命令:REVMATCH
好啊错误:ActiveX服务器返回错误:参数不是可选的
我将代码放在(defun c:REVMATCH(/)中,并添加了一个(vl load com),但仍然出现了这个错误。
有什么想法吗?它正在AutoCAD 2015上使用具有完全相同的块名和属性标记名的模拟块。。。 我已经编辑了上面的代码,以匹配您的REVMATCH,并对照您的示例dwg进行了检查。 块名称和属性名称相同,但块是否具有样例图形中未包含的其他特性和其他属性,这有关系吗?我一有机会就会给你发送真正的标题栏。 这是工作标题栏。我的vcom可能有问题。dll,现在正在工作。如果你在这台上运行它,它会工作。。。让我知道。此外,我正在运行AutoCAD 2014。
页:
[1]
2