LISP to Apply Attribute Hyperlink to Entities and keeping them after exploding block

LISP to Apply Attribute Hyperlink to Entities and keeping them after exploding block

lzedCB
Advocate Advocate
417 Views
3 Replies
Message 1 of 4

LISP to Apply Attribute Hyperlink to Entities and keeping them after exploding block

lzedCB
Advocate
Advocate

Hello folks,

 

I have a block that indicates the view of some photos/views and I'm using an attribute with Hyperlink field to accomplish that (number 2 of pic bellow). So, the user need to CTRL+Click in this attribute wth Hyperlink field to open the webpage with corresponding pic:

 

cubotopografia_0-1676219533160.png

 

I would like to be able to explode this block and still keep the Hyperlink inside the attribute OR to apply the hyperlink to all entities of the block and still keeping them after exploding the block. Is any way to do this via LISP? Another solution that I was trying was to use normal Dtext or Mtext with Fields to steal the attribute field with the Hyperlink, but it was not possible using formulas. Any effective or better way of doing that in AutoCAD?

 

Thanks in advance for any suggestions or help.

 

 

 

0 Likes
Accepted solutions (1)
418 Views
3 Replies
Replies (3)
Message 2 of 4

Moshe-A
Mentor
Mentor

@lzedCB hi,

 

Although i do not understand why one want to do such a thing but this was nice challenge to code 😀

and here is how it works:

if the selected block(s) has attributes + hyperlink, it will be explode and any ATTDEF inside will be set with the block hyperlink data - works?

 

enjoy

Moshe

 

(vl-load-com)

(defun c:hexp (/ attdef->text ; local function
	         ss AcDbBlkRef attributes hyperlinks first ent anchor elist0 elist1)

 (defun attdef->text (e)
  (entmake
   (append
    (list '(0 . "TEXT") '(72 . 4))
    (vl-remove-if
     '(lambda (dxf)
       (member (car dxf) '(-1 0 2 3 5 70 72 74 100 102 280 330 347 360 370 440)) ; eliminate these dxf codes from elist
      )
     e
    ); vl-remove-if
   ); append
  ); entmake
 ); attdef->text


 ; here start c:hexp 
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")
  
 (if (setq ss (ssget '((0 . "insert") (2 . "CUBO-T-SMB-VISTA.FOTO,`*U*"))))
  (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
   (setq AcDbBlkRef (vlax-ename->vla-object ename))
    
   (if (and
	 (eq (strcase (vla-get-effectiveName AcDbBlkRef)) "CUBO-T-SMB-VISTA.FOTO")
	 (eq (vla-get-hasAttributes AcDbBlkRef) :vlax-true)
       )
    (progn
     (foreach AcDbAttrib (vlax-invoke AcDbBlkRef 'getAttributes)
      (setq attributes (cons (cons (strcase (vla-get-tagString AcDbAttrib)) (vla-get-textString AcDbAttrib)) attributes))
      (vlax-release-object AcDbAttrib) 
     ); vlax-for

     (setq hyperlinks nil)
     (vlax-for AcDbHyperLink (vla-get-hyperlinks AcDbBlkRef)
      (setq hyperlinks (append hyperlinks (list (vla-get-URL AcDbHyperLink) (vla-get-URLNamedLocation AcDbHyperLink) (vla-get-URLdescription AcDbHyperLink))))
      (vlax-release-object AcDbHyperLink) 
     ); vlax-for

     (if hyperlinks
      (progn
       (command "._point" "0,0,0")	
       (setq anchor (entlast) ent anchor)
       (command "._explode" ename)
       (while (setq ent (entnext ent))
        (setq elist0 (entget ent))
	(if (eq (cdr (assoc '0 elist0)) "ATTDEF")
	 (progn
	  (setq elist1 (attdef->text elist0))
	  (entmod (subst (cons '1 (cdr (assoc (strcase (cdr (assoc '2 elist0))) attributes))) (assoc '1 elist1) elist1))
	  (command "._-hyperlink" "_insert" "_object" "_si" (entlast) (car hyperlinks) (cadr hyperlinks) (caddr hyperlinks))
	  (entdel ent)
	 ); progn
	); if
       ); while
       (entdel anchor)
      ); progn
     ); if
       
    ); progn
   ); if

   (vlax-release-object AcDbBlkRef) 
  ); foreach
 ); if

 (command "._undo" "_end")
 (setvar "cmdecho" 1)

 (princ)
); c:hexp

 

0 Likes
Message 3 of 4

Sea-Haven
Mentor
Mentor

I had add photos from mobile phone you can get the lat and long from the photos, no angle, it would add to plan, a few metres wrong but not bad compared to real world co-ords. Used CIV3D before you ask supports Lat long.

0 Likes
Message 4 of 4

komondormrex
Mentor
Mentor
Accepted solution

why explode? convert dynamic block to static and apply hyperlink to it, so clicking on a latter takes you to a hyperlinked image.

0 Likes