Lisp to list layer xrefs inserted on

Lisp to list layer xrefs inserted on

ralstogj
Collaborator Collaborator
5,429 Views
27 Replies
Message 1 of 28

Lisp to list layer xrefs inserted on

ralstogj
Collaborator
Collaborator

Hi, Guys

I am tying to piece together a piece of lisp code that will look at all the xrefs in a drawing and find what layer they are inserted on and then print the xref name and the layer at the command line. I found this example for listing the paths Example of Listing Paths. It that does something similar to what I want. I have tried for a couple of hours to re write to give the layer name with on luck below is my code so far. If some one could get it working that would be appreciated so long since I did lisp I have forgotten most things.

 

 

 

 

(defun c:xreflayers ()
(vl-load-com)
(vlax-for item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
(if (= (vla-get-isxref item) :vlax-true)

(setq oLayer(vla-item(vla-get-layers(vla-get-activedocument (vlax-get-acad-object)))));; oxref layer
(setq layerName (cdr (assoc 8 (entget oLayer))))


)

(princ (strcat "\nXref name: "(vla-get-name item)" --- Layer: " layername)
)
)
(princ)
)

Regards

Justin Ralston
http://c3dxtreme.blogspot.com/
0 Likes
Accepted solutions (1)
5,430 Views
27 Replies
Replies (27)
Message 2 of 28

pbejse
Mentor
Mentor
Accepted solution

@ralstogj wrote:

Hi, Guys

I am tying to piece together a piece of lisp code that will look at all the xrefs in a drawing and find what layer they are inserted on and then print the xref name and the layer at the command line.


(defun c:xreflayers nil

  (vl-load-com)
  (vlax-for layout (vla-get-layouts
		     (vla-get-activedocument (vlax-get-acad-object))
		   )
    (vlax-for i	(vla-get-block layout)
      (if (and
	    (eq (vla-get-ObjectName i) "AcDbBlockReference")
	    (vlax-property-available-p i 'Path)
	  )
	(princ (strcat "\nXref name: " (vla-get-Name i)
		       " --- Layer: "  (vla-get-Layer i)
	       )
	)
      )
    )
  )
  (princ)
  )
Message 3 of 28

braudpat
Mentor
Mentor

Hello Mr @pbejse

 

1) Thanks for our excellent routine : XrefLayersList

 

2) Please could you give us 4 other variants (for the other XREFs) :

 

XrefImagesList , XrefPdfsList , XrefDgnsList , XrefDwfsList

 

Thanks in advance, Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 4 of 28

ralstogj
Collaborator
Collaborator

Thanks Patrick work a treat.

Regards

Justin Ralston
http://c3dxtreme.blogspot.com/
0 Likes
Message 5 of 28

pbejse
Mentor
Mentor

@ralstogj wrote:

Thanks Patrick work a treat.


 

Nice.

You are welcome. 

 

 

0 Likes
Message 6 of 28

pbejse
Mentor
Mentor

@braudpat wrote:

 

2) Please could you give us 4 other variants (for the other XREFs) :

 

 

 


 

Would you want a prompt to choose the type of XREF underlay or five different commands?

 

 

Message 7 of 28

braudpat
Mentor
Mentor

Hello @pbejse

 

Thanks for your effort ! ... Well in fact, I have a dream !

 

I am ambitious for these routine : SORRY !

 

1) The routine can be run from the Keyboard and from a Script !

 

2) Questions: A for ALL types , D for DWG , N for DGN , F for DWF , P for PDF , I for Image

 

3) Question: C for Current Space (Model or Layout) or A for ALL Spaces (Model + All Layouts)

 

4) Question: Result on text/command screen (T option) or into a text Tile (F  option)

If F ask for the filename ?

If existing file: Replace or Append

 

5) Please add the layer name on which is inserted the XREF !

 

So the result will be a 3 columns text ...

 

NOW the routine is much more COMPLEX !

 

Thanks in advance, Regards, Patrice (The French EE Froggy)

 

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 8 of 28

pbejse
Mentor
Mentor

@braudpat wrote: 

NOW the routine is much more COMPLEX !

 


 

Smiley Surprised Now I regretted asking the question, I will work on Patrice, hang in there.

 

 

 

Message 9 of 28

pbejse
Mentor
Mentor

=========================================

Status --->  WIP 

=========================================

command: XREFUnderlay 

Choose type [All/Dwg/dGn/dwF/PDF/Image] <All>: ⏎ 

Layout to process [Current/All] <All>: ⏎ 

Result on text/command screen [Text/File] <Text>: 

