PDA

View Full Version : LISP Routine to remove all unrefernced Xref's


stephen.coff
2007-07-16, 10:29 AM
Does anyone have a LISP Routine to remove any unrefernced XREF's.
I am constantly getting Architects drawings that have 30+ unrefernced drawings listed in the Xref Manager. They are a real pain in the $#^(&^* to get rid of.

Any asssistance would be great

Stephen

jmcshane
2007-07-16, 12:27 PM
Hi Stephen,

Here is a routine that was posted in this forum before.
I'm sorry I can't remember who the author was so I hope they will forgive me
for posting their work.

The routine was written to bind all xrefs and detach all unreferenced xrefs.

I changed it slightly to reload the xrefs and detach the unreferenced Xrefs.

Hope this helps.

John


(defun c:XD (/ *blks* ref xname)
(vl-load-com)
(setq *blks*
(vla-get-Blocks
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
)
(vlax-for item *blks*
(if (eq (vla-get-IsXref item) :vlax-true)
(progn
(setq ref (tblsearch "BLOCK" (setq xname (vla-get-Name item))))
(if (eq (logand (cdr (assoc 70 ref)) 32) 32)
(command "-xref" "_R" xname)
(command "-xref" "_D" xname)
)
)
)
)

)

CADmium
2007-07-16, 12:29 PM
Try the tool in the attachment .. call it with xrefcleaner..

stephen.coff
2007-07-16, 01:49 PM
Thanks heaps guys, just what I was needing.

Stephen

stephen.coff
2007-07-17, 05:24 AM
jmcshane ,
I have played with your routine and am sure it worked perfectly last night. However I have tried to use it today on this drawing and it looks as though it worked though when you open the xr manager everything unrefernced is still there. Is it because these are ".jpg" ?
Can the routine be altered to remove these and make sure it binds any OLE objects etc,

These files i have been sent are absolutely rediculous and slow the AutoCAD massively, beware.

See attachement
Stephen

dkennard
2007-07-17, 08:41 AM
Man! thats a load of xref's

stephen.coff
2007-07-17, 09:42 AM
Man tell me about it. I have 27 of the buggers and they all look the same so far.
Hence the request for some assistance. I am not sure about you though it takes me 7mins to fully open the drawing let along do anything with it. Just hangs the **** out of my computer.

Stephen

jmcshane
2007-07-17, 11:15 AM
Stephen,

That is a nasty nasty nasty piece of work.

I'm sorry my lisp knowledge doesn't extend to removing jpegs (the routine itself wasn't even mine).

I'm quite sure if you keep this thread going, someone in the forum will supply a fix.

The only thing I could possibly do for you at this time would be to take your address and post you out a large stick to use at your own discretion.

Sorry I can't be of any more assistance

John

stephen.coff
2007-07-17, 11:21 AM
Ha ha hah, lol. Yes it is a very frustrating job this one. It is working out nearly an hour each drawing to prep for xref as background. Ughhh, it's only 4 days work, whats wrong with that. My boss calls me a blugger, but this is rediculous. Now he has reason to thinks it's true.

Don't send the stick, i fear in a mad rage I might hurt myself !

Stephen

jmcshane
2007-07-17, 11:37 AM
Stephen,

This is not really an answer but you could try sticking this at the command line.

(vl-cmdf "-Image" "D" "*")

It will remove ALL the images and make the drawing a lot faster to work with.

Give it a try anyway.

jmcshane
2007-07-17, 11:49 AM
My boss calls me a blugger, but this is rediculous.

Whats a Blugger?

stephen.coff
2007-07-17, 12:12 PM
Well well well, what do you know. That does the trick and very fast, "DING". The drawing is back to normal. I have absolutley zero idea how to tie this in with the existing routine.

Actually, just playing with the "_Image" command and it gives an option "Path" when you enter this and "*" it lists the existing location of all loaded and only "loaded Image files".
It then asks for a new location. So that said, Is there anyone that could write for me a routine that lists the locations and lists the new location the same as the current. That will give a list of all files required to stay (that area actually loaded and there). Then list all the files under the "?" "*" which lists absolutely everything including the unrefernced image files and loaded ones and then subtract the difference ?
That should then give a list of the actual files unrefernced to detach, can this be done ?

Sounds very easy though sure it isn't, figured it was worth asking and betting there is a much simpler solution.

Stephen

CADmium
2007-07-17, 12:50 PM
In the attachment you 'll find a routine, erasing all unrefernced image files from the dwg. Call it with CLEARIMAGEDICT

jmcshane
2007-07-17, 12:51 PM
Just stick it in at the end.


(defun c:XD (/ *blks* ref xname)
(vl-load-com)
(setq *blks*
(vla-get-Blocks
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
)
(vlax-for item *blks*
(if (eq (vla-get-IsXref item) :vlax-true)
(progn
(setq ref (tblsearch "BLOCK" (setq xname (vla-get-Name item))))
(if (eq (logand (cdr (assoc 70 ref)) 32) 32)
(command "-xref" "_R" xname)
(command "-xref" "_D" xname)
)
)
)
)
(vl-cmdf "-Image" "D" "*")
(princ)

)


Will have to look at the images bit of your last post.

John

jmcshane
2007-07-17, 01:04 PM
In the attachment you 'll find a routine, erasing all unrefernced image files from the dwg. Call it with CLEARIMAGEDICT

Hi Thomas,

Any chance you could post the code instead of a vlx ?
It would just be nice to see how other people do things.

Regards

John

stephen.coff
2007-07-17, 01:06 PM
Thomas,
Why thank you yet again. This does exactly that, clears all unrefernce image files.

You wouldn't by any chance wish to elaborate any further ? Say add this to the other routine you made "Xrefcleaner" and call it something short and sweat, maybe "exref" for erase xref, pretty, pretty, pretty, please ?
If it was done with lisp I would have added them together myself though have no idea about vlx file.

Out of curiosity, does anyone know how the hell to do that with lisp and would be nice enough to let me know ?
I have few simple functions for preping a drawing and wouldn't mind tying them all together, this one is a ripper and would love to have it in there.

Not meaning to be rude Thomas, you have been a great help in the last two nights and i think answered all of my threads. thank you very much, you have been a great help.

Stephen

stephen.coff
2007-07-17, 01:27 PM
Guys,
Correct me if i am wrong though looking at jmcshane code:

" (setq ref (tblsearch "BLOCK" (setq xname (vla-get-Name item))))
(if (eq (logand (cdr (assoc 70 ref)) 32) 32)
(command "-xref" "_R" xname)
(command "-xref" "_D" xname)"

It looks to be looking for (70.32) as the answer, which tells it that that xref is unrefernced ?
Does this mean we need to simply look for a different number to tell us it is an unrefernced image file ? If so can anyone tell me where I find out the options or what they are ?

Stephen

T.Willey
2007-07-17, 05:09 PM
Images are different than xrefs. Images are harder to deal with, as their information is stored in a dictionary inside the drawing, while xrefs are just smart blocks. Maybe this will help you.

(defun c:fil (/ Pos DictList ImDict ImDictData ImName ImDefData tempData tempImList ImList ImPath)
; find image locations within the drawing.
; returns a list of (<Image Name> <Image path> <List of tabs inserted in>)

(if (setq Pos (vl-position '(3 . "ACAD_IMAGE_DICT") (setq DictList (entget (namedobjdict)))))
(progn
(setq ImDict (cdr (nth (1+ Pos) DictList)))
(setq ImDictData (entget ImDict))
(foreach lst ImDictData
(if (equal (car lst) 3)
(setq ImName (cdr lst))
)
(if (equal (car lst) 350)
(progn
(setq ImDefData (entget (cdr lst)))
(setq ImPath (cdr (assoc 1 ImDefData)))
(foreach pair ImDefData
(if
(and
(= (type (cdr pair)) 'ENAME)
(setq tempData (entget (cdr pair)))
(= (cdr (assoc 0 tempData)) "IMAGEDEF_REACTOR")
)
(foreach tempList tempData
(if
(and
(equal (car tempList) 330)
(not (assoc (cdr tempList) tempImList))
)
(setq tempImList (cons (cons (cdr tempList) (cdr (assoc 410 (entget (cdr tempList))))) tempImList))
)
)
)
)
(setq ImList (cons (list ImName ImPath (mapcar 'cdr tempImList)) ImList))
(setq tempImList nil)
)
)
)
)
)
ImList
)

stephen.coff
2007-07-18, 01:38 AM
Ahhhhh,
I haven't ried yet though have all faith.
Thank you Tim.

Stephen

stephen.coff
2007-07-18, 04:20 AM
Hmmmm, I ran the routine on a drawing like the one i uploaded before though it didn't work.
I looks as though It is reading the files attached as they all display in the command line. After it has finished I checked the exref manager though all of the files are still there ?

Below is what the command line shows:

Command: eimg
_2006.jpg" nil) ("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$AD-060724-SCP-IC5REALN
(3)" "S:\\C. Projects\\105001 Al Raha Masterplan\\Incoming\\060731 -
Maunsell\\AD-060724-SCP-IC5REALN (3).jpg" nil) ("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$060119 Hotel Schedule"
"S:\\B. Documentation\\105001 Al Raha Masterplan\\06.00 SPECIFICATIONS &
SCHEDULES\\6.06 Area Schedules\\060119 Hotel Schedule\\060119 Hotel
Schedule.jpg" nil))\\Incoming\\060925 - Ferrari
Island\\BNY-MPGP-0001_21_08_2006.jpg" nil) ("AXIS-BAS$0$CORE
B3-B2$0$X00pw-cada_MasterPlan$0$AD-060724-SCP-IC5REALN (3)" "S:\\C.
Projects\\105001 Al Raha Masterplan\\Incoming\\060731 -
Maunsell\\AD-060724-SCP-IC5REALN (3).jpg" nil) ("AXIS-BAS$0$CORE
B3-B2$0$X00pw-cada_MasterPlan$0$060119 Hotel Schedule" "S:\\B.
Documentation\\105001 Al Raha Masterplan\\06.00 SPECIFICATIONS &
SCHEDULES\\6.06 Area Schedules\\060119 Hotel Schedule\\060119 Hotel
Schedule.jpg" nil) ("AXIS-BAS$0$CORE B3-B2$0$TBLOCK-A2$0$PC 814" "C:\\Documents
and Settings\\ely\\Desktop\\PC 814.jpg" nil) ("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$facade-form-max" "\\\\Mzsrv1\\design\\06-AD324-AUH-ALDAR
Headquarters\\dwg\\12-12-06\\facade-form-max.tga" nil) ("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$SCAN1753_001" "S:\\C.
Projects\\105001 Al Raha Masterplan\\Scans\\060726 - Pr B
Islands\\SCAN1753_001.jpg" nil) ("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$SCAN1269_001" "S:\\C.
Projects\\105001 Al Raha Masterplan\\Scans\\060502\\SCAN1269_001.jpg" nil)
("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$SCAN0005_001" "S:\\C.
Projects\\105001 Al Raha Masterplan\\Scans\\060922 - Ladies Beach
Area\\SCAN0005_001.jpg" nil) ("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$Raha Beach New" "S:\\C.
Projects\\105001 Al Raha Masterplan\\Scans\\060327 - new DEF\\Raha Beach
New.jpg" nil) ("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$Project layout drg 19"
"S:\\C. Projects\\105001 Al Raha Masterplan\\Incoming\\051129 - Eng
Corridors\\Project layout drg 19.jpg" nil) ("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$Precinct D for CAD
overlay" "S:\\C. Projects\\105001 Al Raha Masterplan\\Incoming\\060614 -
Precinct D change MAU\\Precinct D for CAD overlay.jpg" nil) ("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$plan view" "S:\\C.
Projects\\105001 Al Raha Masterplan\\Scans\\060927-Ladies Beach HD AS\\plan
view.jpg" nil) ("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$Option A[A]" "S:\\C.
Projects\\105001 Al Raha Masterplan\\Outgoing\\060303 - Sailing Club
Options\\Option A[A].jpg" nil) ("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$Omaa surfaces Sept 05 V4
Raha" "S:\\C. Projects\\105001 Al Raha Masterplan\\Incoming\\061004 - GCCA
pdf\\Omaa surfaces Sept 05 V4 Raha.jpg" nil) ("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$island" "S:\\C.
Projects\\105001 Al Raha Masterplan\\Incoming\\061005 - Mau Marine\\island.jpg"
nil) ("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$Height Aerial 150 dpi"
"D:\\Al Raha - workshop Oct 2006\\Cad\\Plans\\Current\\References\\Height
Aerial 150 dpi.jpg" nil) ("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$Height Aerial" "S:\\C.
Projects\\105001 Al Raha Masterplan\\Scans\\Height Aerial.jpg" nil)
("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$Ferrari Plan 1" "S:\\C.
Projects\\105001 Al Raha Masterplan\\Incoming\\060802 - Ferrari\\Ferrari Plan
1.jpg" nil) ("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$Ferrari Plan" "S:\\C.
Projects\\105001 Al Raha Masterplan\\Incoming\\060802 - Ferrari\\Ferrari
Plan.jpg" nil) ("AXIS-BAS$0$CORE
B3-B2$0$TBLOCK-A2$0$AXIS-TYP$0$X00pw-cada_MasterPlan$0$BNY-MPGP-0001_21_08_2006"
"S:\\C. Projects\\105001 Al Raha Masterplan\\Incoming\\060925 - Ferrari
Island\\BNY-MPGP-0001_21_08
Command:
Command: xr
XREF
Command: _EXTERNALREFERENCES
Command: *Cancel*

Have I done something wrong, could you check please.

Stephen

stephen.coff
2007-07-21, 03:05 AM
Can anyone assist any further, I am sure it's something really simple.

Stephen

azarko
2007-07-23, 09:23 AM
ImgDet - Detach not used image
XrefDet - Detach not used Xref

stephen.coff
2007-07-23, 11:15 AM
Thank you Azarko, grately appreciated.

Stephen