Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
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
Solved! Go to Solution.
Solved by CadUser46. Go to 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
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).
Can't find what you're looking for? Ask the community or share your knowledge.