;;;从AutoCAD 2013 Active Reference帮助中code Examples中提取
;;;本源代码由 xshrimp 2013.2.20 搜集整理,版权归原作者所有!


(vl-load-com)
(defun c:Example_SetCustomByIndex()
    ;; This example shows how to access drawing properties
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    (setq summaryInfo (vla-get-SummaryInfo doc))
  
    ;; Add and display standard properties
    (vla-put-Author summaryInfo "John Doe")
    (vla-put-Comments summaryInfo "Includes all ten levels of Building Five")
    (vla-put-HyperlinkBase summaryInfo "http://www.autodesk.com")
    (vla-put-Keywords summaryInfo "Building Complex")
    (vla-put-LastSavedBy summaryInfo "JD")
    (vla-put-RevisionNumber summaryInfo "4")
    (vla-put-Subject summaryInfo "Plan for Building Five")
    (vla-put-Title summaryInfo "Building Five")

    (setq author (vla-get-Author summaryInfo))
    (setq comments (vla-get-Comments summaryInfo))
    (setq HLB (vla-get-HyperlinkBase summaryInfo))
    (setq KW (vla-get-Keywords summaryInfo))
    (setq LSB (vla-get-LastSavedBy summaryInfo))
    (setq RN (vla-get-RevisionNumber summaryInfo))
    (setq subject (vla-get-Subject summaryInfo))
    (setq Title (vla-get-Title summaryInfo))
    (alert (strcat "The standard drawing properties are "
                   "\nAuthor = " author
                   "\nComments = " comments
                   "\nHyperlinkBase = " HLB
                   "\nKeywords = " KW
                   "\nLastSavedBy = " LSB
                   "\nRevisionNumber = " RN
                   "\nSubject = " Subject
                   "\nTitle = " Title
           )
    )
  
    ;; Add and display custom properties
    (setq CustomPropertyBranch "Branch")
    (setq PropertyBranchValue "Main")
    (setq CustomPropertyZone "Zone")
    (setq PropertyZoneValue "Industrial")

    ;; Add custom properties
    (if (>= (vla-NumCustomInfo summaryInfo) 1)
        (vla-SetCustomByIndex summaryInfo 0 CustomPropertyBranch PropertyBranchValue)
        (vla-AddCustomInfo summaryInfo CustomPropertyBranch PropertyBranchValue)
    )

    (if (>= (vla-NumCustomInfo summaryInfo) 2)
        (vla-SetCustomByKey summaryInfo CustomPropertyBranch "Satellite")
        (vla-AddCustomInfo summaryInfo CustomPropertyZone PropertyZoneValue)
    )

    ;; Get custom properties
    (vla-GetCustomByIndex summaryInfo 0 'Key0 'Value0)
    (setq Key1 CustomPropertyZone)
    (vla-GetCustomByKey summaryInfo Key1 'Value1)
  
    (alert (strcat "The custom drawing properties are "
                   "\nFirst property name = " Key0
                   "\nFirst property value = " Value0
                   "\nSecond property name = " Key1
                   "\nSecond property value = " Value1
           )
    )
)