This is a sample output on screen

============================================================
BlockReference ......................................3 Found
------------------------------------------------------------
XREF SAMPLE 1 ...............................THIS-LAYER-NAME
XREF SAMPLE LONGER NAME ..............THAT-LAYER-LONGER-NAME
XREF SAMPLE EVEN LONGER NAME ................THIS-LAYER-NAME
============================================================

============================================================
RasterImage .........................................1 Found
------------------------------------------------------------
IMAGE SAMPLE 1 ..............................THIS-LAYER-NAME
============================================================

============================================================
DwfReference ........................................1 Found
------------------------------------------------------------
DWF SAMPLE 1 ................................THIS-LAYER-NAME
============================================================

============================================================
DgnReference ........................................1 Found
------------------------------------------------------------
Dgn SAMPLE 1 ................................THIS-LAYER-NAME
============================================================

============================================================
PdfReference ........................................1 Found
------------------------------------------------------------
PDF SAMPLE 1 ................................THIS-LAYER-NAME
============================================================

 

 

1) The routine can be run from the Keyboard and from a Script !

2) Questions: A for ALL types , D for DWG , N for DGN , F for DWF , P for PDF , I for Image 

3) Question: C for Current Space (Model or Layout) or A for ALL Spaces (Model + All Layouts)  

4) Question: Result on text/command screen (T option) or into a text Tile (F  option)  

 

Can you please elaborate on this

 


@braudpat wrote:

 

 If F ask for the filename ?

If existing file: Replace or Append

 

0 Likes
Message 10 of 28

braudpat
Mentor
Mentor

 

Hello Jedi Master of the Lisp/VLisp

 

If F ask for the filename ?

If existing file: Replace or Append

 

Question: Result on Text/command screen (T) or on a File (F) (Default=T) : ?

 

If File (F)

Navigate on the Units (C:, D:, etc) and give/find a TXT,CSV File

If a NEW  Filename go on ...

If existing Filename Question: Replace the file (R) or Append at the end (A) (Default=R) : ?

 

Is it clear ?

 

Thanks Again, Regards, Patrice

 

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 11 of 28

pbejse
Mentor
Mentor

@braudpat wrote:

 

 

If File (F)

Navigate on the Units (C:, D:, etc) and give/find a TXT,CSV File

If a NEW  Filename go on ...

If existing Filename Question: Replace the file (R) or Append at the end (A) (Default=R) : ? 

 

You specify 3 columns for the external file, the object name, layer name, and what's the third one?

I assumed the file will always be appended when running in the script?

 

 

 

 

0 Likes
Message 12 of 28

braudpat
Mentor
Mentor

Hello

 

1) YES 3 columns :

object name, layer name and the complete path

 

2) When running in Script mode:

If the filename exist then Append automatically

If the filename doesn't exit, create a new one ...

 

Thanks, Regards, Patrice

 

PS: if an Image or DWG or XXX, is inserted as a XREF N times, of course we will get N lines !

 

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 13 of 28

braudpat
Mentor
Mentor

Hello

 

If it is too complex to do all the job in ONE routine !?

 

Please 2 routines : one standard and the other one ONLY Script ...

 

Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 14 of 28

pbejse
Mentor
Mentor

 

 

    	"\n::---------------------------------------------------------::"
	"\n::  XREFUnderlay is now loaded [command version <DRAFT>]   ::"
	"\n::---------------------------------------------------------::"

 

 

Command: XREFUNDERLAY
Choose type [All/Dwg/dGn/dwF/PDF/Image] <All>: A
Layout to process [Current/All] <All>:
Result on text/command screen [Text/File] <Text>: T

 

 

============================================================
BlockReference ......................................3 Found
------------------------------------------------------------
XREF SAMPLE 1 ...............................THIS-LAYER-NAME
XREF SAMPLE LONGER NAME ..............THAT-LAYER-LONGER-NAME
XREF SAMPLE EVEN LONGER NAME ................THIS-LAYER-NAME
============================================================

============================================================
RasterImage .........................................1 Found
------------------------------------------------------------
IMAGE SAMPLE 1 ..............................THIS-LAYER-NAME
============================================================
....

 

Command: XREFUNDERLAY
Choose type [All/Dwg/dGn/dwF/PDF/Image] <All>: A
Layout to process [Current/All] <All>: A
Result on text/command screen [Text/File] <Text>: F
File already exist:
Choose option [Append/oveWrite] <Append>: W

 

 

