×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

xref attachment routine

xref attachment routine

xref attachment routine

(OP)
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")
        (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")

    (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

RE: xref attachment routine

(OP)
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"));returns ("Go01a1.dwg")
      (COMMAND "-XREF" "ATTACH" ref "0,0" "1" "1" "0")
    (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")
            )

RE: xref attachment routine

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")))

RE: xref attachment routine

(OP)
thanks works excellent. I knew I was getting close. one more item. Is there a better method of attaching the xref than the (COMMAND "-XREF" "ATTACH" ref "0,0" "1" "1" "0") statement?

RE: xref attachment routine

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)

RE: xref attachment routine

(OP)
Correct me if i am wrong but isnt this line of code:
 (setq dir (vl-filename-directory (getfiled "Select Drawing in directory desired..." "" "DWG" 4))) 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?

RE: xref attachment routine

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")


RE: xref attachment routine

(OP)
Thank you problem solved!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close