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

count regapps in xrefs

27 REPLIES 27
SOLVED
Reply
Message 1 of 28
rick.hberg
2581 Views, 27 Replies

count regapps in xrefs

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
27 REPLIES 27
Message 2 of 28
pbejse
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

 

Message 3 of 28
rick.hberg
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
Message 4 of 28
rick.hberg
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
Message 5 of 28
Partenheimer
in reply to: rick.hberg

This seems to be an issue that just won't go away. We are a sub-consultant on a large project and I just discovered all project files are infected with excess Regapps. As soon as we attached project Xrefs, our files became infected. (240,000+ Regapps)

 

Thank you for posting your final Lisp. It's great for a quick check on the status of individual files.

 

Regards,

Michael Partenheimer

Message 6 of 28
rick.hberg
in reply to: Partenheimer

No problem Michael, glad it helped some.

 

And yeah, that's basically what our nightmare was - sharing files.  Eventually all companies have this super mound of regapps and it gets impossible to totally stop it.  If you have file A and i have file B, and we xref each others file...then every reload brings the same regapps back in.  The only way to stop the loop is to open file A, purge regapps, then save it.  NEXT open file B, purge the regapps in file B, and save.  Now they both see each other as "clean" and when you reopen file A, it sees file B as clean...so it doesn't repopulate.

 

On the other hand, If you just purge file A, then save it...later reopen file A...all the regapps are back (reloaded from xref file B).

 

We decided to force a regapp purge every time a drawing is opened (from acaddoc.lsp), which runs after the existing xrefs load in the file.  This way, the only way to close a file with all the bad regapps in it is if you reload or attach a bad xref after opening.  Eventually though, there isn't too much new attaching or reloading to do in a file (after the initial open)...and hopefully the last save is a clean one.  Not sure if any of this makes sense, but it has actually worked after several months...  Most of our files are now clean.  The trick is that a file can be saved as "clean" but still have bad xrefs in it.  So you only have to worry about xrefs one level deep.  Over time, those older xrefs (xrefs in the current xrefs) are not used any more...and they fade away.  oh, we also use a .net program to purge...faster than -purge command.

 

I also have some xref reactors running, so any time an xref is attached/overlayed, or reloaded the user gets the output of regapps in the xref.  So if users are paying attention when they attach files, they should see the bad ones - then go open them and purge the source.  In reality though, most users don't pay attention - hence the reason we force the purge with every open.

 

If you think any of those reactors or purge functions will help you, I don't mind sharing them here (the .net purge I use was written by Kean Walmsley anyway, so it's already shared out there).  Ok, this is a long post...but it's been a long problem to deal with!!  I really believe the program should clean these unused regapps without us having to fix it.  It's a HUGE problem and most people don't even notice until their file is REALLY BAD!  In Civil 3D we can't use the external regapp utility either, because it was deleting alignment labels in our data references...sigh

Civil 3D 2014
Windows 7 x64
Message 7 of 28
Partenheimer
in reply to: rick.hberg

I first encountered the RegApp bloat issue in 2005, 10 years ago.

Here I am today and this issue still lingers...

 

Worse today is that the RegApp bloat issue has two additional companions: DGN bloat and Excess Scale bloat.

This is NOT a ringing endorsement of AutoCAD as a product or Autodesk as a responsible corporate "partner". These are (devistating) product design flaws which, unfortunately, we customers are left to grapple with.

 

Band-Aid solutions not withstanding, these defects simply shouldn't (still) be an ongoing issue.

 

Kudos to Rick (and all others) battling these budget busting product flaws.

 

Regards,

Michael Partenheimer

 

 

Message 8 of 28
JamesMaeding
in reply to: pbejse

Harvesting info from files can be done directly. We have been doing this for about 10 years now.

So open the dwg as dbx doc and get any info about the drawing needed, including app ids if that's what you care about.

This is the lisp code I used to use for the purgeids program we wrote, shown at the bottom.

I now use .net because it allows me to see if the ucs is set to world, which the civil3d batch converter needs, so we use the purgeids tool for many things besides actually cleaning app ids out.

 

