Solved! Go to Solution.
Solved by p_mcknight. Go to Solution.
Below is a routine I use to open a drawing, get the block definitions out of and then compare them to the block definitions in my current drawing. I just threw it together a few days ago and still need to do some cleaning up and streamlining but it should get you started. Note that (getfilepath is a custome routine I use to navigate to the correct file based off of its part number in our system. You will need to replace it with your own path making routine (or input from user). Hope this helps.
(defun c:scb ( / objs obj vlobj blockName partNumber docs doc blocks block n dwgEData blockBData ent vlent edata blockAData vlentlast ll ur xmax ymin ymax ymid insPoint)
(setq objs (ssget))
(repeat (setq i (sslength objs))
(setq blockAData nil)
(setq blockBData nil)
(setq obj (ssname objs (setq i (1- i))))
(setq vlobj (vlax-ename->vla-object obj))
(if (= (vla-get-ObjectName vlobj) "AcDbBlockReference")
(progn
;Get part number
(setq blockName (vla-get-name vlobj))
(setq partNumber (substr blockName 1 (1- (strlen blockName))))
;Get block information from external dwg
(setq filePath (getfilepath partNumber))
(if (/= filepath "doesNotExist")
(progn
(vla-open (vla-get-documents (vlax-get-acad-object)) filePath :vlax-true)
(setq docs (vla-get-documents (vlax-get-acad-object)))
(setq doc (vla-item docs (1- (vla-get-count docs))))
(setq blocks (vla-get-blocks doc))
(setq index 0)
(repeat (vla-get-count blocks)
(setq block (vla-item blocks index))
(if (= blockName (vla-get-name block))
(progn
(vlax-for n block
(setq dwgEData (entget (vlax-vla-object->ename n)))
(setq dwgEData (vl-remove (assoc -1 dwgEData) dwgEData))
(setq dwgEData (vl-remove (assoc 330 dwgEData) dwgEData))
(setq dwgEData (vl-remove (assoc 5 dwgEData) dwgEData))
(setq blockBData (cons dwgEData blockBData))
)
)
)
(setq index (1+ index))
)
(vla-close doc :vlax-false)
;Get block information from current dwg
(setq ent (entnext (tblobjname "block" blockName)))
(while ent
(setq vlent (vlax-ename->vla-object ent))
(setq edata (entget ent))
(setq edata (vl-remove (assoc -1 edata) edata))
(setq edata (vl-remove (assoc 330 edata) edata))
(setq edata (vl-remove (assoc 5 edata) edata))
(setq blockAData (cons edata blockAData))
(setq ent (entnext ent))
)
)
)
)
)
;Compare the blocks
(vla-GetBoundingBox vlobj 'll 'ur)
(setq ll (vlax-safearray->list ll))
(setq ur (vlax-safearray->list ur))
(setq ll (trans ll 0 1))
(setq ur (trans ur 0 1))
(setq xmin (car ll))
(setq xmax (car ur))
(setq xmid (/ (+ xmin xmax) 2))
(setq ymin (cadr ll))
(setq ymax (cadr ur))
(setq ymid (/ (+ ymin ymax) 2))
(setq insPoint (list xmid ymid 0))
(if (equal blockAData blockBData)
(progn
(command ".text" "j" "mc" insPoint 2 0 "SAME")
(setq vlentlast (vlax-ename->vla-object (entlast)))
(vla-put-color vlentlast 3)
)
(progn
(command ".text" "j" "mc" insPoint 2 0 "DIFFERENT")
(setq vlentlast (vlax-ename->vla-object (entlast)))
(vla-put-color vlentlast 1)
)
)
)
(alert "Comparison completed. ")
(princ)
)