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: 

Inventor does not report unstable part file geometry -- but here's how you can.

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
DynamicObjects
771 Views, 10 Replies

Inventor does not report unstable part file geometry -- but here's how you can.

Hello forum,

 

We automate Inventor via COM.

Due to human error sometimes despite best efforts to fully constrain them, some of our part files can accidentally include ambiguous features that cause Inventor to become "unstable" -  i.e. Inventor computes a different solution for the same entity on each recompute.  To illustrate this behaviour I have attached an example part file for you. 

 

To reproduce the behaviour open the part file (Inventor 2020 Pro) and import the attached parameters xml file.  Now hit the "Rebuild" button repeatedly and see how Inventor alternates between two possible solutions on each press of the button.  In this example the root cause is a point in the sketch which i highlight with a red circle in the image below. Compare the LHS and RHS images. 

 

image.png

 

The sketch point circled in this sketch is ambiguous and Inventor toggles between solutions for it with every click of the Rebuild button!

 

Note that Inventor doesn't report that this part file or any of its features are unhealthy.

 

I don't want to focus on the above part - it is trivial to fix and is simply an example of the behaviour.

 

The real issue for us is this:  During automation via COM, when we add this part to an assembly and attempt to "combine" this part occurrence with another occurrence in the assembly Inventor crashes on the line where we call the CombineFeatures.Add() method and Inventor disconnects from COM.  In turn our software is also jeopardised. 

 

Note that this part file Combines successfully for 90% of our model builds and it is only edge-cases such as this one where the parameter values happen to achieve an ambiguous recompute situation where this occurs.  However, our models involve hundreds of instances and it only takes one instance like this to cause Inventor to fail and if Inventor stops communicating to COM it crashes our entire build sequence.  Hence for us this is a major issue.

 

Note that Update(), Update2(), Rebuild(), Rebuild2() etc do not report this unstable part geometry.  Likewise iterating the .Features of the part does not report anything unhealthy.  So we cannot detect, predict or manage these edge-cases that we known will cause CombineFeatures.Add()  to fail.

 

So in the absence of a built-in method to detect the unstable geometry, I am currently writing our own workaround as a solution:
My workaround solution is to push the desired parameters to the part file and then .Rebuild() the part file twice and each time report the part file's physical properties (Mass, CoG, Area etc) - and if the values are identical (allowing for rounding errors) both times then the part is stable.  If the values are different the part file is not stable and is exhibiting the behaviour shown in the attached example.

 

I hope this is helpful to others that may come across this behaviour. 

Also, does anyone know if there is a built in method for achieving this already that I an unaware of?
Also, could Autodesk add this as a feature request please or advise a better solution?

 

Regards

Dan

------------------------------------------------------------------------------------------------------------
Atkins Consultants Ltd UK
+19,000 staff (M&E, Civils, Structural, Geotechnical, Environmental and more)
10 REPLIES 10
Message 2 of 11
WCrihfield
in reply to: DynamicObjects

Just a shot in the dark suggestion...Perhaps it would be worthwhile to comb through the geometric feature creation portions of your code, where a sketch is being used, to check if the sketch is solved (fully constrained) before  proceeding to use the sketch.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 11
DynamicObjects
in reply to: WCrihfield

The sketches are fully constrained.  You can have fully constrained sketches with multiple solutions.  The latter is the problem.  Inventor perhaps too easily marks a sketch as 'full constrained'.   A common example is angles which at the time of authorship are in, say, a clockwise direction from something.  If the part is seeded with values that are quite different Inventor can decide that on this occasion it will make the angle be in a counter-clockwise solution.  However despite ambiguity Inventor will mark the sketch as 'fully constrained' and healthy.

------------------------------------------------------------------------------------------------------------
Atkins Consultants Ltd UK
+19,000 staff (M&E, Civils, Structural, Geotechnical, Environmental and more)
Message 4 of 11
alewer
in reply to: DynamicObjects

Interesting problem! I have been vexed by solver "multiple solution" problems before, but never one that alternated in this fashion. I was able to change parameter values to the ones defined in your .xml. I have also attached the part in case anyone else wants to play with it. I get the exact behavior that you describe: namely that geometry alternates on each rebuild.

 

I believe that I have found the cause of the issue and have a suggestion of how to check for this case. Interestingly, the BarrelLength parameter that drives this "flipping" geometry evaluates to a negative value. It looks like the sketch solver attempts to remedy this on each rebuild by switching the direction. However, the value remains negative even after a rebuild, so on the next rebuild the geometry switches again. You might be able to catch this class of error by checking whether a TwoPointDistanceDimConstraint.Parameter.Value evaluates to a negative (instead of or in addition to comparing volume, area, etc. on rebuilds). I am not sure the physical meaning might be intended by having a negative value for this parameter, but I do see how the solver would interpret it this way. I would argue however that Inventor should warn/fail in such a case instead of silently "flipping" this sketch geometry.

 