(defun getappids ( / DBXDOC REGAPPS REGCOUNT)
  (SETQ DBXDOC GET-DBX-DOC)
  (IF (NOT (vl-catch-all-error-p (vl-catch-all-apply '(lambda () (vla-open DBXDOC ITEM)))))
    (PROGN
      (SETQ REGAPPS (vla-get-registeredapplications DBXDOC)
	    REGCOUNT (vla-get-count REGAPPS)
      )
     )
   )
   (IF DBXDOC
     (VLAX-RELEASE-OBJECT DBXDOC)
   )
   REGCOUNT
  )

You need these too, but you could simplify if just dealing with one version of acad.

 

  (DEFUN CHECK-FOR-DBXCLS ( / )
    (cond
      ((WCMATCH (STRCASE (VLAX-PRODUCT-KEY)) "*BRICSCAD*")
       1
       )
       ((WCMATCH (VLAX-PRODUCT-KEY) "*\\R15*")
         (IF (VL-REGISTRY-READ "HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument\\CLSID") 1 NIL)
       )
       ((WCMATCH (VLAX-PRODUCT-KEY) "*\\R16*")
         (IF (VL-REGISTRY-READ "HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument.16\\CLSID") 1 NIL)
       )
       ((WCMATCH (VLAX-PRODUCT-KEY) "*\\R17*")
         (IF (VL-REGISTRY-READ "HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument.17\\CLSID") 1 NIL)
       )
       ((WCMATCH (VLAX-PRODUCT-KEY) "*\\R18*")
         (IF (VL-REGISTRY-READ "HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument.18\\CLSID") 1 NIL)
       )
       ((WCMATCH (VLAX-PRODUCT-KEY) "*\\R19*")
         (IF (VL-REGISTRY-READ "HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument.19\\CLSID") 1 NIL)
       )
       ((WCMATCH (VLAX-PRODUCT-KEY) "*\\R20*")
         (IF (VL-REGISTRY-READ "HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument.20\\CLSID") 1 NIL)
       )
     )
  )
  
  (DEFUN GET-DBX-DOC ()
    (cond
      ((WCMATCH (VLAX-PRODUCT-KEY) "*\\R15*")
        (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument")
      )
      ((WCMATCH (VLAX-PRODUCT-KEY) "*\\R16*")
        (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument.16")
      )
      ((WCMATCH (VLAX-PRODUCT-KEY) "*\\R17*")
        (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument.17")
      )
      ((WCMATCH (VLAX-PRODUCT-KEY) "*\\R18*")
        (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument.18")
      )
      ((OR (WCMATCH (VLAX-PRODUCT-KEY) "*\\R19*")
           (WCMATCH (VLAX-PRODUCT-KEY) "*\\V13*")
           (WCMATCH (VLAX-PRODUCT-KEY) "*\\V14*")
        )
        (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument.19")
      )
      ((OR (WCMATCH (VLAX-PRODUCT-KEY) "*\\R20*")
           (WCMATCH (VLAX-PRODUCT-KEY) "*\\V15*")
        )
        (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument.20")
      )
    )
  )

HAPurgeids.jpg

 


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Message 9 of 28
JamesMaeding
in reply to: rick.hberg

Rick - force the purge with every open???

 

The -purge locks up drawings with lots of regapps active and in the xref, and takes forever if it does work.

It does not help anyway, as regapps come from xrefs, so why clean the current drawing if you are not cleaning the xref (which you cannot do on open of course).

I would advise anyone thinking of adding that to the acaddoc.lsp think twice, as you are in trouble when the problem hits - likely on a day you are sick and people start cursing your name, probably making you more sick. Its a vicious cycle 🙂

 

The only real solutions I have seen are batch cleaners, like the adesk one, or the Civil3d civil batch converter.

We run all incoming files through the civil batch converter to kill the civil3d entities and styles, and that kills regapps and other things at the same time.

 


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Message 10 of 28
Partenheimer
in reply to: JamesMaeding

FWIW,

 

At the last company I worked (where I was the CAD Systems Manager), I set up -PURGE to run at each file open.

 

My thinking was:

   Eventually all files (Sheet Files and Xrefs alike) would be opened for edit and thus be "fixed".

   If a user complained about slow file opening, I would be contacted and thus alerted to a fresh "infection" which I could better address.

 

That system actually worked.

Of course... that was then...

 

Regards,

Michael Partenheimer

Message 11 of 28
JamesMaeding
in reply to: Partenheimer

That can work with a fairly clean environment.

It would fail at my place in about 1 hour. The files we get are so bad, and most of the consultants have no idea.

For Autodesk to let this go on is insane IMO.

I have never heard them propose a solution, even with serious compromises.

I know xdata is important, and you need a regapp to add it to an entity, but why do the regapps transfer from xrefs?

Layers do not transfer, linetypes, any other tabled item, but app ids do. WHY????


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Message 12 of 28
Partenheimer
in reply to: Partenheimer

BTW:

Rather than Purge "*", I avoided most lockups by filtering my purge:

 

(command "-PURGE" "R" "E*" "N")
(command "-PURGE" "R" "AUDIT*" "N")
(command "-PURGE" "R" "#*" "N")

Message 13 of 28
BlackBox_
in reply to: Partenheimer


@Anonymous wrote:

This seems to be an issue that just won't go away. We are a sub-consultant on a large project and I just discovered all project files are infected with excess Regapps. As soon as we attached project Xrefs, our files became infected. (240,000+ Regapps)

 

Thank you for posting your final Lisp. It's great for a quick check on the status of individual files.


Hi Michael,

 

I've been using this to automagically handle excess RegApps, since first developing it back in Civil 3D 2011 due to similar issues... Hope that you also find it to be of use:

 

https://apps.exchange.autodesk.com/ACD/en/Detail/Index?id=appstore.exchange.autodesk.com%3aappautopurgeregforautocad00ae_windows32and64%3aen

 

 

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Message 14 of 28
JamesMaeding
in reply to: BlackBox_

Blackbox,

do users of your tool realize app ids jump in from the xrefs?

If one does realize that, they know it is futile to clean the current dwg without cleaning the xrefs first.

Also, cleaning out files that have 100k+ regapps takes time, slowing down production.

I wonder how many of the people commenting on your app realize how it all works.

 

The thing about regapps is the cleaning tools and all work great when the problem is not there, then they cause major issues when the problem does hit.

When it does hit, you need to clean the whole trail of regapps back to the source if you can identify it.

That is what the purgeids tool does, is find "xrefs of the xrefs..." until it runs out of dirty files to follow.

I'd be happy to work with you on this if you want to make something for the app store that does it.

I know you have the programming down, just meaning the ideas..


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Message 15 of 28
rick.hberg
in reply to: JamesMaeding

Looks like some good posts to look into! Smiley Happy

 

Hi jmaeding, just to reply to your earlier post -

I do not force a -purge for regapps.  We force a regapp purge method from a .net application.  We also force purge the dgn linetype records from a .net app.  And we reset the scales from yet another .net app.  Our regular startup time is a couple seconds.  If a user has longer load times for any reason, they have all of our output right there on the command line for them to find and fix the problem.  I really believe the users should be aware of the problem and be educated as to how to fix it..why it happens, etc.  (e.g. don't wait for me to show up lol)

 

To be honest, I'm not a cad manager....just a structural guy trying to help the company.  Our users have no obligation to use our startup routines (very loose setup here)....but they all do because it works. Certainly, there may be better methods out there, but originally it was a nightmare just figuring all this out.  I've been trying to get efficient with lisp and now .net with a lot of good help from folks on these forums.  I'm always up for updating with new and/or better methods, so I'll gladly take a gander at your posts (and BlackBox's post of course).

 

For the regapps, we just had to open xrefs one level deep, purge the regapps and save the file.  Any regapps deeper than that didn't matter (e.g. the files aren't opened anymore), and any new files are purged as soon as we open them - so new xrefs can never be a problem.  The initial company wide purge was the hard part!  At the time, we tried the adesk regapp utility, but it was deleting civil 3d labels.  I never heard of the civil3d batch utility, but thankfully it's all over now.  The only way for us to filter incoming files in our company setup is through acad.lsp and acaddoc.lsp.

 

In any case, big thanks to everyone that shares their info on these forums!!  It would be real tough without the teamwork!!  Sorry for my lengthy replies..ugghh Smiley Happy

 

Civil 3D 2014
Windows 7 x64
Message 16 of 28


@rick.hberg wrote:
 

To be honest, I'm not a cad manager....just a structural guy trying to help the company. 


A structural guy running Civil 3D 2014...

At the least you deserve another kudo for showing that kind of bravery.

 

Regards,

Michael Partenheimer

Message 17 of 28
JamesMaeding
in reply to: rick.hberg

Rick,

I also do the regapp purge with .net code, but always on "side databases" which are drawings not open in the editor.

When i was originally working on this issue with adesk, we realized you could purge 100k+ regapps from non-open files in seconds, while it took minutes if open.

I thought the .net method still takes forever on an open drawing, as it somehow looks at the regapps in the xrefs as it decides to purge or not.

Somehow, autodesk is keeping this issue rather hush-hush, but sees how bad it can be so does have a cleaning tool.

This should be a much more visible problem IMO, but then they look bad.

 

That civil3d batch converter wblocks all to a new drawing, fast. Its the best cleaner out there, hands down, no competition.

You just have to be careful to tell it to explode aec objects or not (yes for us) and not to bind xrefs.

Also be sure your drawings have ucs set to world. I asked adesk to fix the ucs thing many times, but they have refused, saying they will fix in their next tool.

Hasn't happened yet, though they did add a .net api function to allow setting ucs to world, though they did not use it in their own prog, whatever.

thx


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Message 18 of 28
InfraChic
in reply to: JamesMaeding

So where would one find a copy of the Purge Apps ID program you made?  This is exactly what I need.  I'm getting in anywhere from 2 to 40 files a day from our Prime and they are just littered with everything. I manually open each file, unload Xrefs, purge styles, Purge reg apps, purge all and finally audit then save as the current version which is C3D 2016 in this case.  I'd love to give you program a shot and see if it helps on my end.

 

Infrachic.


Heidi B.

Message 19 of 28
ronjonp
in reply to: InfraChic

I use this to batch clean regapps from files. I get hugely littered files daily.

 

I also posted some code HERE to wblock files which cleans up many things ( test it of course ).

Message 20 of 28
JamesMaeding
in reply to: InfraChic

@InfraChic 

Hey there, please use this link:

https://dn.hunsaker.com/?linkid=KZi4zr6VWWUcZqRYDua7l6NoQfWP7yd4/4DODS6ncAGbVD1e08QgPg

 

There are install/setup instructions in there. Just be sure to unblock the .dll's mentioned, as somehow windows sets them to blocked. These are .net dll's I created so I know exactly what is in them, no outsider code on this.

I have multiple acad versions and bricscad in there, so choose the one you need.

Let me know if you have any setup issues, I help lots of people with the setup.

Once its going, I recommend always purging regapps, anno scales, groups, and materials (the top check box):

pid.jpg

In addition, if you know you don't have civil3d objects, check the Delete C3D styles button too.

Your choice on the other two, but detaching xrefs is drastic so don't just check all without thinking.

If you read the included pdf on this tool, you will see its a diagnosis tool, as well as a cleaning tool.

Autodesk misses that in their cleaning tool.

We also use it instead of etransmit. You can add say, 10 sheets to the list, click find xrefs, then select all and right click for "copy to folder" option and others. It does not modify the drawing xref paths like etransmit does.

If you look at the batch property modify area on lower right, you will see this is an  xref path search and replacer too, as well as layer props and a couple other things. Its much faster than xref manager and most other tools as it opens the drawings in memory only, not the editor. Once you get good at using this, you can get a good handle on dealing with incoming files and files within your office that get recontaminated.

One last comment, I use this in an autocad session, not civil3d. I also uninstall the civil3d object enablers as I don't want them for autocad. If I need c3d objects to work, I open in a civil3d session. Uninstalling the OE's does not affect a c3d session, it works as normal. If you use in acad, without OE's, you can read and clean drawings in seconds, that hang up for 30 seconds or more in a c3d session.

thx


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

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

Post to forums  

Autodesk Design & Make Report

”Boost