Autolisp - open xref by select

Autolisp - open xref by select

pietro.basta
Explorer Explorer
851 Views
15 Replies
Message 1 of 16

Autolisp - open xref by select

pietro.basta
Explorer
Explorer

Good evening

I need help to create simple lisp file that open a xref by selecting directly on it.

Foolowing screenshot autocad example:

pietrobasta_0-1636633961398.png

File open is named SS.DWG and it load 2 Xrefs, AB9.dwg and MC9.dwg

Is it possible to open the xref file AB.dwg or MC.dwg (it depends on which one you select it) without last digit (9).

They are resident in different folder, see below:

pietrobasta_1-1636634280099.png

Thank you very much,

Pietro

0 Likes
852 Views
15 Replies
Replies (15)
Message 2 of 16

Jason.Piercey
Advisor
Advisor

Try the XOPEN command 

0 Likes
Message 3 of 16

pietro.basta
Explorer
Explorer

Ciao Jason

thanks for your reply but using XOPEN command, Autocad directly open the xref selected resident in folder "TEST\00\07-Xrefs\".

I want the lisp routine identify the right filename of xrefs by clicking on it but "without 9" (last digit) and located in different folder. See pictures in original post.

Example if I select xrefname named AB9.dwg I want that autocad open xrefname AB.dwg in the folder "TEST\01\017-Xrefs_W\" ...... and NOT AB9.dwg

Many thanks

0 Likes
Message 4 of 16

ВeekeeCZ
Consultant
Consultant

Try this. You need to specify a project root dictionary first time you run it. 

 

(vl-load-com)

(defun c:XMother ( / e o p n f)
  
  ;; from _gile   https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vl-directory-files-for-subdirectories/m-p/7815896/highlight/true#M365740
  (defun allfiles (folder pattern)  ; (allfiles dir "*.dwg")
    (apply 'append
	   (cons (if (vl-directory-files folder pattern)
		   (mapcar '(lambda (x) (strcat folder "\\" x))
			   (vl-directory-files folder pattern)))
		 (mapcar '(lambda (x) (allfiles (strcat folder "\\" x) pattern))
			 (vl-remove ".." (vl-remove "." (vl-directory-files folder nil -1)))))))
  
  ; ---------------------------------------------------------------------------------------------------------

  (princ "\nSpecify project root dictionary in dialog... ")
  
  (if (and (setq e (car (entsel "\nSelect xref: ")))
	   (setq o (vlax-ename->vla-object e))
	   (vlax-property-available-p o 'path)
	   (setq p (vla-get-path o))
	   (setq p (substr p 1 (vl-string-position 92 p nil
				 T)))
	   (setq n (vla-get-name o))
	   (or *xm-root*
	       (and (setq p (lisped p))
		    (or (not (numberp p))
			(prompt "\nError: Buttons not supported."))
		    (setq *xm-root* (vl-string-right-trim "\\" p))))
	   (setq f (allfiles *xm-root* (strcat (vl-string-right-trim "0123456789$" n) ".dwg")))
	   )
    (vla-open (vla-get-documents (vla-get-application (vlax-get-acad-object))) (car f)))
  (princ)
  )

 

Edit: Code updated.

0 Likes
Message 5 of 16

pietro.basta
Explorer
Explorer

Hi thanks

it doesn't work, it open always the file with "9" at the end. More or less same as "XOPEN" command

0 Likes
Message 6 of 16

ВeekeeCZ
Consultant
Consultant

Well, it's not to me. 

Run the attached version and post back here the command-line listing.

Also, post a test file with xref... where it fails the same way.

0 Likes
Message 7 of 16

pietro.basta
Explorer
Explorer

Hi

attached small zip file with project sample tree.

Unzip and try to open the file "MC.dwg" in following path: "TEST\R-14XXX\04-Mechanical\047-Xrefs_W" and try to use your lisp routine by clicking the architectural xrefs (AB$.dwg).

The result should be to open the file AB.dwg resident in following path: "TEST\R-14XXX\01-Architectural\017-Xrefs_W"

Probably I made some mistake.

Many thanks

0 Likes
Message 8 of 16

ВeekeeCZ
Consultant
Consultant

I see no xrefs with a number at the end.

 

Z9E3zK5E_0-1636645414232.png

 

0 Likes
Message 9 of 16

pietro.basta
Explorer
Explorer

Yes You are right

I changed ... instead of numbers (9) I preferred to put a different digit ($) to make it easier to be identified.

Is it a problem with your routine lisp?

Sorry

0 Likes
Message 10 of 16

pietro.basta
Explorer
Explorer
Hi
I've changed following string:
(setq f (allfiles *xm-root* (strcat (vl-string-right-trim "012345678$" n) ".dwg")))
with $ digit and it works.
But just once, following if I try to open a second xref appear the message:
Command: XMOTHER
Specify root dictionary in dialog...
Select xref:
........ and do nothing.
0 Likes
Message 11 of 16

pietro.basta
Explorer
Explorer
Hi
the routine would be perfect if:
- worked not once but always digit command "Xmother"
- is possible to avoid to enter manually the root (normally I work on a server and we do not use to map network, so will be difficult to write it)
- the xref opened would be current (at moment return current the original file)
Thank you very much Z9E3zK5E for the help.
I'm sure he will be back soon to me
0 Likes
Message 12 of 16

ВeekeeCZ
Consultant
Consultant

#1 was fixed, the code was updated.

The others were considered and denied. You don't do copy-pasting?

0 Likes
Message 13 of 16

ronjonp
Mentor
Mentor

You want to open a file that has a similar name but not related to the drawing? 🤔 What is your workflow?

0 Likes
Message 14 of 16

pietro.basta
Explorer
Explorer

Yes, it is exactly like that. I'm not crazy.

The xref I want to open is strictly related to xref with different name.

One will be the working and the other the master that will be loaded and shared with the team.

0 Likes
Message 15 of 16

pietro.basta
Explorer
Explorer

Hi (don't know how have to call you .... nickname is complicated),

don't understand what you mean.

#1 fixed and updated, can you send it to me again? The rest, why denied?

Thanks for your answer

0 Likes
Message 16 of 16

ВeekeeCZ
Consultant
Consultant

Can't tell. It's a secret.

0 Likes