Message 1 of 5
Isolated strange behavior when using DriveConstraintSettings from .net

Not applicable
11-10-2011
03:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I have managed to isolate unexpected, to me, bahavior for DriveConstraintSettings.
If I use drive the constraint detecting contact everything is fine the first time. If I change the position of assemblycomponentoccurences and do the same again it stops at the same position as the previous run.
I suspect that this is due to internal caching of proxies or something.
See attached code and dataset to reproduce.
Please post suggestions and ideas for how to resolve this.
I installed this but to no use. http://usa.autodesk.com/adsk/servlet/ps/dl/item?siteID=123112&id=17804829&linkID=9242019
using System; using System.Management.Instrumentation; using System.Runtime.InteropServices; using Inventor; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace SimulationInventorHandlerTest.Utilities.Assembly { [TestClass] public class DriveConstraintTest { [TestMethod] public void ProbeTest() { Application inventorAppliaction = GetInventorAppliaction(); AssemblyDocument assemblyDocument = GetActiveAssemblyDocument(inventorAppliaction); MateConstraint mateConstraintX = GetMateConstraintByName(assemblyDocument, "Axis X"); Inventor.MateConstraint mateConstraintZ = GetMateConstraintByName(assemblyDocument, "Axis Z"); assemblyDocument.ModelingSettings.InteractiveContactAnalysis = Inventor.InteractiveContactAnalysisEnum.kAllComponentsInteractiveContact; assemblyDocument.ModelingSettings.InteractiveContactSurfaces = Inventor.InteractiveContactSurfacesEnum.kAllSurfacesInteractiveContact; mateConstraintX.Offset.Expression = "0 mm"; mateConstraintZ.Offset.Expression = "20 mm"; assemblyDocument.Update(); Drive(0, 10, 0.1, mateConstraintX); double stopPosition = mateConstraintX.Offset.ModelValue; mateConstraintX.Offset.Expression = "0 mm"; mateConstraintZ.Offset.Expression = "0 mm"; assemblyDocument.Update(); Drive(0, 10, 0.1, mateConstraintX); if(Math.Abs(stopPosition - mateConstraintX.Offset.ModelValue) < 0.0001) throw new Exception("Stopped at same position as first run!"); } private void Drive(double startValue, double endValue, double incrementSize, MateConstraint mateConstraint ) { mateConstraint.DriveConstraintSettings.CollisionDetection = true; mateConstraint.DriveConstraintSettings.SetIncrement(Inventor.ConstraintIncrementTypeEnum.kIncrementAsAmountOfValue, incrementSize.ToString()); mateConstraint.DriveConstraintSettings.StartValue = startValue.ToString(); mateConstraint.DriveConstraintSettings.EndValue = endValue.ToString(); mateConstraint.DriveConstraintSettings.GoToStart(); mateConstraint.DriveConstraintSettings.PlayForward(); } private static MateConstraint GetMateConstraintByName(AssemblyDocument assemblyDocument, string constraintName) { MateConstraint mateConstraint; Inventor.AssemblyComponentDefinition assemblyComponentDefinition = assemblyDocument.ComponentDefinition; if (!(assemblyComponentDefinition.Constraints[constraintName] is Inventor.MateConstraint)) throw new InstanceNotFoundException("Not a MateConstraint"); mateConstraint = assemblyComponentDefinition.Constraints[constraintName] as Inventor.MateConstraint; if (mateConstraint == null) throw new InstanceNotFoundException("No constraint"); return mateConstraint; } private static AssemblyDocument GetActiveAssemblyDocument(Application inventorAppliaction) { AssemblyDocument assemblyDocument; if (!(inventorAppliaction.ActiveDocument is Inventor.AssemblyDocument)) { throw new InstanceNotFoundException("No active asseblydocument"); } assemblyDocument = inventorAppliaction.ActiveDocument as Inventor.AssemblyDocument; return assemblyDocument; } private static Application GetInventorAppliaction() { Application inventorAppliaction; inventorAppliaction = Marshal.GetActiveObject("Inventor.Application") as Inventor.Application; return inventorAppliaction; } } }