Help - Getting surface area from assembly document

Help - Getting surface area from assembly document

eelrod
Contributor Contributor
1,862 Views
11 Replies
Message 1 of 12

Help - Getting surface area from assembly document

eelrod
Contributor
Contributor

I have an elliptical cone rotated in two planes that is cut with a cylinder in an assembly document. What I would like to do is programmatically (iLogic, VBA, or VB.net) get the surface area of the face after the cut. I was able to get surface areas from part documents using the code (iLogic) below, but I am unable to get it working in an assembly document. Can you help?

Dim oDoc As PartDocument = ThisDoc.Document
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition

Dim st As String =""
For Each oSurfBody As SurfaceBody In oDef.SurfaceBodies
    
    st &= vbNewLine & oSurfBody.Name & vbNewLine
    Dim volume As Double = oSurfBody.Volume(0.00001)
    st &= "volime = " & volume & vbNewLine    
    
    Dim area As Double = 0.0
    For Each oFace As Face In oSurfBody.Faces
        Dim oEval As SurfaceEvaluator = oFace.Evaluator
        area = area + oEval.Area
    Next
    st &= "area = " & area & vbNewLine

Next

Beep
MsgBox(st)

Cone Front.PNGCone Side.PNGCone ISO.png

0 Likes
Accepted solutions (1)
1,863 Views
11 Replies
Replies (11)
Message 2 of 12

chandra.shekar.g
Autodesk Support
Autodesk Support

@eelrod,

 

 

Hoping that below iLogic code may be helpful.

 

Public Sub Main()
    Dim oAssyDoc As AssemblyDocument
    oAssyDoc = ThisApplication.ActiveDocument
    
    Dim oDoc As Document
    For Each oDoc In oAssyDoc.AllReferencedDocuments
        If oDoc.DocumentType = kPartDocumentObject Then
            Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition

			Dim st As String =""
			For Each oSurfBody As SurfaceBody In oDef.SurfaceBodies
			    
			    st &= vbNewLine & oSurfBody.Name & vbNewLine
			    Dim volume As Double = oSurfBody.Volume(0.00001)
			    st &= "volime = " & volume & vbNewLine    
			    
			    Dim area As Double = 0.0
			    For Each oFace As Face In oSurfBody.Faces
			        Dim oEval As SurfaceEvaluator = oFace.Evaluator
			        area = area + oEval.Area
			    Next
			    st &= "area = " & area & vbNewLine

			Next

			Beep
			MsgBox(st)
        End If
    Next
End Sub

To investigate further, can you please provide non confidential Inventor files?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 12

eelrod
Contributor
Contributor

(please see simplified files attached)

 