SAMPLE 1,THIS-LAYER-NAME,C:\USERS\PBEJSE\AUTODESK COMMUNITY\XREF SAMPLE 1.DWG
SAMPLE LONGER NAME,THAT-LAYER-LONGER-NAME,C:\AUTODESK COMMUNITY\OTHER FOLDER\SAMPLE LONGER NAME.DWG
SAMPLE EVEN LONGER NAME,THIS-LAYER-NAME,T:\OTHER DRIVE\SAMPLE EVEN LONGER NAME.DWG

 

We'll deal with the script enabled version later or perhaps you can figure it out on your own 🙂

 

HTH

 

 

 

0 Likes
Message 15 of 28

braudpat
Mentor
Mentor

Hello

 

SORRY : small problem !

 

Commande: XREFUNDERLAY
Choose type [All/Dwg/dGn/dwF/PDF/Image] <All>:
Layout to process [Current/All] <All>:
; erreur: Le serveur ActiveX a renvoyé l'erreur: nom inconnu: "Path"

Commande:

 

ENTER twice  or  A twice : same result !

 

Into your code you use "path" HERE :

         ("Dwg"     "AcDbBlockReference"      "Path"        BlockReference    )

If i remove this line, the routine runs BUT I can't get Info from DWG XREF ...

 

I have added the (vl-load-com) into your LSP ...

 

Regards, Patrice

 

PS: Tests done with ACAD MAP 2019 & ACAD MAP 2014 ...

 

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 16 of 28

pbejse
Mentor
Mentor
My ßad, i know whats wrong with it.
I'll Modify the code as soon as i get my hands on a computer.



0 Likes
Message 17 of 28

pbejse
Mentor
Mentor

@braudpat wrote:

; erreur: Le serveur ActiveX a renvoyé l'erreur: nom inconnu: "Path"


 

 (if (and	  
(setq f (assoc objectName op)) (setq fname (findfile (vlax-get i (Cadr f))))<-- that being the property "Path"

 

The error is caused by regular blocks having "AcDbBlockReference"  as objectname value but doesn't have the property 'Path.

 

We now add the function vlax-property-available-p  to avoid the error.

 

 (if (and	  
   (setq f (assoc objectName op))
   (vlax-property-available-p i (Cadr f))
   (setq fname (findfile (vlax-get i (Cadr f))))

 

Now back to append, Would you want the code to include the filename before the list is found names etc..? 

 

 

T:\PROJECT FOLDER\PROJECT NAME\02-DETAIL\PROJECT SHEET NUMBER 1.DWG
SAMPLE 1,THIS-LAYER-NAME,C:\USERS\PBEJSE\AUTODESK COMMUNITY\XREF SAMPLE 1.DWG
SAMPLE LONGER NAME,THAT-LAYER-LONGER-NAME,C:\AUTODESK COMMUNITY\OTHER FOLDER\SAMPLE LONGER NAME.DWG
SAMPLE EVEN LONGER NAME,THIS-LAYER-NAME,T:\OTHER DRIVE\SAMPLE EVEN LONGER NAME.DWG

T:\PROJECT FOLDER\PROJECT NAME\02-DETAIL\PROJECT SHEET NUMBER 2.DWG
SAMPLE 1,THIS-LAYER-NAME,C:\USERS\PBEJSE\AUTODESK COMMUNITY\XREF SAMPLE 1.DWG
SAMPLE EVEN LONGER NAME,THIS-LAYER-NAME,T:\OTHER DRIVE\SAMPLE EVEN LONGER NAME.DWG

....

 

 

We are getting there.

 

pBe

 

 

0 Likes
Message 18 of 28

braudpat
Mentor
Mentor

Hello

 

If possible in this order :

1) The XREF Name

2) The Layer

3) The Path (if it exists)

 

Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 19 of 28

pbejse
Mentor
Mentor

Hi,

 

Did you try the mod shown on my previous post? It should work now me thinks.

 

 


@braudpat wrote:

 

If possible in this order : ..


 

It is already in that order, what I'm asking was the order of the data when using the routine in a script to process multiple files.

 

Say on the first file, the user specifies a filename for the csv file [ PROJECT123.CSV ],  the succeeding files will not prompt the user for a filename and just append the PROJECT123.CSV. If i were to collect the data, I would want the list to show which files the list belongs to.

 

Now i'm not sure we're on the same page Smiley Happy

 

 

 

 

0 Likes
Message 20 of 28

braudpat
Mentor
Mentor

Hello

 

Yes the xxxxxx.CSV will collect the Xrefs of all DWGs , so it is an Append ...

 

But don't forget to include a title line with the main DWG filename which is processed ...

 

Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes