<?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 Creating constraints with code in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-constraints-with-code/m-p/5194793#M123209</link>
    <description>Hi&lt;BR /&gt;&lt;BR /&gt;I need to programmatically add an assembly to my assembly and constrain it. I de ally I need 2 flush constraints and a constraint to the centre of an edge curve I select. Let's say I select the edge curve first, then the edge face and finally, the large top face. Can it be achieved? Will I need to set up imates?&lt;BR /&gt;&lt;BR /&gt;Also, could it be done with multiple occurrences? I have made a routine that will add 9 parts in an array ( 1 in the centre and 4 each side.) I need them to be constrained&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Any ideas?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Niige</description>
    <pubDate>Mon, 04 Aug 2014 22:17:26 GMT</pubDate>
    <dc:creator>NachoShaw</dc:creator>
    <dc:date>2014-08-04T22:17:26Z</dc:date>
    <item>
      <title>Creating constraints with code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-constraints-with-code/m-p/5194793#M123209</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;I need to programmatically add an assembly to my assembly and constrain it. I de ally I need 2 flush constraints and a constraint to the centre of an edge curve I select. Let's say I select the edge curve first, then the edge face and finally, the large top face. Can it be achieved? Will I need to set up imates?&lt;BR /&gt;&lt;BR /&gt;Also, could it be done with multiple occurrences? I have made a routine that will add 9 parts in an array ( 1 in the centre and 4 each side.) I need them to be constrained&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Any ideas?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Niige</description>
      <pubDate>Mon, 04 Aug 2014 22:17:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-constraints-with-code/m-p/5194793#M123209</guid>
      <dc:creator>NachoShaw</dc:creator>
      <dc:date>2014-08-04T22:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating constraints with code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-constraints-with-code/m-p/5196063#M123210</link>
      <description>&lt;P&gt;If you have the entities selected (edge, face, etc...) on the occurrence then you need to create proxies of them and add the constraint.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have the objects face1 and face2 to are entities in occurrence1 and occurrence2 in assembly1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Dim face1Proxy As Object&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Dim face2Proxy As Object&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;occurrence1.CreateGeometryProxy(face1, face1Proxy)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;occurrence2.CreateGeometryProxy(face2, face2Proxy)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;assembly1.ComponentDefinition.Constraints.AddFlushConstraint(face1Proxy, face2Proxy, 0.0)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Aug 2014 14:23:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-constraints-with-code/m-p/5196063#M123210</guid>
      <dc:creator>rjay75</dc:creator>
      <dc:date>2014-08-05T14:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating constraints with code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-constraints-with-code/m-p/5197329#M123211</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is where i am so far..... I cant find any specific info on Proxies&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Sub PlaceParts()
    
    
    Dim oAsmCompDef As AssemblyComponentDefinition
    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
   
    ' Create a new matrix object.  It will be initialized to an identity matrix.
    Dim oMatrix As Matrix
    Set oMatrix = ThisApplication.TransientGeometry.CreateMatrix
    
    Dim GetPanel As ComponentOccurrence
    Set GetPanel = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, "Select Part to work on")
    
    Dim face1  As Face
    Set face1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick Edge")
    Dim face2  As Face
    Set face2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick Face")
    
    Dim PartCompDef As PartComponentDefinition
    Set PartCompDef = GetPanel.Definition
    
    Dim sPartPath As String
    sPartPath = "C:\Users\NigelShaw\Documents\Inventor\Projects\SHAW DEVELOPMENT\MyAssemby.iam"
    
    Dim oMateiMateDefinition1 As MateiMateDefinition
    Set oMateiMateDefinition1 = PartCompDef.iMateDefinitions.AddMateiMateDefinition(face1, 0, , , "ST_C_EDGE")

    ' Create a mate iMateDefinition on a work axis
    Dim oMateiMateDefinition2 As MateiMateDefinition
    Set oMateiMateDefinition2 = PartCompDef.iMateDefinitions.AddMateiMateDefinition(face2, 0, , , "ST_F_FACE")
    
    ' Place the first occurrence.
    Dim oOcc1 As ComponentOccurrence
    Set oOcc1 = oAsmCompDef.Occurrences.Add(sPartPath, oMatrix)

    Dim oOcc2 As ComponentOccurrence
    Set oOcc2 = GetPanel
    
    ' Look through the iMateDefinitions defined for the first occurrence
    ' and find the one named "iMate:1".  This loop demonstrates using the
    ' Count and Item properties of the iMateDefinitions object.
    Dim i As Long
    Dim oiMateDef1 As iMateDefinition
    For i = 1 To oOcc1.iMateDefinitions.Count
        If oOcc1.iMateDefinitions.Item(i).Name = "ST_C_EDGE" Then
        MsgBox "Cam Edge is present"
            Set oiMateDef1 = oOcc1.iMateDefinitions.Item(i)
            Exit For
        End If
    Next
    
    Dim j As Long
    Dim oiMateDef2 As iMateDefinition
    For j = 1 To GetPanel.iMateDefinitions.Count
        If GetPanel.iMateDefinitions.Item(j).Name = "ST_F_EDGE" Then
        MsgBox "Panel Edge is present"
            Set oiMateDef2 = GetPanel.iMateDefinitions.Item(j)
            Exit For
        End If
    Next
    

    ' Create an iMate result using the two definitions.
    Dim oiMateResult As iMateResult
    Set oiMateResult = PartCompDef.iMateResults.AddByTwoiMates(oiMateDef1, oiMateDef2)

    
    

