Code Red > AutoLISP (Vanilla / Visual)

Seperating Xrefs from blocks

(1/8) > >>

Hangman:
Does anyone know or have a routine that seperates xrefs from blocks in any given dwg ?

I am working on a bind program, but if I have nested xrefs, it won't bind the dwg.  I need to find a way to alert the user if there are nested xrefs.

Thanks,

T.Willey:
Here is a cheap way to do it.


--- Code: ---(defun c:ListNestedXrefs (/ XrefList BlkCol)

(setq BlkCol (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object))))
(vlax-for Blk BlkCol
 (if
  (and
   (= (vla-get-IsXref Blk) :vlax-true)
   (not (ssget "x" (list (cons 0 "INSERT") (cons 2 (setq XrefName (vla-get-name Blk))))))
  )
  (setq XrefList (cons XrefName XrefList))
 )
)
XrefList
)

--- End code ---

Hangman:
T.Willey,
Thank you.  This is good.  Why would you call it cheap, this is like gold.  (at least to me, it is. )  :?
So, now I can take the XrefList, and if it is not nil, then ALERT to the user.
This will work for now.  Eventually I will come back and beg you to help me put something together that may take the nested xrefs out before binding.  :D

Which reminds me, if I may pick your brain just a bit more.
I am having a similar problem with images.
Can I use the same scenario for images, that is, the vla-get-ImageFile kinda like this (but I don't know how to put it together :(  )

--- Code: ---(setq ImgBlk (vla-get-ImageFile (vla-get-ActiveDocument (vlax-get-Acad-Object))))
(vlax-for Img ImgBlk
 (if
  (and
   (= (vla-get-ImageFile Img) :vlax-true) ;;; I don't think this is going to work here.
   (not (ssget "x" (list (cons 0 "INSERT") (cons 2 (setq ImageName (vla-get-name Img))))))
  )
  (setq ImageList (cons ImageName ImageList))
 )
)
ImageList
)

--- End code ---

And how would the code be put together to detach an unreferenced image on the list ??

Thanks again for your help. 

T.Willey:
It's cheap because I couldn't figure out a way to do it the way I wanted to.  I probably could have, but it would have been a much longer code.  If it works for you, then it is all good.  :-)

Images are stored in a dictionary.  But you can search from them in kind of the same way.  One quick way to get all images would be

--- Code: ---(setq ss (ssget "x" '((0 . "IMAGE"))))

--- End code ---

If you want to see if they are loaded, then you will have to check the dictionary.  Or (just checked something) you can convert it to an ActiveX object, and get the file path, and then use findfile to see if it finds it.  So something like


--- Code: ---(if (setq ss (ssget "x" '((0 . "IMAGE"))))
 (while (setq Ent (ssname ss 0))
  (setq Obj (vlax-ename->vla-object Ent))
  (if (not (findfile (vla-get-ImageFile Obj)))
   (setq ImgList (cons (vla-get-Name Obj)))
  )
  (ssdel Ent ss)
 )
)

--- End code ---

This will get us a list of all the unreferenced images.  Now to detach them, you will have to delete the xrecord (?) in the image dictionary.  Something like


--- Code: ---(setq DictCol (vla-get-Dictionaries (vla-get-ActiveDocument (vlax-get-Acad-Object))))
(setq ImgDict (vla-Item DictCol "ACAD_IMAGE_DICT"))
(foreach ImgName ImgList
 (vla-Delete (vla-Item ImgDict ImgName))
)

--- End code ---
This will error is you run it on a drawing with no images, because the dictionary doesn't exist unless there is at least one image in the drawing.

Hope the helps.

Hangman:
Cool !
This is a bit to chew on, thank you again.
I'll go play with this stuff and see what I can put together.  I don't have a lot of time to play, so it might be a week or so before I can get back with you, but I'll let you know what I come up with.
Just out of curiosity, how did you want to list the xref's ??

Navigation

[0] Message Index

[#] Next page

Go to full version