Helping Changing LISP Code to Only Run on Certain Files

Helping Changing LISP Code to Only Run on Certain Files

joelmNKB6B
Enthusiast Enthusiast
691 Views
5 Replies
Message 1 of 6

Helping Changing LISP Code to Only Run on Certain Files

joelmNKB6B
Enthusiast
Enthusiast

I have a LISP file that is working great, but some changes to the workflow have created a new challenge.

 

I only want the LISP to run on filenames that start with "C2" or "C5".

 

For instance, I wouldn't want it to run on "C1.01.dwg" but I would want it to run on "C2.01.dwg".

 

The LISP is attached.

 

Thanks in advance!

0 Likes
Accepted solutions (1)
692 Views
5 Replies
Replies (5)
Message 2 of 6

paullimapa
Mentor
Mentor
Accepted solution

try this:

(defun c:foo (/ matchlst dwgnam12 s) ;"foo" is the name of the file, typing "foo" in the command line will intiate
 ; add to matchlst additional first two characters of dwgname to perform function
 (setq matchlst (list "C2" "C5") dwgnam12 (strcase(substr (getvar"dwgname") 1 2)))
 (if(member dwgnam12 matchlst)
  (if (setq s (ssget "_X" '((0 . "INSERT") (2 . "OFIMP_#_0,OFIMP_##_0")))) ;will account for block name "OFIMP_1_0" to "OFIMP_99_0"
    (foreach e (mapcar 'cadr (ssnamex s))
      (setpropertyvalue e "OLE_LINK" (strcat (vl-filename-base (getvar 'dwgname)) "!R1C1:R37C5")) ;attribute with tag "OLE_LINK" will have value of the file name minus .dwg extension with "!R1C1:R37C5" suffix
    )
  )
  (progn
   (princ(strcat"\nNot running this on Drawing Name starting with [" dwgnam12 "]."))(princ)
  )
 ) ; if dwgname match
  (princ)
)
(c:foo) ;this will make program run when file is opened. remove this and file will only run when "foo" is typed in command line

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 6

sollowyne
Enthusiast
Enthusiast
wonderful solutions
0 Likes
Message 4 of 6

paullimapa
Mentor
Mentor

glad to help...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 6

pbejse
Mentor
Mentor

Another option is to use wcmacth

(if (and (wcmatch (getvar "dwgname")  "C2.*,C5.*")
	 (setq (ssget "_X" '((0 . "INSERT") (2 . "OFIMP_#_0,OFIMP_##_0"))))
	)
...

HTH

0 Likes
Message 6 of 6

joelmNKB6B
Enthusiast
Enthusiast

thanks for the help, it appears to be working! If I run into issues I will try the 2nd solution.

 

Thanks!

0 Likes