Jump to content

Assistance updating Lisp routine for Field Insertion


Billy Ray
 Share

Recommended Posts

Hello,

I have a lengthy lisp routine that hasn't been updated in years. It is strictly for Custom Field Insertions and I do not remember how to edit it. I created a diesel expression for what I'm trying to do which is simply adding dashes to a filename and removing the last 4 characters for our DWG #'s in the CAD file. I've made a diesel expression included below but it is too long for using MacAttEdit so I'd like to add it to this lisp routine if someone can understand it. Or perhaps if someone knows how to make the Diesel Expression shorter as I am just a novice at this.

 

Our current file name is (28 characters):

AB12345AB1234ABCA123456789-1

 

The DWG # is (FIRST 24 characters plus 5 dashes, so 29 characters):

AB-12345-AB1234-ABC-A12-12345

 

Diesel Expression (long I know):

%<\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 with custom insertions:

(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)

 

Thanks for any assistance and if I figure it out somehow I will re-post here.

Link to comment
Share on other sites

  • Replies 32
  • Created
  • Last Reply

Top Posters In This Topic

  • Billy Ray

    18

  • pBe

    11

  • Lee Mac

    2

  • ronjonp

    2

Top Posters In This Topic

Posted Images

The lisp and diesel expression work by the way if anyone wants to use them. Would be nice to figure out how to shorten that Diesel Expression though as it's pretty long.

Link to comment
Share on other sites

Definitely can be a lot shorter.

 

The long code you posted will make more sense if you attached a sample drawing file along with it.

Link to comment
Share on other sites

Definitely can be a lot shorter.

 

The long code you posted will make more sense if you attached a sample drawing file along with it.

 

A pic will suffice as it is just a field insertion, pic below. If there is a way to make the diesel expression shorter or "ADD" to the lisp routine it would be helpful. The lisp is lengthy because it has many custom field insertions in it. In the pic below I have an insertion on the DWG no. however the Diesel Expression is too long so I would like t add it to the lisp routine. Also in ths case there are 7 numbers after the first two letters, stead of 5 that I originally posted. We either have 5 or 7 digits after the "SA" characters, the rest is the same. Thank for any help!

 

Field Insertion.jpg

Link to comment
Share on other sites

Why don't you just name the files with the dashes in the first place?

 

Agreed, wasn't up to me it's a Client Standard.....

Link to comment
Share on other sites

I don't even think is difficult to do.

 

Also in ths case there are 7 numbers after the first two letters, stead of 5 that I originally posted. We either have 5 or 7 digits after the "SA" characters, the rest is the same.

 

Why 7 and not 5? or 4 even?

 

That is exactly the reason why we're asking for a sample drawing. On that pic you posted, what is the drawing name to start with?

 

and this

what does it mean.PNG

 

What does it all mean?

Link to comment
Share on other sites

Attached is the DWG file. Not sure how a pic of the DWG Properties is there as I attached a pic of the title block. Anyhow, the file name is below and nothing has changed. I supplied the diesel expression before and a lisp file with other insertions in it.

 

SA2144283FA2006PLCE020103101-0

SA2144283FA2006PLCE020103101-0.dwg

Link to comment
Share on other sites

Attached is the DWG file. Not sure how a pic of the DWG Properties is there as I attached a pic of the title block. Anyhow...

 

That way, we could see what other field expressions the title block is referring to within the Custom property

 

 

As starter

 

(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" 

 

You can assign the values into a Custom property then use that as Field value instead of Diesel Expression. or even a lisp variable as a field expression, [ a lot easier IMO ]

 

You have not explained why sometimes it's 5 and not 7, Can you explain more?

 

 

(1 2) ->3

(3 5) ->8

(8 6) ->14

(14 3)->17

(17 3)->20

(20 5))

 

- I'm seeing a pattern here [ LPB ]

 

LM would love this :)

Edited by pBe
Link to comment
Share on other sites

You have not explained why sometimes it's 5 and not 7, Can you explain more?

 

 

It's a Client requirement for their file names. Older projects have 5 digits after the "SA" and all new and future projects have 7 digits after the "SA" .Other than that the remaining number of characters will never change.

 

Thank you I will try to add that to the lisp routine. It's getting so full it's hard to remember where all to add it , lol.

Link to comment
Share on other sites

Since the extracted substrings appear consecutively in the original string, you could design a function which would accept a single list of character breakpoints, e.g.:

(defun fn ( str lst / len )
   (setq len (- (cadr lst) (car lst)))
   (if (cddr lst)
       (strcat (substr str (car lst) len) "-" (fn (substr str (cadr lst)) (mapcar '(lambda ( x ) (- x len)) (cdr lst))))
       (substr str (car lst) len)
   )
)

_$ s
"AB12345AB1234ABCA123456789-1"
_$ (fn s '(1 3 8 14 17 20 25))
"AB-12345-AB1234-ABC-A12-34567"

Or alternatively:

(defun fn2 ( str lst / i )
   (setq i 0 lst (cdr lst))
   (vl-list->string
       (apply 'append
           (mapcar
              '(lambda ( x )
                   (cond
                       (   (null lst) lst)
                       (   (<= (car lst) (setq i (1+ i)))
                           (if (setq lst (cdr lst)) (list 45 x))
                       )
                       (   (list x))
                   )
               )
               (vl-string->list str)
           )
       )
   )
)

_$ s
"AB12345AB1234ABCA123456789-1"
_$ (fn2 s '(1 3 8 14 17 20 25))
"AB-12345-AB1234-ABC-A12-34567"

Link to comment
Share on other sites

Since the extracted substrings appear consecutively in the original string, you could design a function which would accept a single list of character breakpoints, e.g.:
(defun fn ( str lst / len )
   (setq len (- (cadr lst) (car lst)))
   (if (cddr lst)
       (strcat (substr str (car lst) len) "-" (fn (substr str (cadr lst)) (mapcar '(lambda ( x ) (- x len)) (cdr lst))))
       (substr str (car lst) len)
   )
)

_$ s
"AB12345AB1234ABCA123456789-1"
_$ (fn s '(1 3 8 14 17 20 25))
"AB-12345-AB1234-ABC-A12-34567"

Or alternatively:

(defun fn2 ( str lst / i )
   (setq i 0 lst (cdr lst))
   (vl-list->string
       (apply 'append
           (mapcar
              '(lambda ( x )
                   (cond
                       (   (null lst) lst)
                       (   (<= (car lst) (setq i (1+ i)))
                           (if (setq lst (cdr lst)) (list 45 x))
                       )
                       (   (list x))
                   )
               )
               (vl-string->list str)
           )
       )
   )
)

_$ s
"AB12345AB1234ABCA123456789-1"
_$ (fn2 s '(1 3 8 14 17 20 25))
"AB-12345-AB1234-ABC-A12-34567"

 

Thanks Lee! It seems like every bit of code in the world has your hands in it, lol. Very much appreciated! the expression was for your MacAttEditor and the lisp I believe derived from your update title block. I will update as soon as I get this project out. Thank you all for your help!

Link to comment
Share on other sites

Thanks Lee! It seems like every bit of code in the world has your hands in it, lol. Very much appreciated! the expression was for your MacAttEditor and the lisp I believe derived from your update title block. I will update as soon as I get this project out. Thank you all for your help!

 

Thanks Billy Ray -

 

You may wish to use my Batch Attribute Editor for this task - it's a more recently developed program and should allow you to populate your attributes with your existing DIESEL field expression.

Link to comment
Share on other sites

..It's a Client requirement for their file names..

 

I think its safe to assume if the filename is 28 characters long and not 30 then its old format, correct?

 

Since the extracted substrings appear consecutively in the original string, you could design a function which would accept a single list of character breakpoints, e.g.:

 

I knew you're going to math the s*** out of this. :lol:

Link to comment
Share on other sites

(Defun c:FromLispToTblock ( / acadDocument dwgname breaker)
 
(setq acadDocument (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq dwgname (vl-filename-base (vla-get-name acadDocument)))
(Setq breaker (if (= (Setq flen (strlen dwgname)) 28)
       		'((1 2) (3 5) (8 6) (14 3) (17 3) (20 5))
       		'((1 2) (3 7) (10 6) (16 3) (19 3) (22 5))
                )
  )
         
       (setq ForTitleBlock    
	(substr (apply
	    'strcat (mapcar
	      '(lambda (n)
	         (strcat "-" (substr (getvar 'dwgname) (car n) (cadr n)))
	         ) breaker	     
	      )
	    )
	  2
	  )
         	RevisionFromFilename (substr dwgname flen)
         	)
 	(list ForTitleBlock Revision)
 )

 

On the attached drawing [ SA2144283FA2006PLCE020103101-1.dwg ], the "DRAWINGNUMBER" tag gets the field value from "ForTitleBlock" Lisp Variable and for "REV" tag its "RevisionFromFilename"

 

Command: FROMLISPTOTBLOCK

 

HTH

 

EDIT: Come to think of it, there's no point in using fields if one is using a lisp code to generate the value :D

SA2144283FA2006PLCE020103101-1.dwg

Edited by pBe
Link to comment
Share on other sites

I think its safe to assume if the filename is 28 characters long and not 30 then its old format, correct?

 

Yes that's correct. Sorry for the late response

Link to comment
Share on other sites

It also looks like you're pulling the REV number after the "-" in the file name .. here's one way to grab that info:

(setq f (vl-filename-base (getvar 'dwgname)))
(if (setq i (vl-string-search "-" f))
 (setq rev (substr f (+ 2 i) (strlen f)))
)

Link to comment
Share on other sites

It also looks like you're pulling the REV number after the "-" in the file name .. here's one way to grab that info:

(setq f (vl-filename-base (getvar 'dwgname)))
(if (setq i (vl-string-search "-" f))
 (setq rev (substr f (+ 2 i) (strlen f)))
)

 

Thanks that is useful. The main reason I wanted to add expressions was in case others don't have the Custom ones loaded they can drop these from a library and insert them in the MAcATTEditor.

Link to comment
Share on other sites

(Defun c:FromLispToTblock ( / acadDocument dwgname breaker)
 
(setq acadDocument (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq dwgname (vl-filename-base (vla-get-name acadDocument)))
(Setq breaker (if (= (Setq flen (strlen dwgname)) 28)
       		'((1 2) (3 5) (8 6) (14 3) (17 3) (20 5))
       		'((1 2) (3 7) (10 6) (16 3) (19 3) (22 5))
                )
  )
         
       (setq ForTitleBlock    
	(substr (apply
	    'strcat (mapcar
	      '(lambda (n)
	         (strcat "-" (substr (getvar 'dwgname) (car n) (cadr n)))
	         ) breaker	     
	      )
	    )
	  2
	  )
         	RevisionFromFilename (substr dwgname flen)
         	)
 	(list ForTitleBlock Revision)
 )

 

On the attached drawing [ SA2144283FA2006PLCE020103101-1.dwg ], the "DRAWINGNUMBER" tag gets the field value from "ForTitleBlock" Lisp Variable and for "REV" tag its "RevisionFromFilename"

 

 

 

HTH

 

EDIT: Come to think of it, there's no point in using fields if one is using a lisp code to generate the value :D

 

Thank you I will check this out.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share


×
×
  • Create New...