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

Drawing name set equal to a number from a provided list?

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
425 Views, 7 Replies

Drawing name set equal to a number from a provided list?

I have the need to make the current open dwg (name) equal to its predefined number in a large list. For example, building66.dwg is equal to 123789. I’ll have a large list in a tab delimited txt file with the example below. I can put the list in the lsp file if needed. Something like (if (getvar "dwgname") make equal to listname) and go out to the list and return its number. Seems kind of easy but I can’t make it happen. Any iseas?

 

 

building66.dwg 123789

building12.dwg 333789

building94.dwg 345789

7 REPLIES 7
Message 2 of 8
3wood
in reply to: Anonymous

The file name of current opened drawing is READ-ONLY. You have to close it before rename.

Message 3 of 8
Anonymous
in reply to: 3wood

Oh, not looking to rename the current open dwg. I just need to pluck a number from a list based on the current open dwg.
Message 4 of 8
3wood
in reply to: Anonymous

Maybe posting part of your code is easier for others to spot out the problem.

Message 5 of 8
pbejse
in reply to: Anonymous


@Anonymous wrote:
Oh, not looking to rename the current open dwg. I just need to pluck a number from a list based on the current open dwg.

 

(defun c:pluck (/ file data of a suff f)
  (if
    (and
      (= (getvar 'DwgTitled) 1)
      (setq data nil
	    file (getfiled "Select text file"
			   (getvar
			     'dwgprefix
			   )
			   "txt"
			   16
		 )
      )
      )
    (progn
	    (setq of (open file "r"))
	     (while (setq a (read-line of))
	       (if (setq suff (vl-string-position 32 a))
		 (setq data (cons (list	(strcase (substr a 1 suff))
					(substr a (+ 2 suff))
				  )
				  data
			    )
		 )
	       )
	     )
	    (close of)
	     (if (setq f (assoc (strcase (getvar 'dwgname)) data))
	       (print (cadr f))
	       (princ "\n<<<Drawing name not found>>>")
	       )
	     )
      )
(princ)
)

 

Or you can make this change this line to where the drawing.txt is located

 

(setq data nil
	    file (getfiled "Select text file"
			   (getvar
			     'dwgprefix
			   )
			   "txt"
			   16
		 )
      )

to

 

(setq data nil
      file (findfile "H:\\Documents and Settings\\pbe\\My Documents\\drawing list.txt"))

 Where the highlighted text is the permanent name and location of the txt file.

 

HTH

 

 

 

 

Message 6 of 8
Anonymous
in reply to: pbejse

Thanks for the quick replies!  Pardon my rustyness with this. It the code designed to read like the attached txt file? I got a <<<Drawing name not found>>> while in the FMAARABOF3.dwg. Anyway, I take it data or stuff will be the number value found in the file based on the dwg name?

Message 7 of 8
pbejse
in reply to: Anonymous


@Anonymous wrote:

Thanks for the quick replies!  Pardon my rustyness with this. It the code designed to read like the attached txt file? I got a <<<Drawing name not found>>> while in the FMAARABOF3.dwg. Anyway, I take it data or stuff will be the number value found in the file based on the dwg name?


I wasnt expecting the "\t" <tab> dilimeter

 

change this 

(setq suff (vl-string-position 32 a))

 to

 

(or (setq suff (vl-string-position 32 a))
		       (setq suff (vl-string-position 9 a)))

 

That way you can still use the code even if you are using a " " <space> dilimeted file

 

HTH

 

 

Message 8 of 8
Anonymous
in reply to: pbejse

Seems pbejse hit it right off the bat. That's working just as needed in early testing. Thanks!

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

Post to forums  

Autodesk Design & Make Report

”Boost