- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Community,
I have a title block that contains several attributes. One of the attributes is a DWGREF (drawing reference).
Currently it just stores text (drawing number) typed by the designer.
My goal is to convert the attribute from text to a Field that stores a hyperlink.
This can all be done manually. My goal is to automate with AutoLISP or Visual Lisp.
I have searched the forums and tasked AI tools to write the code, but have been unsuccessful.
Here is the code I have so far:
;;; Convert attribute text to a field and hyperlink
;;;
(defun C:ConvertAttribToHyperlink (/
atttag blkAttribs blkData blkEnt blkName foundAttTag hyperlinkurl ss)
;; defaults
(setq blkName "MyBlockName" ;; block name
attTag "MyAttribTag" ;; attribute tag name
hyperlinkURL "http://example.com" ;; hhyperlink
) ;_setq
;; Create the selection set using ssget with filters:
(setq ss (ssget "_X" (list (cons 0 "INSERT") ;; Filter for block references (INSERT)
(cons 2 blkName)))) ;; Filter for block name
;; Check if the selection set is valid
(if ss
(progn
(setq blkEnt (ssname ss 0) ;; Get first block (for now) from selection set
blkData (entget blkEnt) ;; Get the entity data
) ;_setq
(if (and blkEnt blkData)
(progn
;; Get the block reference attributes
(setq blkAttribs (vlax-invoke (vlax-ename->vla-object blkEnt) 'GetAttributes))
;; Loop through attributes to find the attribute tag
(setq foundAttTag nil)
(foreach att blkAttribs
(if (= (vla-get-tagstring att) attTag)
(progn
(setq foundAttTag t) ;; Set flag if attribute found
;;;
;;; This is where I need to insert a field into the attribute
;;; and then set the field to store a hyperlink
;;;
) ;_progn
) ;_if
) ;_foreach
) ;_progn
) ;_if
) ;_progn
(princ (strcat "\nNo block named, '" blkName "' found in the drawing.")) ;; No blocks found
) ;_if
(princ)
) ;_C:ConvertAttribToHyperlink
(princ)
Lines 35 - 38 are where I would expect the conversion to occur.
I cannot determine how to "insert" a field into the attribute text.
Once the field is inserted, a hyperlink needs to be set in the field.
Here is some text I discovered when manually inserting the field and hyperlink:
I have attached a drawing with block and attribute that match the code.
Thank you for your time attention. I look forward to your replies.
Regards,
Jerry
P.S. I found this forum post, but it uses VB.NET
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Solved! Go to Solution.