Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How Can I Make This Neat? VBA code

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Anonymous
442 Views, 3 Replies

How Can I Make This Neat? VBA code

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

 

3 REPLIES 3
Message 2 of 4
CadUser46
in reply to: Anonymous

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
Message 3 of 4
Anonymous
in reply to: CadUser46

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).

Message 4 of 4
Anonymous
in reply to: CadUser46

It works and is so much better thank you!

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

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

Post to forums  

Autodesk Design & Make Report