I have a few additional comment about your techniques overall. First, I have had much better stability when I base sketch constraints off common SketchLines wherever possible. I have attached two images showing a "before" and "after" of this idea as applied to your OD and ODspigot. While these are not the cause of the problem with "flipping" geometry, I think you will have fewer "multiple solution" problems if you apply this technique. See how I have made both geometries depend only on the part centerline? Before doing this, the position of the "OD" line relied on the solved position of the "ODspigot" line, which itself relied on the solved position of the "RIspigot" line. My redimensioning now means that these are all calculated directly from the centerline. In practice, this this allows for much cleaner logic, and the sketch solver seems to give much more stable results from this approach in my experience. I hope this makes sense--if I does not, let me know and I will try to explain differently perhaps with different examples.

 

My final comment is that you might have better stability in practice using OffsetDimConstraints (SketchLine to SketchPoint) wherever possible instead of TwoPointDistanceDimConstraints (SketchPoint to SketchPoint) which you appear to have used exclusively. I do not know why this should matter, but in my experience it seems to help with multiple solutions related problems.

 

Let me know if that helped you or if you have any further questions.

Message 5 of 11
DynamicObjects
in reply to: alewer

@alewer 

 

  1. I agree with you that better technique such as your suggestion to make all dimension relative to the same common origin (rather than chain them relative to each other) would prevent the problem. However I am not able to enforce good practice amongst all staff all of the time and I must presume that mistakes do and will happen, and attempt to detect and handle these situations.  - I am aware there are limits to how much software can or should correct for human error!!  
  2. Regarding your observations about TwoPointDistanceDimConstraint.Parameter.Value evaluating to a negative:  I am familiar with the fact that Inventor ignores the sign for dimensions and simply applies the magnitude (with the exception of a few features such as workplanes and 3D point coordinates).  You said :

    "It looks like the sketch solver attempts to remedy this on each rebuild by switching the direction. However, the value remains negative even after a rebuild, so on the next rebuild the geometry switches again. "

    I am not convinced you are correct.  This is why:  To test your theory I attach a really simple sketch of a rectangle Size1 by Size2 where Size2 is bigger than Size1
    image.pngThe rectangle is positioned a distance (Size1 - Size2) from the origin.  I.e. a negative number, always.  According to your theory, clicking the Rebuild button would cause the sketch solver to attempt to make the driven dimensions, d2 and d3, positive, and in so doing, manifest the behaviour of toggling between the possible positions for the rectangles top-left point... 2 possible positions on the x-axis (left of the origin by the magnitude (Size1-Size2) or right of the origin by the same magnitude OR similarly the two possible positions on the y-axis. 

    However, we don't get that behaviour.  No instability exists.  No parameter values change.  No points in the sketch move.  Clicking rebuild yields the same solution repeatedly.
------------------------------------------------------------------------------------------------------------
Atkins Consultants Ltd UK
+19,000 staff (M&E, Civils, Structural, Geotechnical, Environmental and more)
Message 6 of 11

Also I've just discovered that Inventor toggles the geometry with each click of Rebuild only when you are editing the ipt part file.   So by contrast, if you add the part to an assembly, each occurrence you add, which i think I'm correct in saying is a proxy of the part's bodies, stays static, honouring the geometry last saved in the part file ... i.e. in the assembly document clicking Rebuild of the assembly does not toggle the geometry of the part in the way it does when editing the part file.  But if you open the part file up and hit Rebuild and save and return to the assembly and Rebuild or Update then all occurrences of that part flip to the new geometry solution saved in the part file!

------------------------------------------------------------------------------------------------------------
Atkins Consultants Ltd UK
+19,000 staff (M&E, Civils, Structural, Geotechnical, Environmental and more)
Message 7 of 11
alewer
in reply to: DynamicObjects

I see one important difference between the original file (StubPipeByCoords,LoD350,v02_1.ipt) and your recent screenshot: the equation in the original file uses a reference dimension, while your newest screenshot appears not to. I cannot be sure because you have only a screenshot and have not attached a file.

 

I was able to create an example file where sketch geometry alternates with rebuilds; see attached Instability.ipt. I can replicate this if my parameter both:

  1. Evaluates to a negative value.
  2. Consumes (references) a reference dimension/parameter.

While I believe this is 100% an Inventor bug, I would still suggest for now that you incorporate a check for negative parameter values for point to point dimensions into your code. Regardless of how Inventor handles such a case, I see no sensible interpretation for a negative distance between two points.

Message 8 of 11
DynamicObjects
in reply to: alewer

@alewer - you're right!  That's really interesting. I downloaded your part and altered the formula of d20 to deduct 6 from 3 rather than 6.78 from 3 ... so still always yielding a negative value, but this time the value (6) derives from a model parameter rather than a reference parameter (6.78).   The toggling behaviour in the sketch is gone!  Putting it back to a reference parameter and the toggling behaviour is back!!

 

image.png

 

I wonder is this intentional or a bug in Inventor as you suggest?

 

So, your suggestion about iterating the dimensions of a sketch and checking if a TwoPointDistanceDimConstraint.Parameter.Value evaluates to a negative would presumably have to also meet the condition that it's formula included a reference parameter since as you can see from before and after the small tweak to d20's formula, whilst it still always evaluates as a negative value the flipping sketch behaviour is not always present.

(In addition I am concerned for my own team that the authors of our library of a great many part files , knowing that Inventor ignores sign of a value, and especially where they have made use of sin, consine and angles in formulas may not have felt they needed to wrap outcomes with an ABS() or other technique to ensure positive values.  ..So I think for my own project, I will stick with evaluating the physical properties as a means of detecting the behaviour.)

Thanks for pin-pointing the cause of the flip to the reference parameters !

------------------------------------------------------------------------------------------------------------
Atkins Consultants Ltd UK
+19,000 staff (M&E, Civils, Structural, Geotechnical, Environmental and more)
Message 9 of 11
DynamicObjects
in reply to: alewer

@alewer@WCrihfield  - just to say that I've opened a new post here for the purpose of reporting the possible bug to Autodesk using your example sketch @alewer rather than cloud the issue with the workarounds etc that we were discussing on this post.

------------------------------------------------------------------------------------------------------------
Atkins Consultants Ltd UK
+19,000 staff (M&E, Civils, Structural, Geotechnical, Environmental and more)
Message 10 of 11

Further to explaining the workaround in general terms, I've hacked out this quick VBA method that you can call in order to test whether the occurrences added to your assembly are both fully healthy (no unhealthy features), and that their geometry is stable.

 

One word of caution:  Inventor's .Rebuild2() method returns FALSE even if the features that are unhealthy are suppressed features.  So if you want to ignore the suppressed features you will need to amend the line "OccIsHealthy = OccDoc.Rebuild2(True)" to something a little more rigorous such as your own function to iterate the OccPartDef.Features collection and check the .Suppressed property and the .HealthStatus property of each feature to suit your purposes. 

 

 

Option Explicit

Public Type PhysProps
    CentreOfMassX As Double
    CentreOfMassY As Double
    CentreOfMassZ As Double
    Volume As Double
    Mass As Double
    Area As Double
End Type

Public Sub ExampleUsage()
    Dim I As Inventor.Application
    Set I = ThisApplication
    Dim a As AssemblyDocument
    Set a = I.ActiveDocument
    Debug.Print a.DisplayName & ".IsHealthyAndStable=" & IsHealthyAndStable(a)
End Sub

Public Function IsHealthyAndStable(ByRef ThisAssembly As AssemblyDocument, Optional ByVal DecPlaces As Integer = 3) As Boolean
    Dim Occs As ComponentOccurrences
    Set Occs = ThisAssembly.ComponentDefinition.Occurrences
    Dim Occ As ComponentOccurrence
    For Each Occ In Occs
        Dim OccPartDef As PartComponentDefinition
        Set OccPartDef = Occ.Definition
        Dim OccMassProps As Inventor.MassProperties
        Set OccMassProps = OccPartDef.MassProperties
        Dim GeometryBefore As PhysProps
        GeometryBefore.Area = OccMassProps.Area
        GeometryBefore.Mass = OccMassProps.Mass
        GeometryBefore.Volume = OccMassProps.Volume
        ' Some partfiles might not have a surface body - e.g. they consist only of sketch(es)
        ' In which case you cannot obtain the .CentreOfMass
        On Error Resume Next
            GeometryBefore.CentreOfMassX = OccMassProps.CenterOfMass.x
            GeometryBefore.CentreOfMassY = OccMassProps.CenterOfMass.y
            GeometryBefore.CentreOfMassZ = OccMassProps.CenterOfMass.z
        On Error GoTo 0
        Dim OccDoc As PartDocument
        Set OccDoc = Occ.Definition.Document
        Dim OccIsHealthy As Boolean
        OccIsHealthy = OccDoc.Rebuild2(True)
        ThisAssembly.Rebuild
        If Not OccIsHealthy Then Exit For ' Inventor reports unhealthy features - exit
        If Round(GeometryBefore.Area, DecPlaces) <> Round(OccMassProps.Area, DecPlaces) Then OccIsHealthy = False: Exit For
        If Round(GeometryBefore.Mass, DecPlaces) <> Round(OccMassProps.Mass, DecPlaces) Then OccIsHealthy = False: Exit For
        If Round(GeometryBefore.Volume, DecPlaces) <> Round(OccMassProps.Volume, DecPlaces) Then OccIsHealthy = False: Exit For
        ' Some partfiles might not have a surface body - e.g. they consist only of sketch(es)
        ' In which case you cannot obtain the .CentreOfMass
        On Error Resume Next
            If Round(GeometryBefore.CentreOfMassX, DecPlaces) <> Round(OccMassProps.CenterOfMass.x, DecPlaces) Then OccIsHealthy = False: Exit For
            If Round(GeometryBefore.CentreOfMassY, DecPlaces) <> Round(OccMassProps.CenterOfMass.y, DecPlaces) Then OccIsHealthy = False: Exit For
            If Round(GeometryBefore.CentreOfMassZ, DecPlaces) <> Round(OccMassProps.CenterOfMass.z, DecPlaces) Then OccIsHealthy = False: Exit For
        On Error GoTo 0
    Next
    IsHealthyAndStable = OccIsHealthy
End Function

 

 

 

i'll be needing to transcribe it to c# shortly, so I'll post that when i get to it.

 

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

And pretty much the same thing in c#..

 

 

 

private struct PhysProps
{
	public double Mass;
	public double Area;
	public double Volume;
	public double CenterOfMassX;
	public double CenterOfMassY;
	public double CenterOfMassZ;
}

private static bool UnsuppressedFeaturesAreHealthy(ComponentOccurrence Occ)
{
	// iterate the occurrences features and check their health
	PartComponentDefinition PCD = Occ.Definition as PartComponentDefinition;
	foreach (PartFeature feature in PCD.Features)
	{
		if (feature.Suppressed) continue;
		if (feature.HealthStatus != HealthStatusEnum.kUpToDateHealth) return false;
	}
	return true;
}

private static bool IsHealthyAndStable(ComponentOccurrence Occ, int DecPlaces = 3)
{
	// ensure the part file is up to date for any changed parameter values
	PartComponentDefinition PCD = Occ.Definition as PartComponentDefinition;
	PartDocument OccDoc = PCD.Document as PartDocument;
	OccDoc.Rebuild2(AcceptErrorsAndContinue: true);

	// exit if the occurrence is not healthy
	bool IsHealthy = UnsuppressedFeaturesAreHealthy(Occ);
	if (!IsHealthy) return false;

	// otherwise obtain the occurrence's initial geometry

	MassProperties OccMassProps = PCD.MassProperties;
	PhysProps GeometryBefore;
	GeometryBefore.Area = OccMassProps.Area;
	GeometryBefore.Mass = OccMassProps.Mass;
	GeometryBefore.Volume = OccMassProps.Volume;
	try  // some partfiles might not have a surface body - e.g. they consist only of sketch(es)
	{
		GeometryBefore.CenterOfMassX = OccMassProps.CenterOfMass.X;
		GeometryBefore.CenterOfMassY = OccMassProps.CenterOfMass.Y;
		GeometryBefore.CenterOfMassZ = OccMassProps.CenterOfMass.Z;
	}
	catch (Exception) // in which case you cannot obtain the .CentreOfMass 
	{
		GeometryBefore.CenterOfMassX = 0;
		GeometryBefore.CenterOfMassY = 0;
		GeometryBefore.CenterOfMassZ = 0;
	}

	// now rebuild the part file to see if it changes its geometry
	IsHealthy = OccDoc.Rebuild2(AcceptErrorsAndContinue: true); 
	if (!IsHealthy) return false;

	// check if its rebuilt geometry matches its initial geometry
	if (!IsMatch(GeometryBefore.Area, OccMassProps.Area, DecPlaces)) return false;
	if (!IsMatch(GeometryBefore.Mass, OccMassProps.Mass, DecPlaces)) return false;
	if (!IsMatch(GeometryBefore.Volume, OccMassProps.Volume, DecPlaces)) return false;
	try
	{
		if (!IsMatch(GeometryBefore.CenterOfMassX, OccMassProps.CenterOfMass.X, DecPlaces)) return false;
		if (!IsMatch(GeometryBefore.CenterOfMassY, OccMassProps.CenterOfMass.Y, DecPlaces)) return false;
		if (!IsMatch(GeometryBefore.CenterOfMassZ, OccMassProps.CenterOfMass.Z, DecPlaces)) return false;
	}
	catch (Exception) { }
	return true;
}

private static bool IsMatch(double value1, double value2, int DecPlaces)
{
	return Math.Round(value1, DecPlaces, MidpointRounding.AwayFromZero) == Math.Round(value2, DecPlaces, MidpointRounding.AwayFromZero);
}

 

 

------------------------------------------------------------------------------------------------------------
Atkins Consultants Ltd UK
+19,000 staff (M&E, Civils, Structural, Geotechnical, Environmental and more)

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report