- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Fastest Way To Access Point/Vector Information to Get Center of Mass
Hello,
As the title suggests, I am looking for speed-saving methods to access underlying geometric information of Points, Vectors, etc. Namely, I am looking to get the center of mass of an EdgeLoop. Two methods I have come up with to get this are
edgeLoop.RangeBox.MinPoint.GetPointData(ref minPtData); edgeLoop.RangeBox.MaxPoint.GetPointData(ref maxPtData);
then scaling by half and getting to the center, or the more obvious method of collecting the start/end point of each edge and getting the average.
The problem is that the Inventor API calls are incredibly slow, even just to access properties. The above two lines take ~200ms which means when I collect on the order of 100/1000 center points, this takes way too much time to be viable.
Does anyone have an idea or know how to do this more efficiently? I have locally made versions of Points and Vectors to ease with the math once they are there, but to actually get the information from a Part/Assembly is where I am struggling.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I ran a quick test in VBA to grab RangeBox coords on all planar surfaces.
Sub EdgeLoopTest()
Dim app As Application
Set app = ThisApplication
Dim doc As Document
Set doc = app.ActiveDocument
Dim startTime As Date, endTime As Date
startTime = Now()
If doc.DocumentType = kPartDocumentObject Then
Dim count As Integer
Dim pDoc As PartDocument
Set pDoc = doc
Dim cDef As ComponentDefinition
Set cDef = pDoc.ComponentDefinition
Dim srfBods As SurfaceBodies
Set srfBods = cDef.SurfaceBodies
Dim srfBod As SurfaceBody
For Each srfBod In srfBods
If srfBod.IsSolid Then
Dim sFaces As Faces
Set sFaces = srfBod.Faces
Dim sFace As Face
Dim eLoop As EdgeLoop
For Each sFace In sFaces
If sFace.SurfaceType = kPlaneSurface Then
For Each eLoop In sFace.EdgeLoops
'Dim x1 As Integer, x2 As Integer, y1 As Integer
'Dim y2 As Integer, z1 As Integer, z2 As Integer
Dim mn() As Double
Dim mx() As Double
eLoop.RangeBox.MinPoint.GetPointData mn
eLoop.RangeBox.MaxPoint.GetPointData mx
'x1 = eLoop.RangeBox.MinPoint.x
'y1 = eLoop.RangeBox.MinPoint.y
'z1 = eLoop.RangeBox.MinPoint.z
'x2 = eLoop.RangeBox.MaxPoint.x
'y2 = eLoop.RangeBox.MaxPoint.y
'z2 = eLoop.RangeBox.MaxPoint.z
count = count + 1
Next
End If
Next
End If
Next
End If
endTime = Now()
End SubThe part I tested had over 4800 faces and it ran in less than a second. I tried it with both the GetPointData and directly getting the XYZ properties. Same amount of time on both ways. I haven't tried it in an addin in c#. I'm not sure why it's so slow for you?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Oh wow, that is very interesting...perhaps it is just this slow in the debugging environment? I will try this in a 'release' and report back here.
It's nice to know that it is capable of working so quickly, this would solve all my problems.
Thank you for taking the time to test this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I just re-ran the test in a c# addin in debug. Same results, under a second for 4800+ faces.
private void EdgeLoopTest()
{
Inventor.SurfaceBodies srfBodies = ((Inventor.PartDocument)Props.Document).ComponentDefinition.SurfaceBodies;
int count = 0;
DateTime start = DateTime.Now;
foreach (SurfaceBody body in srfBodies)
{
if (body.IsSolid)
{
foreach (Face face in body.Faces)
{
if (face.SurfaceType == SurfaceTypeEnum.kPlaneSurface)
{
foreach (EdgeLoop loop in face.EdgeLoops)
{
double[] minPt = new double[2];
double[] maxPt = new double[2];
loop.RangeBox.MinPoint.GetPointData(ref minPt);
loop.RangeBox.MaxPoint.GetPointData(ref maxPt);
++count;
}
}
}
}
}
DateTime end = DateTime.Now;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Strange, I ran your exact code on my computer and it took 23 seconds, both in debug and release mode. The computer is far from slow for every other application, so this is very bizarre...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm at a loss. What was your final face count? I guess you could try a stand-alone app and try it using Apprentice. I don't think it would be a version issue, but I'm on Inventor Pro 2017.