Most efficient API way to count solid body's faces

Most efficient API way to count solid body's faces

Maxim-CADman77
Advisor Advisor
1,179 Views
10 Replies
Message 1 of 11

Most efficient API way to count solid body's faces

Maxim-CADman77
Advisor
Advisor

I'd like to know which is the fastest way to count solid body's faces.

Please find the IPT with quite a few (23000+ faces) attached.

Apart from geometry it has an iLogic rule embedded that tries to access the face counter using.

 

ThisDoc.Document.ComponentDefinition.SurfaceBodies(1).Faces.Count

 

 

The main problem with the rule - it takes about 10 seconds to get the counter value (which is unacceptably long).

Another (manual) way to count not only faces but all objects is to run BSCT (Ctrl+F7) which takes less than 2 seconds...

 

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
1,180 Views
10 Replies
Replies (10)
Message 2 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support

@Maxim-CADman77,

 

Unfortunately, Inventor API does not have capability like BSCT (CTRL + F7). Please log this wish list at idea station using below link.

 

https://forums.autodesk.com/t5/inventor-ideas/idb-p/v1232

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 11

Maxim-CADman77
Advisor
Advisor
Thank you for suggestion but I need some solution that I can apply just nowadays (not several years later).

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 4 of 11

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Use this instead:

Dim CmdMan As ControlDefinition
    CmdMan = ThisApplication.CommandManager.ControlDefinitions.Item("AppBodySanityCheckCmd")
   	
	CmdMan.Execute
    	' or CmdMan.Execute2 (True)

it is the same as CTRl+F7

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 11

Maxim-CADman77
Advisor
Advisor
Thank you.
This works but AFAIK returns no data at the API level (only at UI level).

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 6 of 11

bradeneuropeArthur
Mentor
Mentor

Hi,

I think Autodesk uses "ApprenticeServer" for this!!

This runs quicker.

Dim a As ApprenticeServer = New ApprenticeServerComponent

        Dim b As ApprenticeServerDocument = a.Open("C:\YOURFILENAME.ipt")
        MsgBox(b.ComponentDefinition.SurfaceBodies(1).Faces.Count)

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 11

Maxim-CADman77
Advisor
Advisor
ApprenticeServer takes even longer (about 17 seconds) to get the first solid body faces count of the sample 😞

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 8 of 11

bradeneuropeArthur
Mentor
Mentor

Think you are right with that..

 

Could it be possible that this kind of information is directly stored in the document anywhere!

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 9 of 11

Maxim-CADman77
Advisor
Advisor

8-second duration difference is not a big deal but recently one of IPTs stored in our corporate vault taked 16minutes to read the counter of 103000+ faces (while BSCT get it done in less than 2 minutes). Quarter of hour seems worth to re-activate the workaround  for this issue... Any further suggestions?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 10 of 11

DRoam
Mentor
Mentor

So I did a quick test that reveals something interesting -- the operation that takes so long isn't actually getting the Count property, it's getting the Faces collection. In other words, this is very slow:

 

Dim faceColl As Faces = ThisDoc.Document.ComponentDefinition.SurfaceBodies(1).Faces

 

But this is very fast:

Dim FC As Integer = faceColl.Count

 

So counting isn't the issue, the issue is generating the collection of thousands of faces. Doesn't exactly help you... but it at least explains why it's so much slower than BSCT. The BSCT just counts the faces, whereas the SurfaceBody.Faces property has to generate a runtime collection of thousands of Face objects.

 

It would be handy to have a "SurfaceBody.Inspect" object that offers properties like "FaceCount", "EdgeCount", etc., so we can query these attributes without having to generate the "Faces", "Edges", etc. collections. Maybe something for the IdeaStation.

 

In the meantime... the question is how to determine how many faces there are without using the "SurfaceBody.Faces" property. I tried to search the API documentation for some kind of API mechanism for "inspecting" surface bodies but I'm not seeing anything.

 

@Maxim-CADman77, assuming BSCT is the only quick way to get a face count right now, would it be acceptable if there were some automated way to open, read, parse, and get the face count from the BSCT window? The main drawback to this is the file has to be open on-screen for it to work. Is that a deal breaker or could that be a possible solution?

0 Likes
Message 11 of 11

Maxim-CADman77
Advisor
Advisor

Yes, my project supposes document opening thus parsing BSCT-report seems the only possible workaround for the current state of Inventor's API...
Its pitty I'm not yet good enough in parsing.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes