densan Posted March 1, 2022 Posted March 1, 2022 As a learning exercise, I am trying to write a routine that will create an mtext entity and list all the types of external references missing in the current drawing. I attached a sample file for reference. The scope is to create an mtext object that evaluates current missing xrefs and returns the following: Missing external reference: dgnExternalreference-01.dgn Missing external reference: dwfExternalreference-01.dwfx Missing external reference: dwgExternalreference-01.dwg Missing external reference: excelFile-01.xlsx Missing external reference: imgExternalreference-01.jpg Missing external reference: pdfExternalreference-01.pdf My approach is this Get the object names for each xref type Determined if they are missing somehow Create a list for each xref class Create mtext object Fill in mtext with list values I would appreciate it if this forum could please give me some feedback on what I'm doing wrong and what concepts, functions, or references I need to study. I'm struggling with what method to use to get the dwg xref information (ssget, dictionary or vla) and many more things as a noob. The following code is the only part I feel is somewhat correct. Thank you, ;;; Text creation reference https://www.cadtutor.net/forum/topic/17870-entmake-and-mtext/ ;;; Xref from dictionary reference https://www.cadtutor.net/forum/topic/74541-renaming-attached-images/ ;;; (defun c:txtmissxref ( / dlxref dgnxrf dwfxrf imgxrf pdfxrf) ;get a count of datalinks (setq dlxref (cdr (assoc -1 (dictsearch (namedobjdict) "acad_datalink")))) ;get a count of dgns (setq dgnxrf (cdr (assoc -1 (dictsearch (namedobjdict) "acad_dgndefinitions")))) ;get a count of dwfs (setq dwfxrf (cdr (assoc -1 (dictsearch (namedobjdict) "acad_dwfdefinitions")))) ;get a count of images (setq imgxrf (cdr (assoc -1 (dictsearch (namedobjdict) "acad_image_dict")))) ;get a count of pdfs (setq pdfxrf (cdr (assoc -1 (dictsearch (namedobjdict) "acad_pdfdefinitions")))) ;mtext creation (setq txtloc (getpoint "\nSelect insertion point")) (setq txtvals "Hello World") (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 txtloc) (cons 1 txtvals) ) ) (princ) ) addtxtMissingxref.dwg Quote
mhupp Posted March 2, 2022 Posted March 2, 2022 (edited) Since your trying to learn ill only give you bits of what should work. 1. Get the object names for each xref type What you have gets the entity name of the dictionary group. ((-1 . <Entity name: 27cab6e0>) (0 . "DICTIONARY") (5 . "202A8") (102 . "{ACAD_REACTORS") (330 . <Entity name: 27cab6a0>) (102 . "}") (330 . <Entity name: 27cab6a0>) (100 . "AcDbDictionary") (281 . 1) (3 . "fraction-to-decimal-table") (350 . <Entity name: 27cb09a0>)) what you want is the all the 350's in that group not the -1 (setq imgxrf (dictsearch (namedobjdict) "acad_image_dict")) (setq imgxrf (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 350)) imgxrf))) This will make a list of entity names of all images in the drawing. 2. Determined if they are missing somehow Step through each entity and use findfile. (foreach img imgxrf (setq path (cdr (assoc 1 (entget img)))) ;gets path to image (if (eq (findfile path) nil) ;if you don't find file aka missing or moved. ;create list to write to mtext ) ) Edited March 2, 2022 by mhupp Quote
densan Posted March 3, 2022 Author Posted March 3, 2022 Thank you mhupp , I will study your suggestions, and it's great to have a bit of direction. I was going crazy trying to guess how to apply bits from other sources or articles. If I could ask for help on another subject, what do I look for to understand the difference when I get results in these two different formats? I am using the watch window in the AutoCAD Visual LISP IDE, and sometimes.. Data is returned in a single line list ((-1 . <Entity name: 27cab6e0>) (0 . "DICTIONARY") (5 . "202A8") (102 . "{ACAD_REACTORS")....... And sometimes data is returned in a vertical list [0] (-1 . <Entity name: 27cab6e0>) [1] (0 . "DICTIONARY") [2] (5 . "17") [3] (102 . "{ACAD_REACTORS")....... Thank very much for the help. Quote
mhupp Posted March 3, 2022 Posted March 3, 2022 Because either the function its self or the lisp is using a loop to display information. Like these two functions that I Use to collect data of like objects when coding. the vlax-dump-object must have a loop in it and the mapcar 'print is the loop. ;;----------------------------------------------------------------------------;; ;; Dump all methods and properties for Visual Lisp Objects (defun C:VDumpIt (/ ent) (if (setq SS (ssget)) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (vlax-Dump-Object (vlax-Ename->Vla-Object ent) t) (textscr) ) ) (princ) ) ;;----------------------------------------------------------------------------;; ;; Dump all DXF Group Data (defun C:DumpIt (/ e) (if (setq SS (ssget)) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (mapcar 'print (entget ent '( "*"))) (textscr) ) ) (princ) ) Haven't used AutoCAD since late 2015. And really only picked up lisp after my switch to BricsCAD so I can't really cant compare the two. In Briscad it Allows you to see how its getting information in a variable *last-value* this is what is shown when stepping though just this line of code. (setq imgxrf (cdr (assoc -1 (dictsearch (namedobjdict) "acad_image_dict")))) -1 <Entity name: 3fae0350> ((-1 . <Entity name: 39b6920>) (0 . "DICTIONARY") (5 . "81") (102 . "{ACAD_REACTORS") (330 . <Entity name: 3fae0350>) (102 . "}") (330 . <Entity name: 3fae0350>) (100 . "AcDbDictionary") (281 . 1) (3 . "Capture") (350 . <Entity name: 39b66a0>)) (-1 . <Entity name: 39b6920>) <Entity name: 39b6920> By inspecting the third line I had 4 images attached to the drawing. that line had 4 (3 . "Capture") (350 . <Entity name: 39b66a0>) each 3 had the name of the image file. That's how I knew to cut down (setq dwfxrf (cdr (assoc -1 (dictsearch (namedobjdict) "acad_dwfdefinitions")))) to (setq dwfxrf (dictsearch (namedobjdict) "acad_dwfdefinitions")) Then process it thought vl-remove-if-not to get all the entity names Hopefully AutoCAD acts something like that and just doesn't process the whole line in one go and spit out <Entity name: 39b6920> Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.