SOliver 发表于 2022-7-6 08:48:07

查询字典。带l的com

大家好,
 
我继续努力使Autocad成为一个通用界面,我写了一本小词典。com阅读器,我想我会和社区分享。
 


;Dict
;    Return the definitions for a given word.
(vl-load-com)
(defun c:dict( / query url xmlDoc pos posId posItem defs defId def )
   (princ "\n====== Online Dictionary reader ======")
   (setq query (getstring "\nEnter your query:"))
   (setq url (strcat"http://api-pub.dictionary.com/v001?vid=hqcw8ni3fld8ui0nxyoy6sbzxsub7gnp7zlfn4j3pw&type=define&q=" query))
   (if(and         
            (setq xmlDoc (vlax-create-object "MSXML.DOMDocument"))
            (not (vlax-put xmlDoc 'async 0))
            (= (vlax-invoke xmlDoc 'load url ) -1)
            (= 4 (vlax-get xmlDoc 'readyState)))
       (progn
         (setq pos (vlax-invoke-method xmlDoc 'getElementsByTagName "partofspeech"))
         (if(> (vlax-get pos 'length) 0)
               (progn
                   (setq posId -1)
                   (while (< (setq posId(1+ posId))(vlax-get pos 'length))
                     (setq posItem (vlax-get-property pos 'Item posId))
                     (princ (strcat "\n------\nPart of speech:    " (vlax-get (vlax-invoke-method (vlax-get-property posItem 'attributes) 'getNamedItem "pos") 'value)))
                     (setq defs (vlax-invoke-method posItem 'getElementsByTagName "def"))
                     (if(> (vlax-get defs 'length) 0)
                           (progn
                               (setq defId -1)
                               (while(< (setq defId(1+ defId)) (vlax-get defs 'length))
                                 (setq def (vlax-get-property defs 'Item defId))
                                 (princ (strcat "\n" (rtos (1+ defId) 2 0) ": " (vlax-variant-value(vlax-get-property def 'nodeTypedValue))))
                               )
                           )
                     )
                   )
               )
               (princ "\nNo results found")
         )
       )
   )
   (vlax-release-object xmlDoc)
   (princ)
)

注:
url中的vid值不是永久性的,如果有人打算长期使用该值,或者碰巧在将来阅读该值,并且看到acad打印文字到控制台的想法使其充满了fervor api键,可以从字典的网站上获得。
 
编辑:
更新的代码通知用户,他们的查询没有返回结果
页: [1]
查看完整版本: 查询字典。带l的com