Jump to content

Recommended Posts

Posted

Hi all,

 

I'm try to build a lisp program to link content of a text and attributes/text.

 

Somehow I manage to place the values in side the attribute with example code references. When comes to introduce a reactor to maintain the sync between the contents I can't. Thus, this text sync can be done with Field but If someone delete the source then its mess. So I came up with this idea.

 

text has the format like SEC_NO,TAG_NO,FLAG_NO. Those would link with same tag named attribute and the copy of blocks as well. Once master text value change the respective values in attribute would change (See snap). if it turns hard, text to text would save tons of time and can use with multiple times.

 

Thanks in advance.

 

harimadhavan66_0-1754117417820.png.178f4779127c704ce30b84ef1e5382ec.png

trail.lsp TextSync.dwg

Posted

There is vlr-object-reactor, which can call a defun like your lisp. i dont know how though you would pass it the correct block object to change. If you make the text a block then you could have a invisible attribute which is the handle ID of the matching block. 

 

https://www.google.com/search?q=reactor+object+cahnged+autocad+lisp&sca_esv=3b7e4dc23e2c7901&source=hp&ei=KKWOaOmOLsaU4-EPgIS0-Qk&iflsig=AOw8s4IAAAAAaI6zOGqTE_bufe0aJLcdS0xRbMY74k-X&ved=0ahUKEwjpwoS9qe2OAxVGyjgGHQACLZ8Q4dUDCA8&uact=5&oq=reactor+object+cahnged+autocad+lisp&gs_lp=Egdnd3Mtd2l6IiNyZWFjdG9yIG9iamVjdCBjYWhuZ2VkIGF1dG9jYWQgbGlzcDIHECEYoAEYCjIFECEYnwVI4lFQgwpY-ExwAXgAkAEAmAGWAqAB1TWqAQcwLjE4LjE3uAEDyAEA-AEBmAIkoALFNqgCCsICChAAGAMY6gIYjwHCAgsQABiABBixAxiDAcICCxAuGIAEGLEDGIMBwgIREC4YgAQYsQMY0QMYgwEYxwHCAg4QLhiABBixAxiDARiKBcICDhAAGIAEGLEDGIMBGIoFwgIIEAAYgAQYsQPCAg4QLhiABBixAxjRAxjHAcICCxAuGIAEGNEDGMcBwgIOEAAYgAQYsQMYgwEYyQPCAg4QABiABBixAxiSAxiDAcICCxAAGIAEGJIDGIoFwgIUEC4YgAQYsQMYgwEYxwEYjgUYrwHCAggQLhiABBixA8ICDhAuGIAEGMcBGI4FGK8BwgIFEAAYgATCAgUQLhiABMICBhAAGBYYHsICCBAAGBYYChgewgILEAAYgAQYhgMYigXCAgUQABjvBcICCBAAGIAEGKIEwgIIEAAYogQYiQXCAgUQIRigAcICBhAhGBUYCpgDBvEFDVTDEYK0XNeSBwcxLjE4LjE3oAfdwwGyBwcwLjE4LjE3uAe-NsIHBzExLjE3LjjIB04&sclient=gws-wiz
 

You could do a lisp that saves the two objects handles and use the reactor on close, save & quit to update via lisp the objects. I have used save etc to do something. I use ldata to save values in a dwg so you would have one data value which is how many, then you would have multiple values saved. The other method is to use Xdata on say the text saving the block ID. Again the handle. Doing the text on specific layers may make it fast to check v's getting all text in the dwg.

 

 

 

 

  • 2 weeks later...
Posted

Hi sir, @BIGAL

 

It's a late reply but I try to figure out the ways as you said.

 

I just simply made a seperate command, instead reactor based approach. That is too complicated and I'm not that much expert.

I have used seperate commands to update linked texts. Now I'm trying to use this on multiple sessions while open/close and reopen the DWG file. But i couldn't fix that. Kindly help with update. Also could possible to link the attribute, block inside text contents?.

 

(vl-load-com)

;; Global storage for set/view links
(setq *set-view-links* nil)

