The corresponding code from .Net:
Caution, this is just a quick hack and will not work for all types of constraints. The unitsconversion is hardcoded to convert to Inventor.UnitsTypeEnum.kDatabaseLengthUnits
Probably numerous bugs, but they are free
/// <summary>
///A test for DriveConstraint
///</summary>
[TestMethod()]
public void DriveConstraint()
{
Inventor.AssemblyDocument assemblyDocument = GetActiveAssemblyDocument();
assemblyDocument.ModelingSettings.InteractiveContactAnalysis =
Inventor.InteractiveContactAnalysisEnum.kAllComponentsInteractiveContact;
assemblyDocument.ModelingSettings.InteractiveContactSurfaces =
Inventor.InteractiveContactSurfacesEnum.kAllSurfacesInteractiveContact;
foreach (Inventor.AssemblyConstraint constraint in assemblyDocument.ComponentDefinition.Constraints)
{
if(constraint.DriveConstraintSettings.IsInitialized)
{
constraint.DriveConstraintSettings.CollisionDetection = true;
constraint.DriveConstraintSettings.SetIncrement(Inventor.ConstraintIncrementTypeEnum.kIncrementAsAmountOfValue, GetExpressionString(assemblyDocument,2,Inventor.UnitsTypeEnum.kMillimeterLengthUnits));
constraint.DriveConstraintSettings.StartValue = GetExpressionString(assemblyDocument, 0,
Inventor.UnitsTypeEnum.
kMillimeterLengthUnits);
constraint.DriveConstraintSettings.EndValue = GetExpressionString(assemblyDocument, 20,
Inventor.UnitsTypeEnum.
kMillimeterLengthUnits);
constraint.DriveConstraintSettings.GoToStart();
constraint.DriveConstraintSettings.PlayForward();
constraint.DriveConstraintSettings.StartValue = GetExpressionString(assemblyDocument, -20,
Inventor.UnitsTypeEnum.
kMillimeterLengthUnits);
constraint.DriveConstraintSettings.EndValue = GetExpressionString(assemblyDocument, 0,
Inventor.UnitsTypeEnum.
kMillimeterLengthUnits);
constraint.DriveConstraintSettings.GoToEnd();
constraint.DriveConstraintSettings.PlayReverse();
}
}
Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
private string GetExpressionString(Inventor.AssemblyDocument assemblyDocument, double value, Inventor.UnitsTypeEnum unitsTypeEnum)
{
double convertedValue = assemblyDocument.UnitsOfMeasure.ConvertUnits(value, unitsTypeEnum,
Inventor.UnitsTypeEnum.
kDatabaseLengthUnits);
string expressionString=assemblyDocument.UnitsOfMeasure.GetStringFromValue(convertedValue,
Inventor.UnitsTypeEnum.kMillimeterLengthUnits);
return expressionString;
}
public static Inventor.AssemblyDocument GetActiveAssemblyDocument()
{
if (!(InventorUtilities.GetInvetorActiveDocument() is AssemblyDocument))
{
throw new InstanceNotFoundException("No active asseblydocument");
}
Inventor.AssemblyDocument assemblyDocument = InventorUtilities.GetInvetorActiveDocument() as AssemblyDocument;
if (assemblyDocument == null) throw new InstanceNotFoundException("No active asseblydocument");
return assemblyDocument;
}