Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Open a dwg, get some information and return to the original dwg using script

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
mpnetto
438 Views, 2 Replies

Open a dwg, get some information and return to the original dwg using script

Hi, I'm trying to open a dwg, get some information and return to the original dwg using script but i'm having trouble doing that. The thing is, everything work perfect fine, but when i try to run the command in the original dwg nothing happens. I thin is because the original dwg is not activated. I have to use the lisp on a new drawing, and i don't see how can I activate an unsaved dwg. Someone could help? Cheers,
2 REPLIES 2
Message 2 of 3
p_mcknight
in reply to: mpnetto

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)
  )

Message 3 of 3
mpnetto
in reply to: p_mcknight

Yeah... It is not via script but i could get a solution from it... (vla-open (vla-get-documents (vlax-get-acad-object)) arquivo :vlax-true) (setq docs (vla-get-documents (vlax-get-acad-object))) (setq doc (vla-item docs (1- (vla-get-count docs)))) (vlax-for blk (vla-get-blocks doc) (vlax-for obj blk (setq original "") (if (eq (vla-get-objectname obj) "AcDbBlockReference") (progn (setq ef (vlax-get-property obj (if (vlax-property-available-p obj 'effectivename) 'effectivename 'name ) ) ) (if (and (eq (vla-get-hasattributes obj) :vlax-true) (eq ef "prum") ) (progn (foreach att (vlax-invoke obj 'getattributes) (cond ( (eq (vla-get-tagstring att) "PRUM") (setq tipo (vla-get-textstring att)) ) ) ) (setq vb (RetornaValor (vlax-vla-object->ename obj) "Visibility")) (setq lst (cons (list tipo vb) lst)) ) ) ) ) ) ) (vla-close doc :vlax-false)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost