Jump to content

Recommended Posts

Posted (edited)

Hi folks,

 

Continuing my apparent quest to make Autocad a universal interface I wrote a small dictionary.com reader which I thought I'd share with community.

 


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

Note:

The vid value within the url isn't permanent, in the event someone intends on using this long term or happen to be reading this a bit in the future and the idea of seeing acad print words to the console fills them with fervor api keys are available from the dictionary's website.

 

Edit:

Updated code inform the user that their query returned no results

Edited by SOliver

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...