End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Doesnt matter what i do, i error on this line-&lt;/P&gt;&lt;PRE&gt;Set oiMateResult = PartCompDef.iMateResults.AddByTwoiMates(oiMateDef1, oiMateDef2)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the Assembly i place called "MyAssembly.iam" has 2 Flush iMates called ST_C_Face &amp;amp; ST_C_Edge. i am creating 2 flush iMates on my part that i select and these are called ST_F_EDGE &amp;amp; ST_F_FACE. i can get the iMate names to check that they are there, i just cannot make the imate. Is this because 1 set of iMates are in a part and the other set are in an assembly? do i need to move the iMates in the placed assembly to a part within that assembly?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nigel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Aug 2014 23:46:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-constraints-with-code/m-p/5197329#M123211</guid>
      <dc:creator>NachoShaw</dc:creator>
      <dc:date>2014-08-05T23:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: Creating constraints with code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-constraints-with-code/m-p/5198323#M123212</link>
      <description>&lt;P&gt;You want to use the main assembly component definition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Set oiMateResult = oAsmCompDef.iMateResults.AddByTwoiMates(oiMateDef1, oiMateDef2)&lt;/P&gt;</description>
      <pubDate>Wed, 06 Aug 2014 14:06:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-constraints-with-code/m-p/5198323#M123212</guid>
      <dc:creator>rjay75</dc:creator>
      <dc:date>2014-08-06T14:06:20Z</dc:date>
    </item>
    <item>
      <title>Re: Creating constraints with code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-constraints-with-code/m-p/5198985#M123213</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;I had tried that already and it didn't work. I got it working by using the iMateToEntity instead which works 2 out of 3 lol. I can constraint to my edge and my face but I cannot contrain to a work plane... The work plane is in the assembly. I have tried setting my pick to work plane but that doesn't work either. Any suggestins?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks for your help&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Nige</description>
      <pubDate>Wed, 06 Aug 2014 17:23:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-constraints-with-code/m-p/5198985#M123213</guid>
      <dc:creator>NachoShaw</dc:creator>
      <dc:date>2014-08-06T17:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating constraints with code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/creating-constraints-with-code/m-p/5199193#M123214</link>
      <description>&lt;P&gt;Here's another method demonstrating proxies and constraints. If you can get&amp;nbsp;logically (or by user selection) get to an entity and know the occurrence it belongs to you can create the constraints between the pairs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Sub PlaceParts()    
    Dim oAsmCompDef As AssemblyComponentDefinition
    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
   
    ' Create a new matrix object.  It will be initialized to an identity matrix.
    Dim oMatrix As Matrix
    Set oMatrix = ThisApplication.TransientGeometry.CreateMatrix
    
    Dim GetPanel As ComponentOccurrence
    Set GetPanel = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, "Select Part to work on")
    
    'Selections from an assembly gets proxy objects
    Dim face1  As FaceProxy
    Set face1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick Edge")
    Dim face2  As FaceProxy
    Set face2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick Face")
	   
    Dim PartCompDef As PartComponentDefinition
    Set PartCompDef = GetPanel.Definition
    
    Dim sPartPath As String
    sPartPath = "C:\Users\NigelShaw\Documents\Inventor\Projects\SHAW DEVELOPMENT\MyAssemby.iam"

    ' Place the first occurrence.
    Dim oOcc1 As ComponentOccurrence
    Set oOcc1 = oAsmCompDef.Occurrences.Add(sPartPath, oMatrix)
	&lt;BR /&gt;    'Get Workplane Proxies if workplanes are named.
    Dim wp1 As WorkPlane
    Dim wp1Proxy As WorkPlaneProxy
    Set wp1 = oOcc1.ComponentDefinition.WorkPlanes("namedPlane1")
    oOcc1.CreateGeometryProxy(wp1, wp1Proxy)
&lt;BR /&gt;    Dim wp2 As WorkPlane
    Dim wp2Proxy As WorkPlaneProxy
    Set wp2 = oOcc1.ComponentDefinition.WorkPlanes("namedPlane2")
    oOcc1.CreateGeometryProxy(wp2, wp2Proxy)
	
    'Apply Constraints
    oAsmCompDef.ComponentDefinition.Constraints.AddMateConstraint(face1Proxy, wp1, 0.0)
    oAsmCompDef.ComponentDefinition.Constraints.AddMateConstraint(face2Proxy, wp2, 0.0)  
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Aug 2014 18:38:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/creating-constraints-with-code/m-p/5199193#M123214</guid>
      <dc:creator>rjay75</dc:creator>
      <dc:date>2014-08-06T18:38:36Z</dc:date>
    </item>
  </channel>
</rss>

