How Can I Make This Neat? VBA code

Anonymous

How Can I Make This Neat? VBA code

Anonymous
Not applicable

I've written a piece of code that inspects large assemblies and part of it is going through each assembly and sub assembly until it gets to the parts (and then does things).

 

I've attached an image of my code as copy and paste doesn't seem to be helping.

 

I basically have this many times- is there a way to make it neater? It's awful coding I'm sure Smiley Tongue

 

0 Likes
Reply
Accepted solutions (1)
464 Views
3 Replies
Replies (3)

CadUser46
Collaborator
Collaborator
Accepted solution

If you are looping through the collection of allreferenceddocuments then you don't need to call it multiple times, it is already the entire collection of every child and child's child etc.

 

My first question is does ThreadData and HoleData care what type it is?  The way it is written i would have to assume not, or it has it's own code to handle either doctype.  In which case why do you need to distinguish between doctype in this sub?

 

If you really do you can do something like this (I'm going on memory, not intellisense)

 

dim DocType as DocumentType: set DocType = aDoc.DocumentType

 

Select Case DocType

Case kPartDocumentObject, kSheetMetalDocumentObject   'Im just showing you can list types, not totally sure if sheet metal exists here.

      ThreadData

      HoleData

Case kAssemblyDocumentObject

      ThreadData

      HoleData

Case Else

      'Any other type

End Select

 

 

 


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes

Anonymous
Not applicable

Oh so allreferenceddocuments will get all the parts within sub assemblies? I obviously missed that! I'm not calling it multiple times- that was just where I started and then from there I dug into assemblies from there - But I guess if allreferenceddocs gets the parts anyway this isn't required? HoleData and ThreadData are just other subs I'm calling to look into the parts (they're not really relevant).

0 Likes

Anonymous
Not applicable

It works and is so much better thank you!

That was the key bit that I just didn't quite catch on to!

0 Likes