URL and Lisp

Discussion in 'AutoCAD' started by UnderdogNo1, Nov 8, 2004.

  1. UnderdogNo1

    UnderdogNo1 Guest

    Hi!
    Anyone know how to put in text from attribute and create URL link of the text?
     
    UnderdogNo1, Nov 8, 2004
    #1
  2. UnderdogNo1

    dblaha Guest

    Could you provide a specific example of what you are trying to do?--what you're starting with and what you want to end up with?

    Dave
     
    dblaha, Nov 8, 2004
    #2
  3. UnderdogNo1

    UnderdogNo1 Guest

    I try to get text from an attribute and put i to an url For ex. Attribute text 1256 and put in a urllink called
    http://example/nisse.asp=1256 if it not exist create urllink.
     
    UnderdogNo1, Nov 8, 2004
    #3
  4. UnderdogNo1

    dblaha Guest

    dblaha, Nov 8, 2004
    #4
  5. UnderdogNo1

    UnderdogNo1 Guest

    Thanks for the help!
     
    UnderdogNo1, Nov 9, 2004
    #5
  6. UnderdogNo1

    UnderdogNo1 Guest

    Trid but i cant seem to get it right. The text wint get in as an hyperlink. Heres the Code:
    (defun c:atv (/ blk)
    (setq blk_data nil
    ; clear if any values
    blk (entsel "\nSelect Block with Attributes:"))
    (setq blk2 blk)
    (if blk
    (progn
    (setq blk (entget (car blk)))
    (while blk
    (setq blk (entget (entnext (cdr (assoc -1 blk)))))
    (if (assoc 1 blk)
    (setq blk_data (append blk_data (list (cdr (assoc 1 blk)))))
    )
    (if (not (= (cdr (assoc 0 blk)) "ATTRIB"))(setq blk nil))
    )))

    (setq newlink (read (blk_data)))
    (setq ent (car (entsel)))
    (setq obj (vlax-ename->vla-object ent))
    (setq hy (vlax-get-property obj 'hyperlinks))
    (vlax-invoke-method hy 'Add newlink )
    )
     
    UnderdogNo1, Nov 9, 2004
    #6
  7. UnderdogNo1

    UnderdogNo1 Guest

    Checked something but still get "Select Block with Attributes:; error: bad association list: ("1235")" 1235 is the value of the attribute. New code:
    (defun c:atv (/ blk)
    (setq blk_data nil
    ; clear if any values
    blk (entsel "\nSelect Block with Attributes:"))
    (setq blk2 blk)
    (if blk
    (progn
    (setq blk (entget (car blk)))
    (while blk
    (setq blk (entget (entnext (cdr (assoc -1 blk)))))
    (if (assoc 1 blk)
    (setq blk_data (append blk_data (list (cdr (assoc 1 blk)))))
    )
    (if (not (= (cdr (assoc 0 blk)) "ATTRIB"))(setq blk nil))
    )))

    (setq newlink (entget (entnext (cdr (assoc 1 blk_data)))))
    ;(setq ent (car (entsel)))
    (setq obj (vlax-ename->vla-object blk))
    (setq hy (vlax-get-property obj 'hyperlinks))
    (vlax-invoke-method hy 'Add newlink )
    )
     
    UnderdogNo1, Nov 9, 2004
    #7
  8. UnderdogNo1

    dblaha Guest

    Here it is with several changes:

    (defun c:atv (/ blk blk_data)
    (setq blk (car (entsel "\nSelect Block with Attributes:")))
    (if blk
    (progn
    (setq blk (entnext (cdr (assoc -1 (entget blk)))))
    (while blk
    (setq blk_ent (entget blk))
    (if (setq blk_val (cdr (assoc 1 blk_ent)))
    (setq blk_data (append blk_data (list blk_val)))
    )
    (if (not (= (cdr (assoc 0 blk_ent)) "ATTRIB"))
    (setq blk_ent nil)
    )
    (setq blk (entnext (cdr (assoc -1 blk_ent))))
    )
    )
    )
    (setq newlink (car blk_data))
    (setq obj (vlax-ename->vla-object blk))
    (setq hy (vlax-get-property obj 'hyperlinks))
    (vlax-invoke-method hy 'Add newlink )
    )

    Note that, as it is right now, this routine will collect all attribute values that are present in the selected block but will only create a hyperlink based on the first attribute it found.

    Dave
     
    dblaha, Nov 9, 2004
    #8
  9. UnderdogNo1

    UnderdogNo1 Guest

    Hi!
    I still cant get it to work. It only returns:
    error: bad argument type: lentityp nil
    I've tried to use block with only one attribute to and it doesn't work. Got any clue??
     
    UnderdogNo1, Nov 10, 2004
    #9
  10. UnderdogNo1

    Jürg Menzi Guest

    Hi UnderdogNo1

    This one should do the job:
    Code:
    (defun C:ATV ( / AcaDoc AttTxt ColCnt CurEnt CurObj ExLoop LnkCol)
    (vl-load-com)
    (while (not ExLoop)
    (initget " ")
    (setq CurEnt (entsel "\nSelect Attribute <exit>: "))
    (cond
    ((eq CurEnt "") (setq ExLoop T))
    ((not CurEnt) (princ "1 selected, 0 found. "))
    ((not
    (eq
    (vla-get-ObjectName
    (setq CurObj (vlax-ename->vla-object (car (nentselp (cadr CurEnt)))))
    )
    "AcDbAttribute"
    )
    )
    (princ "Selected object is not an Attribute. ")
    )
    (T
    (setq AcaDoc (vla-get-ActiveDocument (vlax-get-acad-object))
    AttTxt (vla-get-TextString CurObj)
    LnkCol (vla-get-Hyperlinks (vlax-ename->vla-object (car CurEnt)))
    ColCnt 0
    )
    (vla-StartUndoMark AcaDoc)
    (repeat (vla-get-Count LnkCol)
    (vla-Delete (vla-Item LnkCol ColCnt))
    (setq ColCnt (1+ ColCnt))
    )
    (vla-Add LnkCol AttTxt)
    (princ (strcat "Hyperlink '" AttTxt "' added."))
    (vla-EndUndoMark AcaDoc)
    )
    )
    )
    (princ)
    )
    
    Cheers
     
    Jürg Menzi, Nov 10, 2004
    #10
  11. UnderdogNo1

    UnderdogNo1 Guest

    Thank You! It worked very well!!!
     
    UnderdogNo1, Nov 10, 2004
    #11
  12. UnderdogNo1

    Jürg Menzi Guest

    Welcome...¦-)

    Cheers
     
    Jürg Menzi, Nov 10, 2004
    #12
  13. UnderdogNo1

    UnderdogNo1 Guest

    I'd like to add a couple of things to the url link. Blockname and text from a textfile and some free text. For example:
    Blockname called room with value 1212 in attribute and the text from file http://verynice/
    would be result http://verynice/room.asp?qs=1212
    Is that possible to do?
     
    UnderdogNo1, Nov 10, 2004
    #13
  14. UnderdogNo1

    Jürg Menzi Guest

    Hi UnderdogNo1

    Sure...
    Code:
    (defun C:ATV ( / AcaDoc BlkObj ColCnt CurEnt CurObj ExLoop LnkCol LnkStr)
    (vl-load-com)
    (while (not ExLoop)
    (initget " ")
    (setq CurEnt (entsel "\nSelect Attribute <exit>: "))
    (cond
    ((eq CurEnt "") (setq ExLoop T))
    ((not CurEnt) (princ "1 selected, 0 found. "))
    ((not
    (eq
    (vla-get-ObjectName
    (setq CurObj (vlax-ename->vla-object (car (nentselp (cadr CurEnt)))))
    )
    "AcDbAttribute"
    )
    )
    (princ "Selected object is not an Attribute. ")
    )
    (T
    (setq AcaDoc (vla-get-ActiveDocument (vlax-get-acad-object))
    BlkObj (vlax-ename->vla-object (car CurEnt))
    LnkCol (vla-get-Hyperlinks BlkObj)
    LnkStr (strcat
    (FunctionToGetTextFromFile) ;Your file reading function
    (vla-get-Name BlkObj)
    ".asp?qs=" (vla-get-TextString CurObj)
    )
    ColCnt 0
    )
    (vla-StartUndoMark AcaDoc)
    (repeat (vla-get-Count LnkCol)
    (vla-Delete (vla-Item LnkCol ColCnt))
    (setq ColCnt (1+ ColCnt))
    )
    (vla-Add LnkCol LnkStr)
    (princ (strcat "Hyperlink '" LnkStr "' added."))
    (vla-EndUndoMark AcaDoc)
    )
    )
    )
    (princ)
    )
    
    It's in your own responsibility to add a function to read the text file.
    I've add a function named 'FunctionToGetTextFromFile'. You can replace
    it with your own file reading function because I don't know the key and
    format of a given text file.
    And finally I wish to correspond with a real (not a nick) name.

    Cheers
     
    Jürg Menzi, Nov 10, 2004
    #14
  15. UnderdogNo1

    UnderdogNo1 Guest

    Thank you very much. I will trie and get it right,
    sincerely
    Thomas Ranhem
    CadCoordinator
     
    UnderdogNo1, Nov 11, 2004
    #15
  16. UnderdogNo1

    Jürg Menzi Guest

    Hi Thomas

    Glad to help you...¦-)

    Cheers
     
    Jürg Menzi, Nov 11, 2004
    #16
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.