Unfortunately, this doesn't get the volume or area after it is modified in the assembly. Also, I discovered another problem that I don't know how to fix: the calculated area is far off. I made a rule in each attached file to demonstrate, based on the code shown above. The total surface area in the part file (which I don't care about) should be 39.818 in² but is coming up as 256.892 in². The total surface area in the assembly file (which I do care about) should be 8.593 in² but is coming up as the same value as the part file, 256.892 in².

Do you have any ideas? Thank you!

0 Likes
Message 4 of 12

eelrod
Contributor
Contributor

@chandra.shekar.g,

Were you able to find time to investigate further?

 

The two issues I have are (from previous post, summarized):

  1. I'm not able to accurately get the surface area.
  2. I'm not able to get the surface area after modifications at the assembly level. (It grabs the area from the part file.)

Thank you sir!

0 Likes
Message 5 of 12

chandra.shekar.g
Autodesk Support
Autodesk Support

@eelrod,

 

As the same part is used in assembly, the total surface area in assembly should be 256.89 in².

 

How is possible to get total surface area in the assembly file as 8.593 in²? Can you please explain difference?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 12

eelrod
Contributor
Contributor

@chandra.shekar.g,

Thank you for asking. I feel we're getting closer to understanding my problems now.

  • Even though the same part is used in the assembly, is it being modified in the assembly document. (Reference "Extrusion 1" in the assembly document.) Please also see the screenshot attached; it shows the original cone overlayed on the one modified at assembly.
  • A surface area of 256.89 in² is definitely wrong. The formula for an elliptical cone's surface area is complex, so if we use the formula for a regular cone instead ( A = πr[r+√(h²+r²)] ) and use the semi-major axis for the radius, we get around 48 in². So it should definitely be much closer to that than 256.89 in². Manually measuring all three surfaces with the measure tool confirms this.

The wong surface area is really confusing for me and I have no idea how to fix that in the code. Do you know of another way of getting the surface area?

And as for my original question, do you know of how to get the surface area for parts that have been modified at assembly?

Thank you kindly, sir!

0 Likes
Message 7 of 12

JamieVJohnson2
Collaborator
Collaborator

I haven't been able to prove this theory using your posted numbers, but here goes anyway:

Fact - Inventor thinks in centimeters, any length value reported back will be in cm via code (because units are always assumed to be in centimeters, unless explicitly converted).  Even when your document is in inches, and your display shows inches, Inventor still processes data in centimeters.

Your numbers could be off a factor of 2.54 squared (no they are not, but it is 2.93 squared, so there may be something else on top of that I'm not able to see).

Aide - for the time being while debugging math issues with Inventor API, I recommend setting drawing units and display units to centimeters until the math is perfect, then setup conversion factors for inches as necessary.

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
Message 8 of 12

JamieVJohnson2
Collaborator
Collaborator

Your spherical cut is subtracting over 60% (9cm length / 24cm length) of the cones length, that definitely shrinks the assembly surface area.

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 9 of 12

chandra.shekar.g
Autodesk Support
Autodesk Support

@eelrod,

 

For further investigation, it is reported to engineering team.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 10 of 12

eelrod
Contributor
Contributor

I didn't know that Inventor processes all data as centimeters, so thank you for that. Adding a conversion ( / 2.54 ^ 2 ) to the iLogic appears to give me the right answer for the part model, so that problem appears to be resolved. However, my main problem is getting the surface area on an assembly where there are modifications at the assembly. Do you know of a way? The code I have currently runs at the assembly level, but returns the unmodified part surface area. Thanks jvj!

0 Likes
Message 11 of 12

JamieVJohnson2
Collaborator
Collaborator
Accepted solution

This should shed some light on your problem:

            Dim asmDoc As AssemblyDocument = invApp.ActiveDocument
           ' Dim sb As SurfaceBody = asmDoc.ComponentDefinition.SurfaceBodies.Item(1)
            Dim sbo As SurfaceBody = asmDoc.ComponentDefinition.Occurrences(1).SurfaceBodies(1)
            Dim sbd As SurfaceBody = asmDoc.ComponentDefinition.Occurrences(1).Definition.SurfaceBodies(1)
           ' Debug.Print(sb.Volume(4))
            Debug.Print(sbo.Volume(4))
            Debug.Print(sbd.Volume(4))

Occurrence's surface bodies are from the modified in assembly occurrence.  However, Occurrences.Definition.SurfaceBodies are from the original part file.

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
Message 12 of 12

eelrod
Contributor
Contributor

Thank you @JamieVJohnson2! This is exactly what I was looking for.

For reference, here's my working iLogic code snippet for use with the previously attached assembly file:

Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument
Dim sbo As SurfaceBodies = oAssyDoc.ComponentDefinition.Occurrences(1).SurfaceBodies

For Each oSurfBody As SurfaceBody In sbo
	For Each oFace As Face In oSurfBody.Faces
		i += 1
		nEachFace = oFace.Evaluator.Area / 2.54 ^ 2
		MsgBox("Surface" & i & " Area = " & nEachFace)
		nAreaTotal += nEachFace
	Next
	MsgBox("Total Area = " & nAreaTotal)
Next

Many thanks to you and @chandra.shekar.g for your efforts!

0 Likes