Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LISP function to do a keyword search within a list

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
JustinTCox
458 Views, 10 Replies

LISP function to do a keyword search within a list

I am writing a LISP that takes a folder the user selects that contains 10 drawings in it, and takes those drawings and inserts them into their corresponding drawing that is on a network drive.  I had the LISP working perfectly if the user was able to select the network folder that contains the empty drawing and also selects the folder that contains the 10 drawings.  but now the problem is that user is not going to be able to select the network folder because of other issues.  The problem I am having is that there are several network folders that may contain the drawings they are working on.  I wrote a function that goes into the network drive and creates a directory list of every .dwg in the network drive.  but now I need a function to be able to go into that list and set a variable to just that directory that contains that same .dwg name. 

 

where it says XXXXX is where I am getting lost

 

(defun c:insertdesign (/ DirPath1 DirPath2 DwgA DwgB DwgList1 DwgList2 LstB OpFil ScrFil)
  (if (and (setq DirPath1 (SubFolderSearch "T:\\projects\\" ".dwg"))
	   (setq DirPath2 (BrowseForFolder "Select the folder containing the design drawings to INSERT."))
	   (/= DirPath1 DirPath2)
	   )
    (progn
      (setq DwgList1 (DirPath1)
	   DwgList2 (vl-directory-files DirPath2 "*.dwg" 1)
	    ScrFil "C:\\temp\\Temp.scr"
	    OpFil (open ScrFil "W")
      )
      (foreach Dwg DwgList2
	(if (setq LstB (member Dwg DwgList1))
	  (progn
	    (setq DwgA (XXXXXXXXXXXXXXXXX)
		  DwgB (strcat DirPath2 (car LstB))
	    )
(write-line (strcat "_.open " (chr 34) DwgA (chr 34)) OpFil)
	    (write-line "model" OpFil)
	    (write-line (strcat "_.-insert " (chr 34) (chr 42) DwgB (chr 34) " 0,0,0 1 0") OpFil)
	    (write-line "zoom extents" OpFil)
	    (write-line "layon" OpFil)
	    (write-line (strcat "ssx  layer " (chr 34) "level 34 " (chr 40) "construction" (chr 41) (chr 34) " ") OpFil)
	    (write-line "erase previous " OpFil)
	    (write-line "ssx  entity ellipse " OpFil)
	    (write-line "erase previous " OpFil)
	    (write-line "zoom extents" OpFil)
	    (write-line "flatten all  no" OpFil)
	    (write-line "ssx  color 2 " OpFil)
	    (write-line "erase previous " OpFil)
	    (write-line "ssx  color 3 " OpFil)
	    (write-line "erase previous " OpFil)
	    (write-line "ssx  color 7 " OpFil)
	    (write-line "erase previous " OpFil)
	    (write-line "ssx  color 30 " OpFil)
	    (write-line "erase previous " OpFil)
	    (write-line "ssx  entity 3dface " OpFil)
	    (write-line "erase previous " OpFil)
	    (write-line "ssx  entity solid " OpFil)
	    (write-line "erase previous " OpFil)
	    (write-line "ssx  entity text " OpFil)
	    (write-line "erase previous " OpFil)
	    (write-line "ssx  entity Mtext " OpFil)
	    (write-line "erase previous " OpFil)
	    (write-line "tilemode 0" OpFil)
	    (write-line "-layer new viewport plot no viewport " OpFil)
	    (write-line "ssx  entity viewport " OpFil)
	    (write-line "change previous  p la viewport " OpFil)
	    (write-line "-plot y layout1" OpFil)
	    (write-line "PRINTER" OpFil);;;;CHANGE TO YOUR DEFAULT PRINTER
	    (write-line "letter" OpFil)
	    (write-line "inches landscape no layout fit" OpFil)
	    (write-line "0.07,0.14" OpFil)
	    (write-line "yes monochrome.ctb" OpFil)
	    (write-line "yes no no no no yes no" OpFil)
	    (write-line "-insert overlay" OpFil)
	    (write-line "5.7640,0.0133,0.00 1 1 0" OpFil)
	    (write-line "-bedit tb_text" OpFil)
	    (write-line "change -1.53,0.53,0  -1.55,0.51,0 ROMAND 0.115 0 title3 enter title3" OpFil)
	    (write-line "TITLE3" OpFil)
	    (write-line "bsave bclose" OpFil)
	    (write-line "attsync name tb_text" OpFil)
	    (write-line "updatefield all " OpFil)
	    (write-line "mspace zoom extents pspace" OpFil)
	    (write-line "tbupdate" OpFil)
	    (write-line "qsave" OpFil)
	    (write-line "close" OpFil)
	    
	  );; progn
	  );; if
     );; foreach
     (close OpFil)
     (command "_.script" ScrFil)
   );; progn
    );; if
  (princ)
  );; inserts

 

