Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Valued Contributor
rick.hberg
Posts: 70
Registered: ‎06-27-2011
Message 1 of 4 (365 Views)
Accepted Solution

count regapps in xrefs

365 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
*Expert Elite*
pbejse
Posts: 2,459
Registered: ‎11-24-2009
Message 2 of 4 (350 Views)

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

 

Valued Contributor
rick.hberg
Posts: 70
Registered: ‎06-27-2011
Message 3 of 4 (329 Views)

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
Valued Contributor
rick.hberg
Posts: 70
Registered: ‎06-27-2011
Message 4 of 4 (297 Views)

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
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.