Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

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

count regapps in xrefs

403 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 2014
Windows 7 x64
(if
(and (= (vlax-get-property each 'IsXref) :vlax-true) (not (assoc 71 (entget (tblobjname "block" (vla-get-Name each))) ) ) )
.......

 

HTH

 

*Expert Elite*
pbejse
Posts: 2,511
Registered: ‎11-24-2009
Message 2 of 4 (388 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: 78
Registered: ‎06-27-2011
Message 3 of 4 (367 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 2014
Windows 7 x64
Valued Contributor
rick.hberg
Posts: 78
Registered: ‎06-27-2011
Message 4 of 4 (335 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 2014
Windows 7 x64
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.