(defun c:LINKTEXT (/ set views m-handle s-handles)
  (prompt “\nSelect the SET TEXT or MTEXT: “)
  (setq set (car (entsel)))
  (if (and set
           (wcmatch (cdr (assoc 0 (entget set))) “TEXT,MTEXT”))
    (progn
      ;; Change set text color to red for identification
      (entmod (subst (cons 62 1) (assoc 62 (entget set)) (entget set)))
      (entupd set)

      (setq m-handle (cdr (assoc 5 (entget set))))

      ;; Select views
      (prompt “\nSelect VIEW TEXT or MTEXT entities: “)
      (setq views (ssget ‘((0 . “TEXT,MTEXT”))))

      (if views
        (progn
          (setq s-handles ‘())
          (repeat (sslength views)
            (setq ent (ssname views 0))
            (ssdel ent views)
            (setq s-handles (cons (cdr (assoc 5 (entget ent))) s-handles))
            ;; Immediately match text
            (vla-put-TextString
              (vlax-ename->vla-object ent)
              (cdr (assoc 1 (entget set)))
            )
          )
          ;; Store link pair in global var
          (setq *set-view-links*
                (cons (list m-handle s-handles) *set-view-links*))
          (prompt “\nSet linked to views.”)
        )
        (prompt “\nNo view text selected.”)
      )
    )
    (prompt “\nInvalid set entity.”)
  )
  (princ)
)

(defun c:SYNCSET (/ link m-ent s-handles m-obj m-text s-obj)
  (if *set-view-links*
    (progn
      (foreach link *set-view-links*
        (setq m-ent (handent (car link)))
        (if m-ent
          (progn
            (setq m-text (cdr (assoc 1 (entget m-ent))))
            (foreach s-handle (cadr link)
              (setq s-obj (handent s-handle))
              (if s-obj
                (vla-put-TextString
                  (vlax-ename->vla-object s-obj)
                  m-text
                )
              )
            )
          )
        )
      )
      (prompt “\nAll view texts updated from their sets.”)
    )
    (prompt “\nNo set-view links found.”)
  )
  (princ)
)

(defun c:SELECTLINKED (/ pick handle result)
  (prompt “\nPick any linked text (set or view): “)
  (setq pick (car (entsel)))
  (if pick
    (progn
      (setq handle (cdr (assoc 5 (entget pick))))
      (setq result (ssadd))
      (foreach link *set-view-links*
        (cond
          ;; If picked is set
          ((equal (car link) handle)
           (ssadd (handent (car link)) result)
           (foreach s-h (cadr link)
             (ssadd (handent s-h) result)
           )
          )
          ;; If picked is view
          ((member handle (cadr link))
           (ssadd (handent (car link)) result)
           (foreach s-h (cadr link)
             (ssadd (handent s-h) result)
           )
          )
        )
      )
      (if (> (sslength result) 0)
        (progn
          (sssetfirst nil result)
          (princ (strcat “\nSelected “ (itoa (sslength result)) “ linked texts.”))
        )
        (prompt “\nNo linked texts found.”)
      )
    )
    (prompt “\nNothing selected.”)
  )
  (princ)
)

(defun c:UNLINKVIEW (/ set views m-handle)
  (prompt “\nSelect SET TEXT: “)
  (setq set (car (entsel)))
  (if set
    (progn
      (setq m-handle (cdr (assoc 5 (entget set))))
      (prompt “\nSelect VIEWS to unlink: “)
      (setq views (ssget ‘((0 . “TEXT,MTEXT”))))
      (if views
        (foreach link *set-view-links*
          (if (equal (car link) m-handle)
            (progn
              (setq new-views (vl-remove-if
                                 ‘(lambda (h)
                                    (ssmemb (handent h) views))
                                 (cadr link)))
              (setq *set-view-links*
                    (subst (list m-handle new-views) link *set-view-links*))
            )
          )
        )
        (prompt “\nNo views selected.”)
      )
    )
    (prompt “\nInvalid set.”)
  )
  (princ)
)

(defun WarnIfDeletingSet (/ e)
  (if (and e (member (cdr (assoc 5 (entget e))) (mapcar ‘car *set-view-links*)))
    (alert “WARNING: You are deleting a SET text linked to other texts!”)
  )
)

;; Add reactor for delete warning
(vlr-command-reactor
  Nil
  ‘((:vlr-commandWillStart . 
     (lambda (reactor cmd)
       (if (wcmatch (strcase cmd) “ERASE”)
         (progn
           (setq ss (ssget “_I”))
           (if ss
             (repeat (sslength ss)
               (WarnIfDeletingSet (ssname ss (setq idx (1- (sslength ss)))))
             )
           )
         )
       )
     )
   )
  )
)

(prompt “\nCommands: LINKTEXT, SYNCSET, SELECTLINKED, UNLINKVIEW”)
(princ)


 

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...