Bug: SurfaceBody.IsEntityValid fails for C#

Bug: SurfaceBody.IsEntityValid fails for C#

DynamicObjects
Advocate Advocate
745 Views
5 Replies
Message 1 of 6

Bug: SurfaceBody.IsEntityValid fails for C#

DynamicObjects
Advocate
Advocate

Hello Autodesk, I am reporting a bug in Inventor:

 

Calling SurfaceBody.IsEntityValid() from VBA succeeds.

Calling SurfaceBody.IsEntityValid() from C# fails.

 

Both code samples below are run on the same Part file, and the same version of Inventor Professional 2020.

Here is the VBA code which works:

 

image.png

You can see from the Immediate window that all properties report correctly for the two solids in the model; 'Solid9' and 'Solid19'.

 

Now the same properties are requested via C# code below which fails:

image.png

Note that you can see both in the Console window and in VS lines 44, 45 and 46 that Surface Body 'Solid9' was able to return the properties .IsSolid, .Visible and .IsTransient, but fails with a COM exception for the method .IsEntityValid().

 

For your inspection and to reproduce the behaviour I have attached the part file used in this demo.

 

Please can you advise of a workaround or a fix ?

Best regards

Dan

------------------------------------------------------------------------------------------------------------
Atkins Consultants Ltd UK
+19,000 staff (M&E, Civils, Structural, Geotechnical, Environmental and more)
0 Likes
Accepted solutions (1)
746 Views
5 Replies
Replies (5)
Message 2 of 6

bradeneuropeArthur
Mentor
Mentor

Hi,

 

I see a difference:

Try this in VBA too like you do in C#

for each SB in Pdef.SurfaceBodies

Debug.print.....

next

Gives this also a error?

 

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 3 of 6

DRoam
Mentor
Mentor
Accepted solution

Hm, I'm getting the same error in iLogic with this simple rule, run in a part with nothing but a Box primitive modeled:

 

Dim oThisDoc As Inventor.PartDocument = ThisDoc.Document

For Each sb As SurfaceBody In oThisDoc.ComponentDefinition.SurfaceBodies
	MsgBox(sb.IsEntityValid)
Next

 

I tried it with and without the parentheses after "IsEntityValid", didn't make a difference.

 

This does seem to be a bug in the API. @johnsonshiue can this be logged?

 

@DynamicObjects, in the meantime, I was able to get it to return a value by providing it with "dummy" values for the first and third arguments, and the default value (3) for the second argument, like this:

 

MsgBox(sb.IsEntityValid(Nothing, 3, Nothing))

 

 Could you try that and see if it works for your C# application? (EDIT: Note that in C#, I believe the "Nothing" should be replaced with "null".)

0 Likes
Message 4 of 6

DynamicObjects
Advocate
Advocate

Just confirming for you that

for each SB in Pdef.SurfaceBodies

has the identical successful outcome in VBA as 

Dim SurfaceBodies As SurfaceBodies
Set SurfaceBodies = PDef.SurfaceBodies
For Each SB In SurfaceBodies

and that conversely in C# you also get failure for either construct.

 

------------------------------------------------------------------------------------------------------------
Atkins Consultants Ltd UK
+19,000 staff (M&E, Civils, Structural, Geotechnical, Environmental and more)
0 Likes
Message 5 of 6

DynamicObjects
Advocate
Advocate
@DRoam - I confirm that adding the explicit arguments null, 3, null to the c# call does indeed result in success ! Thanks for your help on this.
------------------------------------------------------------------------------------------------------------
Atkins Consultants Ltd UK
+19,000 staff (M&E, Civils, Structural, Geotechnical, Environmental and more)
Message 6 of 6

DRoam
Mentor
Mentor

Glad it worked! Hopefully the bug can still be fixed to save others from going through the same trouble.

0 Likes