Billy Ray 发表于 2022-7-5 15:02:29

协助更新Lisp routi

你好
我有一个很长的Lisp程序程序,多年来没有更新过。这是严格为自定义字段插入,我不记得如何编辑它。我创建了一个diesel表达式,用于我尝试做的事情,即在文件名中添加破折号,并删除CAD文件中DWG#'s的最后4个字符。我制作了一个包含在下面的diesel表达式,但它对于使用MacAttEdit来说太长了,所以如果有人能理解的话,我想把它添加到这个lisp例程中。或者,如果有人知道如何缩短Diesel表达式,因为我只是一个新手。
 
我们当前的文件名是(28个字符):
AB12345AB1234ABCA123456789-1
 
DWG#为(前24个字符加5个破折号,因此为29个字符):
AB-12345-AB1234-ABC-A12-12345
 
Diesel表达式(我知道很长):

%<\AcDiesel $(substr,$(getvar,DWGNAME),1,2)-$(substr,$(getvar,DWGNAME),3,5)-$(substr,$(getvar,DWGNAME),8,6)-$(substr,$(getvar,DWGNAME),14,3)-$(substr,$(getvar,DWGNAME),17,3)-$(substr,$(getvar,DWGNAME),20,5)>%

 
带有自定义插入的Lisp:

(defun c:updatetitleblock ( /
   ;;local variables
   acadObject
   acadDocument
   dProps
   customPropertyName
customPropertyNamecpchem
   revCustomPropertyName
   projectCustomPropertyName
   folderCustomPropertyName
   folderCustomPropertyName2
   KeyCount
   KeyValue
   strDrawingName
   strRevNum
   strDrawingNameNoSpaces
left20characters
left21characters
left22characters
left23characters
left24characters
left25characters
left26characters
left27characters
left28characters
left2characters
left18characters
   )
   
   
;;sets the document properties
(setq acadObject (vlax-get-acad-object)
   acadDocument (vla-get-ActiveDocument acadObject)
   dProps (vlax-get-Property acadDocument 'SummaryInfo)
   customPropertyName "DRAWING No. (from file name)"
customPropertyNamecpchem "filename sans characters after penultimate dash"
   revCustomPropertyName "REV (from file name)"
   projectCustomPropertyName "PROJECT NO (from file name)"
   projectCustomPropertyName2 "file name before underscore"
   folderCustomPropertyName "last character of folder"
   folderCustomPropertyName2 "last 2 characters of folder"
left20characters "filename (left 20 characters)"
left21characters "filename (left 21 characters)"
left22characters "filename (left 22 characters)"
left23characters "filename (left 23 characters)"
left24characters "filename (left 24 characters)"
left25characters "filename (left 25 characters)"
left26characters "filename (left 26 characters)"
left27characters "filename (left 27 characters)"
left28characters "filename (left 28 characters)"
left2characters "filename (left 2 characters)"
left18characters "filename (left 18 characters)"
)

;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName customPropertyName)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps customPropertyName "REOPEN DRAWING TO UPDATE"))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR left20characters;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName left20characters)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps left20characters "REOPEN DRAWING TO UPDATE"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR left21characters;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName left21characters)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps left21characters "REOPEN DRAWING TO UPDATE"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR left22characters;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName left22characters)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps left22characters "REOPEN DRAWING TO UPDATE"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR left23characters;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName left23characters)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps left23characters "REOPEN DRAWING TO UPDATE"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR left24characters;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName left24characters)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps left24characters "REOPEN DRAWING TO UPDATE"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR left25characters;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName left25characters)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps left25characters "REOPEN DRAWING TO UPDATE"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR left26characters;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName left26characters)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps left26characters "REOPEN DRAWING TO UPDATE"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR left27characters;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName left27characters)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps left27characters "REOPEN DRAWING TO UPDATE"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR left28characters;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName left28characters)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps left28characters "REOPEN DRAWING TO UPDATE"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR left2characters;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName left2characters)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps left2characters "REOPEN DRAWING TO UPDATE"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR left18characters;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName left18characters)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps left18characters "REOPEN DRAWING TO UPDATE"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR CPchem;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName customPropertyNamecpchem)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps customPropertyNamecpchem "REOPEN DRAWING TO UPDATE"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR REV;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName revCustomPropertyName)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps revCustomPropertyName "REOPEN DRAWING TO UPDATE"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR folderLastDigit;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName folderCustomPropertyName)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps folderCustomPropertyName "REOPEN DRAWING TO UPDATE"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR project number;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName projectCustomPropertyName)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps projectCustomPropertyName "REOPEN DRAWING TO UPDATE"))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR project number;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName projectCustomPropertyName2)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps projectCustomPropertyName2 "REOPEN DRAWING TO UPDATE"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;SAME THING AS ABOVE, BUT FOR project number;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;sets a couple variables so that we can determine whether the property exists
(setq KeyCount 0 KeyValue nil)

;;while KeyValue is blank and KeyCount is less than number of properties
(while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dProps)))
;;get info about that property
(vla-GetCustomByIndex
   dProps
   KeyCount
   'TempKeyName
   'TempKeyValue
)
;;if the property name matches the name we want, set KeyValue to it's value
(if        (= TempKeyName folderCustomPropertyName2)
   (setq KeyValue TempKeyValue)
)
;;increment KayCount
(setq KeyCount (1+ KeyCount))
)
;;
;;now we add the property if it wasn't there already
(if (= KeyValue nil) (vla-addcustominfo dProps folderCustomPropertyName2 "REOPEN DRAWING TO UPDATE"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;sets strDrawingName as the name of the current drawing
(setq strDrawingName (getvar "dwgname"))

;;resets strRevNum
(setq strRevNum "")

;;makes strDrawingName uppercase
(setq strDrawingName (strcase strDrawingName))

;;if the drawing name ends in .DWG, take off the last 4 characters
(if (= (substr strDrawingName (- (strlen strDrawingName) 3) (strlen strDrawingName)) ".DWG")
(setq strDrawingName (substr strDrawingName 1 (- (strlen strDrawingName) 4)))
(setq strDrawingName strDrawingName)
)

;;makes strDrawingNameNoSpaces
(setq strDrawingNameNoSpaces strDrawingName)
(while (/= strDrawingNameNoSpaces (vl-string-subst "" " " strDrawingNameNoSpaces)) (setq strDrawingNameNoSpaces (vl-string-subst "" " " strDrawingNameNoSpaces)))

;;makes all the set-length filenames
(setq strleft20characters (substr strDrawingNameNoSpaces 1 20))
(setq strleft21characters (substr strDrawingNameNoSpaces 1 21))
(setq strleft22characters (substr strDrawingNameNoSpaces 1 22))
(setq strleft23characters (substr strDrawingNameNoSpaces 1 23))
(setq strleft24characters (substr strDrawingNameNoSpaces 1 24))
(setq strleft25characters (substr strDrawingNameNoSpaces 1 25))
(setq strleft26characters (substr strDrawingNameNoSpaces 1 26))
(setq strleft27characters (substr strDrawingNameNoSpaces 1 27))
(setq strleft28characters (substr strDrawingNameNoSpaces 1 28))
(setq strleft2characters (substr strDrawingNameNoSpaces 1 2))
(setq strleft18characters (substr strDrawingNameNoSpaces 1 18))


;;makes strDrawingNamecpchem
(setq strDrawingNamecpchem strDrawingNameNoSpaces)
(if (= (substr strDrawingNamecpchem (- (strlen strDrawingNamecpchem) 1) 1) "-") (setq strDrawingNamecpchem (substr strDrawingNamecpchem 1 (- (strlen strDrawingNamecpchem) 2)))
(if (= (substr strDrawingNamecpchem (- (strlen strDrawingNamecpchem) 2) 1) "-") (setq strDrawingNamecpchem (substr strDrawingNamecpchem 1 (- (strlen strDrawingNamecpchem) 3)))
        (if (= (substr strDrawingNamecpchem (- (strlen strDrawingNamecpchem) 3) 1) "-") (setq strDrawingNamecpchem (substr strDrawingNamecpchem 1 (- (strlen strDrawingNamecpchem) 4))))
)
)
(if (= (substr strDrawingNamecpchem (- (strlen strDrawingNamecpchem) 1) 1) "-") (setq strDrawingNamecpchem (substr strDrawingNamecpchem 1 (- (strlen strDrawingNamecpchem) 2)))
(if (= (substr strDrawingNamecpchem (- (strlen strDrawingNamecpchem) 2) 1) "-") (setq strDrawingNamecpchem (substr strDrawingNamecpchem 1 (- (strlen strDrawingNamecpchem) 3)))
        (if (= (substr strDrawingNamecpchem (- (strlen strDrawingNamecpchem) 3) 1) "-") (setq strDrawingNamecpchem (substr strDrawingNamecpchem 1 (- (strlen strDrawingNamecpchem) 4))))
)
)

;;does stuff to get rid of revision number
(if (= nil (vl-string-search "REV" strDrawingName))
;;unless there is no rev, in which get rid of trailing numbers
;;if the last three digits of DrawingNameNoSpaces has a dash or a period or an underscore
(if (/= (substr strDrawingNameNoSpaces (- (strlen strDrawingNameNoSpaces) 2) 3) (vl-string-subst "" "." (vl-string-subst "" "_" (vl-string-subst "" "-" (substr strDrawingNameNoSpaces (- (strlen strDrawingNameNoSpaces) 2) 3)))))
   (while (/= "_" (substr strDrawingName (strlen strDrawingName) 1) "-" (substr strDrawingName (strlen strDrawingName) 1) ".")
      (setq strRevNum (strcat (substr strDrawingName (strlen strDrawingName) 1) strRevNum)
            strDrawingName (substr strDrawingName 1 (- (strlen strDrawingName) 1))
      )
   )
   ;;otherwise, if the last four digits are a dash and 3 numbers
   (if (= (vl-string-right-trim "0123456789" (substr strDrawingNameNoSpaces (- (strlen strDrawingNameNoSpaces) 3) 4)) "-")
       (progn
          (setq strRevNum (substr strDrawingNameNoSpaces (- (strlen strDrawingNameNoSpaces) 2) 3)
                strDrawingName (substr strDrawingName 1 (- (strlen strDrawingName) 4))
          )
       )
   )
)

;;gets rid of everything past the REV
(setq strRevNum (substr strDrawingName (+ 4 (vl-string-search "REV" strDrawingName)) (- (+ 1 (strlen strDrawingName)) (vl-string-search "REV" strDrawingName)))
      strDrawingName (substr strDrawingName 1 (vl-string-search "REV" strDrawingName)))
)



;;gets rid of trailing spaces and dashes
(setq strDrawingName (vl-string-right-trim " -._(" strDrawingName))
(setq strRevNum (vl-string-right-trim " -._()" strRevNum))


;;gets rid of #. or ##.from beginning of drawing name
(if (or (= (substr strDrawingName 2 1) ".") (= (substr strDrawingName 3 1) "."))
;;gets rid of opening digits
(setq strDrawingName (vl-string-left-trim "0123456789" strDrawingName))
;;otherwise do nothing
(setq strDrawingName strDrawingName)
)

;;gets rid of leading spaces and dashes
(setq strDrawingName (vl-string-left-trim " -._)" strDrawingName))
(setq strRevNum (vl-string-left-trim " -._()" strRevNum))



;;gets rid of leading zeros from drawing rev
(if (and (= (substr strRevNum 1 1) "0") (> (strlen strRevNum) 1)) (setq strRevNum (substr strRevNum 2 (- (strlen strRevNum) 1))))
(if (and (= (substr strRevNum 1 1) "0") (> (strlen strRevNum) 1)) (setq strRevNum (substr strRevNum 2 (- (strlen strRevNum) 1))))
(if (and (= (substr strRevNum 1 1) "0") (> (strlen strRevNum) 1)) (setq strRevNum (substr strRevNum 2 (- (strlen strRevNum) 1))))


;;sets the property to our formatted name
(vla-SetCustomByKey dProps left20characters strleft20characters)
(vla-SetCustomByKey dProps left21characters strleft21characters)
(vla-SetCustomByKey dProps left22characters strleft22characters)
(vla-SetCustomByKey dProps left23characters strleft23characters)
(vla-SetCustomByKey dProps left24characters strleft24characters)
(vla-SetCustomByKey dProps left25characters strleft25characters)
(vla-SetCustomByKey dProps left26characters strleft26characters)
(vla-SetCustomByKey dProps left27characters strleft27characters)
(vla-SetCustomByKey dProps left28characters strleft28characters)
(vla-SetCustomByKey dProps left2characters strleft2characters)
(vla-SetCustomByKey dProps left18characters strleft18characters)
(vla-SetCustomByKey dProps customPropertyNamecpchem strDrawingNamecpchem)
(vla-SetCustomByKey dProps customPropertyName strDrawingName)
(vla-SetCustomByKey dProps revCustomPropertyName strRevNum)
(vla-SetCustomByKey dProps folderCustomPropertyName (substr(getvar "dwgprefix") (- (strlen (getvar "dwgprefix")) 1) 1))
(vla-SetCustomByKey dProps folderCustomPropertyName2 (substr(getvar "dwgprefix") (- (strlen (getvar "dwgprefix")) 2) 2))
(vla-SetCustomByKey dProps projectCustomPropertyName (vl-string-right-trim " -._()" (substr strDrawingName 1 10)))
(vla-SetCustomByKey dProps projectCustomPropertyName2 (vl-string-right-trim " -._()" (substr strDrawingName 1 (vl-string-search "_" strDrawingName))))

;;forces update
(command "updatefield" "all" "")

)

(vl-load-com)
(c:updatetitleblock)
(princ)

 
谢谢你的帮助,如果我能找到答案,我会在这里重新发布。

Billy Ray 发表于 2022-7-5 15:07:12

如果有人想使用lisp和diesel表达式,顺便提一下。很高兴能找到缩短Diesel表达式的方法,因为它很长。

pBe 发表于 2022-7-5 15:11:12

当然可以短得多。
 
如果随附示例图形文件,则发布的长代码更有意义。

Billy Ray 发表于 2022-7-5 15:14:44

 
一个pic就足够了,因为它只是一个字段插入,如下图所示。如果有办法缩短diesel表达式或将其“添加”到lisp例程中,这将很有帮助。lisp很长,因为其中有许多自定义字段插入。在下面的图片中,我在DWG编号上插入了一个内容。但是Diesel表达式太长,所以我不想将其添加到lisp例程中。同样在这种情况下,前两个字母后面有7个数字,而不是我最初发布的5个数字。“SA”字符后有5或7位数字,其余数字相同。谢谢你的帮助!
 

ronjonp 发表于 2022-7-5 15:16:01

你为什么不先用破折号来命名文件?

Billy Ray 发表于 2022-7-5 15:19:36

 
同意,不由我决定,这是客户标准。。。。。

pBe 发表于 2022-7-5 15:23:47

我甚至认为这并不难。
 
 
为什么是7而不是5?还是4平?
 
这正是我们要求提供样图的原因。在你贴的那张照片上,图片的名字是什么?
 
还有这个

 
这一切意味着什么?

Billy Ray 发表于 2022-7-5 15:27:31

随附的是DWG文件。不确定DWG属性的图片是如何出现的,因为我附加了标题栏的图片。无论如何,文件名在下面,没有任何更改。我之前提供了diesel表达式和一个包含其他插入的lisp文件。
 
SA2144283FA2006PLCE02010301-0
SA2144283FA2006PLCE02010301-0。图纸

pBe 发表于 2022-7-5 15:28:23

 
这样,我们可以看到标题栏在自定义属性中引用了哪些其他字段表达式
 
 
作为启动器
 

(substr
(apply
   'strcat
   (mapcar
   '(lambda (n)
      (strcat "-" (substr (getvar 'dwgname) (car n) (cadr n)))
      )
   '((1 2) (3 5) (8 6) (14 3) (17 3) (20 5))
   )
   )
2
)


("-AB" "-12345" "-AB1234" "-ABC" "-A12" "-34567")
"AB-12345-AB1234-ABC-A12-34567"


 
可以将值赋给自定义特性,然后将其用作字段值,而不是Diesel表达式。甚至可以将lisp变量作为字段表达式,[在我看来要容易得多]
 
你还没有解释为什么有时候是5而不是7,你能解释更多吗?
 
 
 
-我在这里看到了一种模式
 
LM会喜欢的

Billy Ray 发表于 2022-7-5 15:32:31

你还没有解释为什么有时候是5而不是7,你能解释更多吗?
 
 
这是客户对其文件名的要求。旧项目在“SA”后有5位数字,所有新项目和未来项目在“SA”后有7位数字。除此之外,剩余的字符数永远不会改变。
 
谢谢,我将尝试将其添加到lisp例程中。它变得如此满以至于很难记住在哪里添加它,哈哈。
页: [1] 2
查看完整版本: 协助更新Lisp routi