Autodesk Inventor Customization
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
DriveConst raintSetti ngs.PlayFo rward does not animate nor detect contact
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I played around with the drive constraint and detect contact. It looks really nice and have potential to be really useful.
I wrote a small snippet to try iot from code, but ran into some problems.
Public Sub driveConstraint()
' Dim testDoc As AssemblyDocument
Set testDoc = ThisApplication.ActiveDocument
Dim constraint As AssemblyConstraint
For Each constraint In testDoc.ComponentDefinition.Constraints
If constraint.DriveConstraintSettings.IsInitialized Then
Exit For
End If
Next
constraint.DriveConstraintSettings.GoToStart
constraint.DriveConstraintSettings.PlayForward
End Sub
I see two things that differ from when I run the constraint from code compared to when I do the same via inventor GUI.
PlayForward moves the constraint to the end in one step.
Neither collision detection nor contact detection works.
What have i done wrong?
Inventor Professional 2012 SP1 (25 seats with subscription)
Windows 7 64 bit
Lenovo D20, 12 GB RAM, Intel Xeon X5687 3.6 GHz, SSD
Quadro 4000, driver 8.17.12.9573, dual monitors
SpacePilot, driver version 6.15.3 Firmware 3.12
Solved! Go to Solution.
Re: DriveConst raintSetti ngs.PlayFo rward does not animate nor detect contact
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Inventor 2012 64 Installed SP1, still does not work.
Added some more nonsense code but it does not animate.
Public Sub driveConstraint()
Dim testDoc As AssemblyDocument
Set testDoc = ThisApplication.ActiveDocument
Dim constraint As AssemblyConstraint
For Each constraint In testDoc.ComponentDefinition.Constraints
If constraint.DriveConstraintSettings.IsInitialized Then
Exit For
End If
Next
Call constraint.DriveConstraintSettings.GoToStart
Call constraint.DriveConstraintSettings.PlayForward
Call constraint.DriveConstraintSettings.PlayReverse
Call constraint.DriveConstraintSettings.StepForward
Call constraint.DriveConstraintSettings.StepReverse
End Sub
Inventor Professional 2012 SP1 (25 seats with subscription)
Windows 7 64 bit
Lenovo D20, 12 GB RAM, Intel Xeon X5687 3.6 GHz, SSD
Quadro 4000, driver 8.17.12.9573, dual monitors
SpacePilot, driver version 6.15.3 Firmware 3.12
Re: DriveConst raintSetti ngs.PlayFo rward does not animate nor detect contact
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I'm on to something, it seems Inventor does not like the startvalue to be greater than the endvalue. Gonna play around som more and see if I can isolate it.
Inventor Professional 2012 SP1 (25 seats with subscription)
Windows 7 64 bit
Lenovo D20, 12 GB RAM, Intel Xeon X5687 3.6 GHz, SSD
Quadro 4000, driver 8.17.12.9573, dual monitors
SpacePilot, driver version 6.15.3 Firmware 3.12
Re: DriveConst raintSetti ngs.PlayFo rward does not animate nor detect contact
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Now it kinda works, Inventor does not sem to like the StartValue to be less than the EndValue.
The following code animates properly.
Public Sub MeasureByContact()
Dim assyDoc As AssemblyDocument
Set assyDoc = ThisApplication.ActiveDocument
Dim oConstraint As AssemblyConstraint
For Each oConstraint In assyDoc.ComponentDefinition.Constraints
If oConstraint.DriveConstraintSettings.IsInitialized Then
With oConstraint.DriveConstraintSettings
.StartValue = 0
.EndValue = 20
.GoToStart
.PlayForward
.StartValue = -20
.EndValue = 0
.GoToEnd
.PlayReverse
End With
End If
Next
End SubOne thing remains, to stop at contact. The document is setup to detect contact and when I drive the constraint manually it stops perfectly on contact. When I run it from code it does not stop. Gonna dive into it, please post suggestions if you guys have any.
Inventor Professional 2012 SP1 (25 seats with subscription)
Windows 7 64 bit
Lenovo D20, 12 GB RAM, Intel Xeon X5687 3.6 GHz, SSD
Quadro 4000, driver 8.17.12.9573, dual monitors
SpacePilot, driver version 6.15.3 Firmware 3.12
Re: DriveConst raintSetti ngs.PlayFo rward does not animate nor detect contact
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
CollisionDetection does not seem to have the same meaning from the API as from the GUI setting it to true gives me the behaviour I want.
The "Activate Contact Solver" seems to be toggled automatically.
One word of caution, if the stepsize is to large the contact can fail to be detected.
Public Sub MeasureByContact()
Dim assyDoc As AssemblyDocument
Set assyDoc = ThisApplication.ActiveDocument
Dim oConstraint As AssemblyConstraint
assyDoc.ModelingSettings.InteractiveContactAnalysi s = kAllComponentsInteractiveContact
assyDoc.ModelingSettings.InteractiveContactSurface s = kAllSurfacesInteractiveContact
For Each oConstraint In assyDoc.ComponentDefinition.Constraints
If oConstraint.DriveConstraintSettings.IsInitialized Then
With oConstraint.DriveConstraintSettings
.CollisionDetection = True
.StartValue = 0
.EndValue = 20
.GoToStart
.PlayForward
.StartValue = -20
.EndValue = 0
.GoToEnd
.PlayReverse
End With
End If
Next
End Sub
Inventor Professional 2012 SP1 (25 seats with subscription)
Windows 7 64 bit
Lenovo D20, 12 GB RAM, Intel Xeon X5687 3.6 GHz, SSD
Quadro 4000, driver 8.17.12.9573, dual monitors
SpacePilot, driver version 6.15.3 Firmware 3.12
Re: DriveConst raintSetti ngs.PlayFo rward does not animate nor detect contact
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.InteractiveConta ctAnalysis =
Inventor.InteractiveContactAnalysisEnum.kAllCompon entsInteractiveContact;
assemblyDocument.ModelingSettings.InteractiveConta ctSurfaces =
Inventor.InteractiveContactSurfacesEnum.kAllSurfac esInteractiveContact;
foreach (Inventor.AssemblyConstraint constraint in assemblyDocument.ComponentDefinition.Constraints)
{
if(constraint.DriveConstraintSettings.IsInitialize d)
{
constraint.DriveConstraintSettings.CollisionDetect ion = true;
constraint.DriveConstraintSettings.SetIncrement(In ventor.ConstraintIncrementTypeEnum.kIncrementAsAmo untOfValue, GetExpressionString(assemblyDocument,2,Inventor.Un itsTypeEnum.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.G etStringFromValue(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;
}
Inventor Professional 2012 SP1 (25 seats with subscription)
Windows 7 64 bit
Lenovo D20, 12 GB RAM, Intel Xeon X5687 3.6 GHz, SSD
Quadro 4000, driver 8.17.12.9573, dual monitors
SpacePilot, driver version 6.15.3 Firmware 3.12
Re: DriveConst raintSetti ngs.PlayFo rward does not animate nor detect contact
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Refactored it a bit nicer:
public static class AssemblyConstraintUtilities
{
public static void DriveConstraint(Inventor.AssemblyConstraint assemblyConstraint, double fromPosition, double toPosition, Inventor.UnitsTypeEnum unitsTypeEnum, bool analyzeContact)
{
if (assemblyConstraint == null) throw new ArgumentNullException("assemblyConstraint");
if (Math.Abs(fromPosition - toPosition) < double.Epsilon) throw new InvalidOperationException("Startvalue == Endvalue");
Inventor.AssemblyDocument assemblyDocument = assemblyConstraint.Parent.Document;
Inventor.UnitsOfMeasure unitsOfMeasure = assemblyDocument.UnitsOfMeasure;
assemblyDocument.ModelingSettings.InteractiveConta ctAnalysis = Inventor.InteractiveContactAnalysisEnum.kAllCompon entsInteractiveContact;
assemblyDocument.ModelingSettings.InteractiveConta ctSurfaces = Inventor.InteractiveContactSurfacesEnum.kAllSurfac esInteractiveContact;
Inventor.UnitsTypeEnum dataBaseUnitEnum = GetDataBaseUnitEnum(assemblyConstraint);
assemblyConstraint.DriveConstraintSettings.Collisi onDetection = analyzeContact;
string incrementExpressionString = InventorUtilities.GetExpressionString(unitsOfMeasu re, 1, unitsTypeEnum, dataBaseUnitEnum);
assemblyConstraint.DriveConstraintSettings.SetIncr ement(Inventor.ConstraintIncrementTypeEnum.kIncrem entAsAmountOfValue, incrementExpressionString);
string fromExpressionString = InventorUtilities.GetExpressionString(unitsOfMeasu re, fromPosition, unitsTypeEnum, dataBaseUnitEnum);
string toExpressionString = InventorUtilities.GetExpressionString(unitsOfMeasu re, toPosition, unitsTypeEnum, dataBaseUnitEnum);
if (fromPosition > toPosition)
{
DriveConstraintInNegativeDirection(assemblyConstra int, fromExpressionString, toExpressionString);
}
else if (fromPosition < toPosition)
{
DriveConstraintInPositiveDirection(assemblyConstra int, fromExpressionString, toExpressionString);
}
}
private static void DriveConstraintInNegativeDirection(AssemblyConstra int assemblyConstraint, string fromExpressionString, string toExpressionString)
{
assemblyConstraint.DriveConstraintSettings.StartVa lue = toExpressionString;
assemblyConstraint.DriveConstraintSettings.EndValu e = fromExpressionString;
assemblyConstraint.DriveConstraintSettings.GoToEnd ();
assemblyConstraint.DriveConstraintSettings.PlayRev erse();
}
private static void DriveConstraintInPositiveDirection(AssemblyConstra int assemblyConstraint, string fromExpressionString, string toExpressionString)
{
assemblyConstraint.DriveConstraintSettings.StartVa lue = fromExpressionString;
assemblyConstraint.DriveConstraintSettings.EndValu e = toExpressionString;
assemblyConstraint.DriveConstraintSettings.GoToSta rt();
assemblyConstraint.DriveConstraintSettings.PlayFor ward();
}
private static UnitsTypeEnum GetDataBaseUnitEnum(AssemblyConstraint assemblyConstraint)
{
Inventor.UnitsTypeEnum dataBaseUnitEnum;
if ((assemblyConstraint is Inventor.MateConstraint) || (assemblyConstraint is Inventor.FlushConstraint) ||
(assemblyConstraint is Inventor.InsertConstraint) || (assemblyConstraint is Inventor.TangentConstraint))
{
dataBaseUnitEnum = Inventor.UnitsTypeEnum.kDatabaseLengthUnits;
}
else if (assemblyConstraint is Inventor.AngleConstraint)
{
dataBaseUnitEnum = Inventor.UnitsTypeEnum.kDatabaseAngleUnits;
}
else
{
throw new InstanceNotFoundException("Unknown constraint type");
}
return dataBaseUnitEnum;
}
}
Inventor Professional 2012 SP1 (25 seats with subscription)
Windows 7 64 bit
Lenovo D20, 12 GB RAM, Intel Xeon X5687 3.6 GHz, SSD
Quadro 4000, driver 8.17.12.9573, dual monitors
SpacePilot, driver version 6.15.3 Firmware 3.12
