Hi! Anyone know how to put in text from attribute and create URL link of the text?
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
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.
There are many threads in this discussion group that can help you with this. Here are some examples: Extract text values from attributes: http://discussion.autodesk.com/thread.jspa?messageID=1221364 Creating a hyperlink with a program: http://discussion.autodesk.com/thread.jspa?messageID=1960616 Dave
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 ) )
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 ) )
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
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??
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
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?
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