Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xref attachment routine

Status
Not open for further replies.

vbcad

Technical User
Jul 12, 2002
159
US
Below is a piece of code that function fine, however i would like to make it better(of course). The code lets me select a directory to use for the current folder and the opens another dialog to prompt for the actual reference name, it them renames the xref using the "wcmatch" statement. What I would like to do is do away with the dialog boxes. I need to select the current directory and then select the drawing I would like to use as an xref using wildcards. Area that needs revising is in red. Help please!

Code:
 ;START NEW ATTACH
        (COMMAND "CLAYER" "XREF-NEW")
        [red](setq dir
        (vl-filename-directory
	(getfiled "Select Drawing in directory desired..." "" "DWG" 4)
	)
	)
        (setq ref (getfiled "Select A1 plan..." dir "DWG" 16))
  	(COMMAND "-XREF" "ATTACH" ref "0,0" "1" "1" "0")[/red]
	(vlax-for blk (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object)))
		(if
			(and
				(equal (vla-get-IsXref blk) :vlax-true)
				(wcmatch (setq OldName (vla-get-Name blk)) "*a1")
			)
			(vla-put-Name blk "NEW"))
	  	)
	;END NEW ATTACH
 
I have tried this code and I am getting closer. The path selects fine and i can get the filename but I can't get the name to pass from the (setq ref... statement to the xref attach statement. Problem areas still in red.

Code:
  (setq dir (vl-filename-directory (getfiled "Select Drawing in directory desired..." "" "DWG" 4)))
	(setq ref (vl-directory-files dir "*a1.dwg"))[red];returns ("Go01a1.dwg")[/red]
  	[red](COMMAND "-XREF" "ATTACH" ref "0,0" "1" "1" "0")[/red]
	(vlax-for blk (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object)))
		(if
			(and
				(equal (vla-get-IsXref blk) :vlax-true)
				(wcmatch (setq OldName (vla-get-Name blk)) "*a1")
			)
 
Since "vl-directory-files" returns a list of files, you need to extract item from the list. Perhaps:

(setq ref (CAR (vl-directory-files dir "*a1.dwg")))

 
thanks works excellent. I knew I was getting close. one more item. Is there a better method of attaching the xref than the [red](COMMAND "-XREF" "ATTACH" ref "0,0" "1" "1" "0")[/red] statement?
 
Not that I know of (maybe with vba code), and if it works fine, why bother?
You could "internationalize" it and use reals & points instead of strings but it's essentially the same;

(command "_.-xref" "_attach" ref '(0.0 0.0 0.0) 1.0 1.0 0.0)
 
Correct me if i am wrong but isnt this line of code:
[red](setq dir (vl-filename-directory (getfiled "Select Drawing in directory desired..." "" "DWG" 4)))[/red] is supposed to set the directory for use? If I start a new drawing in "my doucuments" for example and browse to the directory where the drawings are stored for the xrefs, the program cant locate the drawings. If I start the new drawing in the folder where the xref drawings are located the program works fine. Am I missing something?
 
Yes "dir" includes the complete path, but "vl-directory-files" is a list of filenames, without the path.

To include the path with the filename, try this:

(setq refname (CAR (vl-directory-files dir "*a1.dwg")))
(setq refnamepath (strcat dir "\\" refname))
(COMMAND "-XREF" "ATTACH" refnamepath "0,0" "1" "1" "0")


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top