10 REPLIES 10
Message 2 of 11
hmsilva
in reply to: JustinTCox

The "SubFolderSearch" function creates a list with the dwg names or with the dwg full path?

Henrique

EESignature

Message 3 of 11
JustinTCox
in reply to: hmsilva

its creates a list with the full path

Message 4 of 11
JustinTCox
in reply to: hmsilva

(defun SubFolderSearch (Path FileExt / tempPath FileList)

	(setq Path
		(if (= (substr Path (strlen Path)) "\\")
			Path
			(strcat Path "\\")
		);;if
	)
	(foreach file (vl-directory-files Path)
		(setq tempPath (strcat Path file))
		(if
			(not
				(or
					(= file ".")
					(= file "..")
				)
			)
			(if (vl-file-directory-p tempPath)
				(setq FileList (append FileList (SubFolderSearch tempPath FileExt)))
				(if (= (strcase FileExt) (strcase (vl-filename-extension tempPath)))
					(setq FileList (cons tempPath FileList))
				)
			)
		)
	)
	FileList
)

 

Message 5 of 11
hmsilva
in reply to: JustinTCox

Maybe something like this

 

(foreach Dwg DwgList2
  (if (and (setq DwgC (strcat (vl-filename-base Dwg) ".dwg"))
	   (setq LstB (member DwgC DwgList1))
	   );; and
    (progn
      (setq DwgA Dwg
	    DwgB (strcat DirPath2 (car LstB))
	    )

 

HTH

Henrique

EESignature

Message 6 of 11
JustinTCox
in reply to: hmsilva

wouldn't DwgA and DwgB the same?

Message 7 of 11
hmsilva
in reply to: JustinTCox

Sorry Justin, my bad...

I don't have AutoCAD with me, so is untested...

(progn
  (foreach x DirPath1
    (setq DwgNames1 (cons (strcat (vl-filename-base x) ".dwg") DwgNames1))
  )
  (setq DwgList1 DirPath1
	DwgList2 (vl-directory-files DirPath2 "*.dwg" 1)
	DwgNames1 (reverse DwgNames1)
	ScrFil "C:\\temp\\Temp.scr"
	OpFil (open ScrFil "W")
      )
      (foreach Dwg DwgList2
	(if (setq pos (vl-position Dwg DwgNames1))
	  (progn
	    (setq DwgA (nth pos DwgList1)
		  DwgB (strcat DirPath2 Dwg)
		  pos nil
	    )

 

Henrique

EESignature

Message 8 of 11
JustinTCox
in reply to: hmsilva

Henrique you once again provail!! just out of curiosity, why do you reverse DwgNames1?

also as a side question, do you know a function or script command to get default printer name?

Message 9 of 11
hmsilva
in reply to: JustinTCox


@JustinTCox wrote:

Henrique you once again provail!! just out of curiosity, why do you reverse DwgNames1?

also as a side question, do you know a function or script command to get default printer name?


The DwgNames1 list is created in reverse order from the DwgList1 list, to ensure the same order ( to use the nth function)I need to reverse the list.

The  'default printer name' is the Windows or the Document default printer?

 

Henrique

EESignature

Message 10 of 11
JustinTCox
in reply to: hmsilva

I am writing this LISP to be used by several people and they are in different buildings using differenct printers.  So when the Lisp writes the Script I want it to setup the default printer for the drawing to be the default "windows" printer that is assigned to their computer.

Message 11 of 11
hmsilva
in reply to: JustinTCox

Justin,

 

to get the default printer in the active layout

 

(setq aclyt (vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object)))
      lytplt (vla-get-ConfigName aclyt))

 

and the windows default printer

 

(setq win "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows"
      dev (vl-registry-read win "Device")
      winplt (substr dev 1 (vl-string-search "," dev)))

 You'll probably have to redefine the KEY depending on the OS...

 

HTH

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost