<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: DriveConstraintSettings.PlayForward does not animate nor detect contact in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/driveconstraintsettings-playforward-does-not-animate-nor-detect/m-p/3212192#M138509</link>
    <description>&lt;P&gt;Now it kinda works, Inventor does not sem to like the StartValue to be less than the EndValue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following code animates properly.&lt;/P&gt;&lt;PRE&gt;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 Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;One 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.&lt;/P&gt;</description>
    <pubDate>Tue, 01 Nov 2011 13:03:05 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2011-11-01T13:03:05Z</dc:date>
    <item>
      <title>DriveConstraintSettings.PlayForward does not animate nor detect contact</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/driveconstraintsettings-playforward-does-not-animate-nor-detect/m-p/3211628#M138506</link>
      <description>&lt;P&gt;I played around with the drive constraint and detect contact. It looks really nice and have potential to be really useful.&lt;BR /&gt;&lt;BR /&gt;I wrote a small snippet to try iot from code, but ran into some problems.&lt;/P&gt;&lt;PRE&gt; 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&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I see two things that differ from when I run the constraint from code compared to when I do the same via inventor GUI.&lt;BR /&gt;PlayForward moves the constraint to the end in one step.&lt;BR /&gt;Neither collision detection nor contact detection works.&lt;BR /&gt;What have i done wrong?&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2011 20:55:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/driveconstraintsettings-playforward-does-not-animate-nor-detect/m-p/3211628#M138506</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-10-31T20:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: DriveConstraintSettings.PlayForward does not animate nor detect contact</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/driveconstraintsettings-playforward-does-not-animate-nor-detect/m-p/3211686#M138507</link>
      <description>&lt;P&gt;Inventor 2012 64 Installed SP1, still does not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Added some more nonsense code but it does not animate.&lt;/P&gt;&lt;PRE&gt; 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&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2011 21:37:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/driveconstraintsettings-playforward-does-not-animate-nor-detect/m-p/3211686#M138507</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-10-31T21:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: DriveConstraintSettings.PlayForward does not animate nor detect contact</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/driveconstraintsettings-playforward-does-not-animate-nor-detect/m-p/3211706#M138508</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2011 22:01:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/driveconstraintsettings-playforward-does-not-animate-nor-detect/m-p/3211706#M138508</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-10-31T22:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: DriveConstraintSettings.PlayForward does not animate nor detect contact</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/driveconstraintsettings-playforward-does-not-animate-nor-detect/m-p/3212192#M138509</link>
      <description>&lt;P&gt;Now it kinda works, Inventor does not sem to like the StartValue to be less than the EndValue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following code animates properly.&lt;/P&gt;&lt;PRE&gt;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 Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;One 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.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2011 13:03:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/driveconstraintsettings-playforward-does-not-animate-nor-detect/m-p/3212192#M138509</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-11-01T13:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: DriveConstraintSettings.PlayForward does not animate nor detect contact</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/driveconstraintsettings-playforward-does-not-animate-nor-detect/m-p/3212304#M138510</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The "Activate Contact Solver" seems to be toggled automatically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One word of caution, if the stepsize is to large the contact can fail to be detected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Sub MeasureByContact()
    Dim assyDoc As AssemblyDocument
    Set assyDoc = ThisApplication.ActiveDocument
    Dim oConstraint As AssemblyConstraint
    assyDoc.ModelingSettings.InteractiveContactAnalysis = kAllComponentsInteractiveContact
    assyDoc.ModelingSettings.InteractiveContactSurfaces = 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&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2011 14:30:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/driveconstraintsettings-playforward-does-not-animate-nor-detect/m-p/3212304#M138510</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-11-01T14:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: DriveConstraintSettings.PlayForward does not animate nor detect contact</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/driveconstraintsettings-playforward-does-not-animate-nor-detect/m-p/3213882#M138511</link>
      <description>&lt;P&gt;The corresponding code from .Net:&lt;/P&gt;&lt;P&gt;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&lt;/P&gt;&lt;P&gt;Probably numerous bugs, but they are free&lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://forums.autodesk.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        /// &amp;lt;summary&amp;gt;
        ///A test for DriveConstraint
        ///&amp;lt;/summary&amp;gt;
        [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;
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2011 14:20:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/driveconstraintsettings-playforward-does-not-animate-nor-detect/m-p/3213882#M138511</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-11-02T14:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: DriveConstraintSettings.PlayForward does not animate nor detect contact</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/driveconstraintsettings-playforward-does-not-animate-nor-detect/m-p/3214222#M138512</link>
      <description>&lt;P&gt;Refactored&amp;nbsp;it a bit nicer:&lt;/P&gt;&lt;PRE&gt;    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) &amp;lt; double.Epsilon) throw new InvalidOperationException("Startvalue == Endvalue");
            Inventor.AssemblyDocument assemblyDocument = assemblyConstraint.Parent.Document;
            Inventor.UnitsOfMeasure unitsOfMeasure = assemblyDocument.UnitsOfMeasure;
            assemblyDocument.ModelingSettings.InteractiveContactAnalysis = Inventor.InteractiveContactAnalysisEnum.kAllComponentsInteractiveContact;
            assemblyDocument.ModelingSettings.InteractiveContactSurfaces = Inventor.InteractiveContactSurfacesEnum.kAllSurfacesInteractiveContact;

            Inventor.UnitsTypeEnum dataBaseUnitEnum = GetDataBaseUnitEnum(assemblyConstraint);

            assemblyConstraint.DriveConstraintSettings.CollisionDetection = analyzeContact;

            string incrementExpressionString = InventorUtilities.GetExpressionString(unitsOfMeasure, 1, unitsTypeEnum, dataBaseUnitEnum);

            assemblyConstraint.DriveConstraintSettings.SetIncrement(Inventor.ConstraintIncrementTypeEnum.kIncrementAsAmountOfValue, incrementExpressionString);

            string fromExpressionString = InventorUtilities.GetExpressionString(unitsOfMeasure, fromPosition, unitsTypeEnum, dataBaseUnitEnum);

            string toExpressionString = InventorUtilities.GetExpressionString(unitsOfMeasure, toPosition, unitsTypeEnum, dataBaseUnitEnum);

            if (fromPosition &amp;gt; toPosition)
            {
                DriveConstraintInNegativeDirection(assemblyConstraint, fromExpressionString, toExpressionString);
            }
            else if (fromPosition &amp;lt; toPosition)
            {
                DriveConstraintInPositiveDirection(assemblyConstraint, fromExpressionString, toExpressionString);
            }
        }

        private static void DriveConstraintInNegativeDirection(AssemblyConstraint assemblyConstraint, string fromExpressionString, string toExpressionString)
        {
            assemblyConstraint.DriveConstraintSettings.StartValue = toExpressionString;
            assemblyConstraint.DriveConstraintSettings.EndValue = fromExpressionString;
            assemblyConstraint.DriveConstraintSettings.GoToEnd();
            assemblyConstraint.DriveConstraintSettings.PlayReverse();
        }

        private static void DriveConstraintInPositiveDirection(AssemblyConstraint assemblyConstraint, string fromExpressionString, string toExpressionString)
        {
            assemblyConstraint.DriveConstraintSettings.StartValue = fromExpressionString;
            assemblyConstraint.DriveConstraintSettings.EndValue = toExpressionString;
            assemblyConstraint.DriveConstraintSettings.GoToStart();
            assemblyConstraint.DriveConstraintSettings.PlayForward();
        }

        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;
        }
    }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2011 17:42:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/driveconstraintsettings-playforward-does-not-animate-nor-detect/m-p/3214222#M138512</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-11-02T17:42:18Z</dc:date>
    </item>
  </channel>
</rss>

