resullins 发表于 2022-7-6 09:40:28

LISP例程:如何。

原谅我,如果这已经涵盖,我是新来的,我找不到它。
 
我已经使用ACAD很长时间了,但从未有意识地使用LISP例程。一些研究告诉了我它们是什么。。。。但我不知道如何让它们工作。
 
我的困境:在块中自动编号selct属性。我在这里找到了一个人们说效果很好的,我已经把它保存到我的支持文件中,我已经把它加载到我的绘图中,但是我实际上如何使它运行呢?
 
对不起,我的无知。感谢所有帮助!

CyberAngel 发表于 2022-7-6 09:44:20

如果查看代码,它应该以括号、单词“defun”(用于定义函数)和例程的名称开头。在AutoCAD任务中加载例程后,只需键入名称即可运行它。实际上,您已经创建了一个新命令。

resullins 发表于 2022-7-6 09:48:37

啊。。。非常感谢。很容易!现在我只需要找到正确的Lisp程序。。。我试过的那个离工作很近!

Lee Mac 发表于 2022-7-6 09:52:37

这可能有助于:
 
http://lee-mac.com/runlisp.html

resullins 发表于 2022-7-6 09:53:22

谢谢李。。。现在一切都有了意义。我以前从未有过使用LISPS的特权,因为我不是一个程序员。
 
还有一个问题,因为你在这方面似乎有很多经验。。。我知道这个话题已经在这里讨论过了,但我似乎找不到我需要的答案。我需要用前缀对某些块属性进行自动编号。例如,我需要一大堆块从L-001到L-010进行编号。然后在后面的图中,我可能需要从L-201到L-221对一些进行编号。我发现一个lisp可以很好地自动编号,但它不会在那里留下前缀。
 
有人知道这个吗?

CADkitt 发表于 2022-7-6 09:59:15

这里有一个类似的问题和解决方案。
http://www.cadtutor.net/forum/showthread.php?52077-前导-zero-s-in-attribute-value&高亮显示=前导

BlackBox 发表于 2022-7-6 10:00:13

 
 
 
这很容易。。。要是当初我也这么做就好了!:lol:lmao
 
当然,我只是在开玩笑。
 
快乐的编码,Resulins!:眨眼:

alanjt 发表于 2022-7-6 10:02:48

完整的论点和有趣的GIF从我。

Lee Mac 发表于 2022-7-6 10:08:48

 
我不久前写了这篇文章,并很快对其进行了修改,以接受可选前缀和零填充-目前它将从左到右编号:
 

(defun c:AttNum ( / *error* _StartUndo _EndUndo _PadLeft doc ss lst ) (vl-load-com)
;; © Lee Mac 2010

(defun *error* ( msg )
   (if doc (_EndUndo doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
)

(defun _StartUndo ( doc ) (_EndUndo doc)
   (vla-StartUndoMark doc)
)

(defun _EndUndo ( doc )
   (if (= 8 (logand 8 (getvar 'UNDOCTL)))
   (vla-EndUndoMark doc)
   )
)

(defun _PadLeft ( str cha len )
   (if (< (strlen str) len)
   (_PadLeft (strcat cha str) cha len)
   str
   )
)

(setq doc(vla-get-ActiveDocument (vlax-get-acad-object)))

(setq *tag (cond ( *tag ) ( "TAG1" ))
      
)

(setq *tag
   (strcase
   (cond
       (
         (eq ""
         (setq tmp
             (getstring
               (strcat "\nSpecify Attribute Tag to be Numbered <"
               (setq *tag
                   (cond ( *tag ) ( "TAG1" ))
               )
               "> : "
               )
             )
         )
         )
         *tag
       )
       ( tmp )
   )
   )
)

(setq *pre (getstring t "\nSpecify Prefix <None> : "))

(initget 6)
(setq len(getint "\nSpecify Number Length <Any> : "))

(setq *num
   (1-
   (cond
       (
         (getint
         (strcat "\nSpecify Starting Number <"
             (itoa
               (setq *num
               (1+
                   (cond ( *num ) ( 0 ))
               )
               )
             )
             "> : "
         )
         )
       )
       ( *num )
   )
   )
)

(if (ssget "_:L" '((0 . "INSERT") (66 . 1)))
   (progn      
   (vlax-for o (setq ss (vla-get-ActiveSelectionSet doc))
       (setq lst
         (cons
         (cons (vlax-get o 'InsertionPoint) o) lst
         )
       )
   )
   (vla-delete ss)

   (_StartUndo doc)

   (mapcar
       (function
         (lambda ( block )
         (mapcar
             (function
               (lambda ( attrib )
               (if (eq *tag (strcase (vla-get-TagString attrib)))
                   (vla-put-TextString attrib
                     (strcat *pre
                     (_PadLeft (itoa (setq *num (1+ *num))) "0" (cond ( len ) ( 0 )))
                     )
                   )
               )
               )
             )
             (vlax-invoke (cdr block) 'GetAttributes)
         )
         )
       )
       (vl-sort lst
         (function
         (lambda ( a b ) (< (caar a) (caar b)))
         )
       )
   )

   (_EndUndo doc)
   )
)

(princ)
)


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

 
英雄联盟
页: [1] 2
查看完整版本: LISP例程:如何。