Trebuchet 发表于 2022-7-6 07:41:19

顺序编号块att

我已经搜索并找到了几个Lisp程序的词,但它们都不适用于我的block。我尝试使用以下方法:
 
(defun c:mnum(/ stStr stNum nLen cAtr dLst blName
         fLst blLst blSet aName sLst lZer aStr)
(vl-load-com)
(if
   (and
   (setq stStr(getstring "\nSpecify start number: "))
   (setq stNum(atoi stStr))
   (setq nLen(strlen stStr))
   ); end and
   (progn
   (if
   (and
      (setq cAtr(nentsel "\nPick attribute > "))
      (= "ATTRIB"(cdr(assoc 0(setq dLst(entget(car cAtr))))))
   ); end and
   (progn
   (setq blName
       (vla-get-Name
          (vla-ObjectIDToObject
         (vla-get-ActiveDocument
            (vlax-get-acad-object))
               (vla-get-OwnerID
                  (vlax-ename->vla-object(car cAtr)))))
       fLst(list '(0 . "INSERT")(cons 2 blName))
       aName(cdr(assoc 2 dLst))
       ); end setq
   (princ "\n<<< Select blocks to number >>> ")
   (if
       (setq blSet(ssget fLst))
       (progn
      (setq sLst
                   (mapcar 'vlax-ename->vla-object
             (mapcar 'car
            (vl-sort
               (vl-sort
               (mapcar '(lambda(x)(list x(cdr(assoc 10(entget x)))))
                   (vl-remove-if 'listp
                           (mapcar 'cadr(ssnamex blSet))))
                     '(lambda(a b)(<(caadr a)(caadr b))))
                     '(lambda(a b)(>(cadadr a)(cadadr b)))))))
      (foreach i sLst
          (setq lZer "")
          (repeat(- nLen(strlen(itoa stNum)))
      (setq lZer(strcat lZer "0"))
      ); end repeat
          (setq atLst
             (vlax-safearray->list
            (vlax-variant-value
            (vla-GetAttributes i))))
          (foreach a atLst
      (if
          (= aName(vla-get-TagString a))
             (vla-put-TextString a
         (strcat lZer(itoa stNum)))
          ); end if
      ); end foreach
      (setq stNum(1+ stNum))
          ); end foreach
         ); end progn
       (princ "\nEmpty selection! Quit. ")
       ); end if
   ); end progn
   (princ "\nThis isn't attribute! Quit. ")
   ); end if
   ); end progn
   (princ "\nInvalid start number! Quit. ")
   ); end if
(princ)
); end of c:mnum

btraemoore 发表于 2022-7-6 08:02:43

我做过一些vb编程,但不多。使用上面的代码,我得到了一个运行时错误。“需要对象”
 
调试突出显示此行:
Sub NameOfYourChoice()
   ' We create our group codes and data values for our selection set.
   Dim gpCode(1) As Integer
   Dim dataValue(1) As Variant
   Dim SS_Blk As AcadSelectionSet
   Dim i As Integer, n As Integer

   SS_delete 1

   ' This is our filter.
   ' We set the group codes and data values for what we want to find.
   Set SS_blk = ThisDrawing.SelectionSets.Add("SS_blk")
       gpCode(0) = 0: dataValue(0) = "INSERT"
       gpCode(1) = 8: dataValue(1) = "layer entities are on"
      
   SS_blk.Select acSelectionSetAll, , , gpCode, dataValue
       ' because VBA is object oriented, we have to create the references for our blocks
       ' We create our blocks and the attributes in our blocks.
       Dim Cur_Blk As AcadBlockReference
       Dim Blk_Atts() As AcadAttributeReference
       Dim Cur_Att As AcadAttributeReference
      
       ' This is where we make our loop
       ' " For i ". " i " is equal to the item number in the selection set
       ' until we get to the count of how many entities in SS_blk -1,
       ' because our item count in a selection set starts at 0 not at 1
       ' like in a collection.
       For i = 0 To SS_blk.Count - 1
         Set Cur_Blk = SS_Example.Item(i)
         Blk_Atts = Cur_Blk.GetAttributes
         
         ' " For n ", " n ' is equal to the attribute number in the current block.
         For n = 0 To UBound(Blk_Atts)
               Set Cur_Att = Blk_Atts(n)
            
               If Cur_Att.TagString = "GROUPID" Then
                   CurAtt.textstring = CurAtt.textstring + 100
' if the attribute text string = 7 then +2 would put it at 9
               End If
         Next n
       Next i
      
   Application.Update


End Sub


'-------------------

Sub SS_delete(x As Byte)
   If ThisDrawing.SelectionSets.Count > 0 Then
   Dim i As Integer
       On Error Resume Next
       For i = 0 To ThisDrawing.SelectionSets.Count - 1
         ThisDrawing.SelectionSets.Item(i).Delete
       Next i
       On Error GoTo 0
   End If
End Sub

 
我对这件事还不太熟悉。

Trebuchet 发表于 2022-7-6 08:06:58

 
对不起,我错过了一些东西。重新复制代码。我将SS_示例更改为SS_blk。

btraemoore 发表于 2022-7-6 08:21:54

只是一种调试问题的方法,我不使用If和progn方法,而是一步一步的方法和defuns,其他人会拒绝我,但它更容易找出代码不工作的地方,因为If中包含的代码不多。我经常做的是(普林斯“1”)等等,看看数字1,2,3在4之前停下来,这可能有助于了解它实际上停在哪里。否则,请在错误设置为on的情况下尝试VLIDE。

BIGAL 发表于 2022-7-6 08:41:11

 
 
这就是你的问题所在:代码正在寻找一个特定的块名。。。。。。
 
 
部分是正确的,这并不局限于您的块,而是因为您使用的是一个动态块,其中块名称在参数修改后更改为匿名名称。
 
在本例中(vla get Name…)将为您提供类似“*U2”的内容,(list“(0。“INSERT”)(cons 2 blName))将为您提供
((0。“插入”)(2。“*U2”))作为fLst的值。
 
更好地使用(vla get EffectiveName…)和(list“(0。“INSERT”)(cons 2(strcat blName”,`*U*”)(66.1))
 
把它们放在一起
 
(defun c:mnum(/str stNum nLen cAtr dLst blName fLst blLst blSet aName sLst lZer asr)(vl load com)[颜色=蓝色](defun _effname(ssobj bn/e selfil)(setq selfil(ssadd))(重复(sslength ssobj)(if(eq(vla get effectivename(vlax ename->vla object(setq e(ssname ssobj 0)))bn)(ssadd e selfil))(ssdel e ssbj))(if(zerop(sslength selfil))nilselfil))(if(and(setq stStr(getstring“\n指定开始编号:))(setq stNum(numberp(read stStr)))(setq nLen(strlen stStr)));end和(progn(if(和(setq cAtr(nentsel“\nPick属性>”))(=“ATTRIB”(cdr(assoc 0(setq dLst(entget(car cAtr);)))));结束和(progn(setq blName(vla get EffectiveName(vla ObjectIDToObject(vla get ActiveDocument(vlax get acad object))(vla get OwnerID(vlax ename->vla object(car cAtr)а)а)fLst(list’(0。“INSERT”)(cons 2(strcat blName“,`*U*”))(66.1))aName(cdr(assoc 2 dLst))); 结束setq(princ“\n>”)(如果(和(setq blSet(ssget fLst))(setq blSet(\u effname blSet blName)))(progn(setq sLst(mapcar“vlax ename->vla对象(mapcar”car(vl sort(vl sort(mapcar)”(lambda(x)(列表x(cdr)(assoc 10(entget x)]]))(vl remove if“listp(mapcar”cadr(ssnamex blSet)))(λ(a b)(

pBe 发表于 2022-7-6 08:45:49

页: [1]
查看完整版本: 顺序编号块att