Jump to content

Changing LISP to select and zoom to found items


Recommended Posts

Posted

Hey all,

Hopefully someone can help me out with this as I really am not very good at LISP at all, I find it very hard to follow even though I use other programming languages regularly.

A while ago someone on this forum was kind enough to help me make a script which will search a CAD drawing for blocks containing two specific attributes. The script works great and is very handy because obviously Find/Search/Replace can only look for one attribute, so for example we may want to find a tag "TT2010" and if we used the built in search function, we could only find either all "TT" tags or all "2010" tags- of which there are many.

I would like to somehow edit the script to select the tag(s) it finds so it operates in just the same way as the built in search function. I have had a look around a few forums and tutorials on the internet but as I said, I find the code very hard to follow. However I assume that what I am trying to do is very simple.

Any help would be greatly appreciated and here is the existing LISP code:

 

(defun c:Tag()
 (setq ss (ssget "X" (list '(0 . "INSERT") '(66 . 1))))
 (setq a1 (getstring "\n1st attribute to search for ")
   a2 (getstring "\n2nd attribute to search for ")
   found 0
   )
 (repeat (setq i (sslength ss))
   (if (check (ssname ss (setq i (1- i))) a1 a2) (setq found (1+ found)))
(ssget "_X" '((0 . "INSERT") (2 . a1 a2)))
   )
 (strcat " ---> " (itoa found) " Tags Found with that name")
 )
(defun check (en a1 a2)
 (setq hit 0 a0 (cdr (assoc 0 (setq el (entget en)))))
 (while (/= a0 "SEQEND")
   (if (= a0 "ATTRIB") (if (member (cdr (assoc 1 el)) (list a1 a2)) (setq hit (1+ hit))))
   (setq a0 (cdr (assoc 0 (setq el (entget (setq en (entnext en)))))))
   )
 (= hit 2)
 )

 

Thanks in advance,

lifeis

Posted

maybe something like this, re zoom you can also use vl-get-insertionpoint then Z C scale

 

(setq oldtag1 "DRAWING_STATUS") ;attribute tag name
(setq newstr1 "ISSUED FOR CONSTRUCTION")
(setq oldtag2 "REV_NO")  ;attribute tag name
(setq newstr2 "0")
(setq ss1 (ssget "x"  '((0 . "INSERT") (2 . "DA1DRTXT"))))
(setq inc (sslength ss1))
(repeat inc      
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 (setq inc (1- inc)) )) 'getattributes)
(if (= oldtag1 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr1) 
) ; end if
(if (= oldtag2 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr2) 
) ; end if
) ; end for
) ;end repeat

Posted
BIGAL

maybe something like this, re zoom you can also use vl-get-insertionpoint then Z C scale

 

Thanks for your reply.

I have tried playing around with your script but I just cant get it to run.

Where in the code is the part that selects the object?

And would I just add it here:

(defun c:Tag()
 (setq ss (ssget "X" (list '(0 . "INSERT") '(66 . 1))))
 (setq a1 (getstring "\n1st attribute to search for ")
   a2 (getstring "\n2nd attribute to search for ")
   found 0
   )
 (repeat (setq i (sslength ss))
   (if (check (ssname ss (setq i (1- i))) a1 a2) (setq found (1+ found)))
(ssget "_X" '((0 . "INSERT") (2 . a1 a2)))
**CODE TO SELECT OBJECT?**
   )
 (strcat " ---> " (itoa found) " Tags Found with that name")
 )
(defun check (en a1 a2)
 (setq hit 0 a0 (cdr (assoc 0 (setq el (entget en)))))
 (while (/= a0 "SEQEND")
   (if (= a0 "ATTRIB") (if (member (cdr (assoc 1 el)) (list a1 a2)) (setq hit (1+ hit))))
**CODE TO SELECT OBJECT?**
   (setq a0 (cdr (assoc 0 (setq el (entget (setq en (entnext en)))))))
   )
 (= hit 2)
 )

 

As I said, I find LISP very hard to follow, so I amn't even sure what the variable defined with the object is called (Im guessing its "a1 & a2" or "en a1 a2" if thats how you concatenate in LISP).

So I just need to add code to select at the second while loop and variables a1 a2 should contain the tag data, so some pseudo code may look like-

Add 1 to the hit variable for each found

Highlight/Zoom to a1 a2

Is this correct and if so, what code do I add there to make the selection?

Thank you very much for your help, its appreciated.

-Craig

Posted

Another thing to note is that 99% of the time, only one tag will be found (if more than one is found then this is a mistake) so the script should not have a problem highlighting or zooming to the selection.

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