• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Visual LISP, AutoLISP and General Customization

    Reply
    Valued Contributor
    rick.hberg
    Posts: 63
    Registered: ‎06-27-2011
    Accepted Solution

    count regapps in xrefs

    189 Views, 3 Replies
    10-01-2012 02:24 PM

    Hi all,  I have thrown together something to return the number of regapps in xref files (and the active file).

     

    My problem is that if an xref is unloaded, it will become an automation error.  I would really like to get the number of regapps even in unloaded xrefs.....but if that's not feasible, can anyone help me to only process loaded xrefs?

     

    Any help is appreciated - I am still trying to learn quite a lot of lisp methods and habits.  Thanks.

    ;; 2012-10-01 RJH.  Goal is to retrieve the number of regapps
    ;;  in the xref files. Purging regapps is useless if they come from the xrefs
    
    ;; Thanks to Balaji Ramamoorthy's post for helpful methods.
    ;;  on ADN: http://adndevblog.typepad.com/autocad/2012/06/
    ;;	entity-name-of-an-xref-subentity-from-its-handle.html
    
    (defun C:TestReg ( / activedoc activeblocks each xrefdb xrefregapps )
    
    ;; Error handling
    (defun *error* (msg)
    	(princ (strcat "\n " msg))
    	(princ)
    )
    
    (vl-load-com)
    
    ;get active document
    (setq activedoc (vla-get-activedocument (vlax-get-acad-object)))
    
    ;get blocks in active document
    (setq activeblocks (vla-get-blocks activedoc))
    
    ;for each block,
    (vlax-for each activeblocks
    
    	;if the block is an xref
    	(if	(= (vlax-get-property each 'IsXref) :vlax-true)
    
    		(progn
    
    			;get xref database
    			(setq xrefdb (vla-get-xrefdatabase each))
    
    			;get the count of regapps in the xref
    			(setq xrefRegapps (vlax-get-property (vla-get-RegisteredApplications xrefdb) 'Count))
    
    			;output findings to command line.
    			(princ (strcat "\n " (rtos xrefRegapps 2 0) " Regapps in " (vla-get-path each)))
    
    		)
    	)
    	;release the block
    	(vlax-release-object each)
    )
    
    ;release the active document.
    (vlax-release-object activedoc)
    
    (princ)
    );end defun

     

    Civil 3D 2011
    Windows 7 x64
    Please use plain text.
    *Expert Elite*
    Posts: 2,057
    Registered: ‎11-24-2009

    Re: count regapps in xrefs

    10-01-2012 07:25 PM in reply to: rick.hberg
    (if
    (and (= (vlax-get-property each 'IsXref) :vlax-true) (not (assoc 71 (entget (tblobjname "block" (vla-get-Name each))) ) ) )
    .......

     

    HTH

     

    Please use plain text.
    Valued Contributor
    rick.hberg
    Posts: 63
    Registered: ‎06-27-2011

    Re: count regapps in xrefs

    10-02-2012 06:24 AM in reply to: pbejse

    cool, Thanks pbejse!

     

    I was trying (entget (vlax-vla-object->ename each))...but I see that has a different return from the (entget (tblobjname...).

     

    Can I ask where/how you found the 71 group code?  I was looking in the Block section of the dxf reference (I think my dxf help file skills are lacking a bit).

     

    In any case thanks again for the help!

    Civil 3D 2011
    Windows 7 x64
    Please use plain text.
    Valued Contributor
    rick.hberg
    Posts: 63
    Registered: ‎06-27-2011

    Re: count regapps in xrefs

    10-12-2012 10:47 AM in reply to: rick.hberg

    this is what I ended up with for anyone interested.  Type REGCOUNT to run the command and view the command line output.

    Civil 3D 2011
    Windows 7 x64
    Please use plain text.