<?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: in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/adding-contraints-with-vba/m-p/760388#M169454</link>
    <description>I figured it out &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  I had placed a chunk of code into a temporary module a few days ago, but hadn't looked at it.  It was the solution!  I think it may have come straight out of the help files - it has excellent comments.  The problem - I was referencing the parts, not the occurrences.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
Anyway, here is the code:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
Dim oAsmCompDef As AssemblyComponentDefinition&lt;BR /&gt;&lt;BR /&gt;
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
' Get references to the two occurrences to constrain.&lt;BR /&gt;&lt;BR /&gt;
' This arbitrarily gets the first and second occurrence.&lt;BR /&gt;&lt;BR /&gt;
Dim oOcc1 As ComponentOccurrence&lt;BR /&gt;&lt;BR /&gt;
Set oOcc1 = oAsmCompDef.Occurrences.Item(1)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
Dim oOcc2 As ComponentOccurrence&lt;BR /&gt;&lt;BR /&gt;
Set oOcc2 = oAsmCompDef.Occurrences.Item(2)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
' Get the XY plane from each occurrence.  This goes to the&lt;BR /&gt;&lt;BR /&gt;
' component definition of the part to get this information.&lt;BR /&gt;&lt;BR /&gt;
' This is the same as accessing the part document directly.&lt;BR /&gt;&lt;BR /&gt;
' The work plane obtained is in the context of the part,&lt;BR /&gt;&lt;BR /&gt;
' not the assembly.&lt;BR /&gt;&lt;BR /&gt;
Dim oPartPlane1 As WorkPlane&lt;BR /&gt;&lt;BR /&gt;
Set oPartPlane1 = oOcc1.Definition.WorkPlanes.Item(3)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
Dim oPartPlane2 As WorkPlane&lt;BR /&gt;&lt;BR /&gt;
Set oPartPlane2 = oOcc2.Definition.WorkPlanes.Item(3)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
' Because we need the work plane in the context of the assembly&lt;BR /&gt;&lt;BR /&gt;
' we need to create proxies for the work planes.  The proxies&lt;BR /&gt;&lt;BR /&gt;
' represent the work planes in the context of the assembly.&lt;BR /&gt;&lt;BR /&gt;
Dim oAsmPlane1 As WorkPlaneProxy&lt;BR /&gt;&lt;BR /&gt;
Call oOcc1.CreateGeometryProxy(oPartPlane1, oAsmPlane1)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
Dim oAsmPlane2 As WorkPlaneProxy&lt;BR /&gt;&lt;BR /&gt;
Call oOcc2.CreateGeometryProxy(oPartPlane2, oAsmPlane2)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
' Create the constraint using the work plane proxies.&lt;BR /&gt;&lt;BR /&gt;
Call oAsmCompDef.Constraints.AddMateConstraint(oAsmPlane1, oAsmPlane2, 0)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
--&lt;BR /&gt;&lt;BR /&gt;
Chris Gitzlaff&lt;BR /&gt;</description>
    <pubDate>Thu, 24 Jul 2003 08:35:08 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2003-07-24T08:35:08Z</dc:date>
    <item>
      <title>Adding contraints with VBA</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/adding-contraints-with-vba/m-p/760385#M169451</link>
      <description>I have an assembly that contains multiple parts.  I have been successful at adding parts with VBA code, but want to place constraints (mate and flush) on the parts I add.  I created work planes specifically for this task in each of the parts I want to constrain.  If I mate Work PlaneX in Part1 to Work PlaneZ in Part2, I will have exactly what I'm looking for.  Below is the VBA code I have been using to try this.  The code references specific Part Documents and Work Planes.  These are working properly (referencing the correct parts and documents).  The constraint call is the only thing not working.  Am I on the right track?&lt;BR /&gt;
&lt;BR /&gt;
TIA,&lt;BR /&gt;
&lt;BR /&gt;
Chris Gitzlaff&lt;BR /&gt;
&lt;BR /&gt;
Code:&lt;BR /&gt;
Dim oAsmCompDef As AssemblyComponentDefinition&lt;BR /&gt;
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition&lt;BR /&gt;
    &lt;BR /&gt;
Dim oPt1CompDef As PartComponentDefinition&lt;BR /&gt;
Dim oPt2CompDef As PartComponentDefinition&lt;BR /&gt;
Dim oMate As MateConstraint&lt;BR /&gt;
&lt;BR /&gt;
Dim oWPlane1 As WorkPlane&lt;BR /&gt;
Dim oWPlane2 As WorkPlane&lt;BR /&gt;
&lt;BR /&gt;
Set oPt1CompDef = ThisApplication.Documents.Item(3).ComponentDefinition&lt;BR /&gt;
Set oWPlane1 = oPt1CompDef.WorkPlanes.Item(9)&lt;BR /&gt;
&lt;BR /&gt;
Set oPt2CompDef = ThisApplication.Documents.Item(6).ComponentDefinition&lt;BR /&gt;
Set oWPlane2 = oPt2CompDef.WorkPlanes.Item(4)&lt;BR /&gt;
&lt;BR /&gt;
Set oMate = oAsmCompDef.Constraints.AddMateConstraint(oWPlane1, oWPlane2, 0, kInferredLine, kInferredLine)</description>
      <pubDate>Wed, 23 Jul 2003 08:56:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/adding-contraints-with-vba/m-p/760385#M169451</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-07-23T08:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Adding contraints with VBA</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/adding-contraints-with-vba/m-p/760386#M169452</link>
      <description>&lt;DIV&gt;&lt;FONT face="Arial" size="2"&gt;Chris,&lt;/FONT&gt;&lt;/DIV&gt;&lt;BR /&gt;
&lt;DIV&gt;&lt;FONT face="Arial" size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;
&lt;DIV&gt;&lt;FONT face="Arial" size="2"&gt;The last two arguments need to be &lt;FONT&gt;&lt;BR /&gt;
face="Times New Roman" size=3&amp;gt;kNoInference in this case since you are &lt;BR /&gt;
constraining planes. kInferredLine is valid only for cylindrical &amp;amp; conical &lt;BR /&gt;
surfaces. Please see the help file for valid combinations.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;BR /&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;
&lt;DIV&gt;&lt;FONT face="Arial" size="2"&gt;Sanjay-&lt;/FONT&gt;&lt;/DIV&gt;&lt;BR /&gt;
&lt;DIV&gt;&lt;FONT face="Arial" size="2"&gt;Inventor API&lt;/FONT&gt;&lt;/DIV&gt;&lt;BR /&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;
&lt;BLOCKQUOTE dir="ltr"&gt;&lt;BR /&gt;
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px"&amp;gt;&lt;BR /&gt;
  &lt;DIV&gt;"cgitzlaff" &amp;lt;&lt;A&gt;&lt;BR /&gt;
  href="mailto:cgitzlaff@majorskylights.com"&amp;gt;cgitzlaff@majorskylights.com&lt;/A&gt;&amp;gt; &lt;BR /&gt;
  wrote in message &lt;A&gt;&lt;BR /&gt;
  href="news:f17a24f.-1@WebX.maYIadrTaRb"&amp;gt;news:f17a24f.-1@WebX.maYIadrTaRb&lt;/A&gt;...&lt;/DIV&gt;I &lt;BR /&gt;
  have an assembly that contains multiple parts. I have been successful at &lt;BR /&gt;
  adding parts with VBA code, but want to place constraints (mate and flush) on &lt;BR /&gt;
  the parts I add. I created work planes specifically for this task in each of &lt;BR /&gt;
  the parts I want to constrain. If I mate Work PlaneX in Part1 to Work PlaneZ &lt;BR /&gt;
  in Part2, I will have exactly what I'm looking for. Below is the VBA code I &lt;BR /&gt;
  have been using to try this. The code references specific Part Documents and &lt;BR /&gt;
  Work Planes. These are working properly (referencing the correct parts and &lt;BR /&gt;
  documents). The constraint call is the only thing not working. Am I on the &lt;BR /&gt;
  right track? &lt;BR /&gt;
  &lt;P&gt;TIA, &lt;BR /&gt;
  &lt;/P&gt;&lt;P&gt;Chris Gitzlaff &lt;BR /&gt;
  &lt;/P&gt;&lt;P&gt;Code: &lt;BR /&gt;Dim oAsmCompDef As AssemblyComponentDefinition &lt;BR /&gt;Set &lt;BR /&gt;
  oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition &lt;BR /&gt;
  &lt;/P&gt;&lt;P&gt;Dim oPt1CompDef As PartComponentDefinition &lt;BR /&gt;Dim oPt2CompDef As &lt;BR /&gt;
  PartComponentDefinition &lt;BR /&gt;Dim oMate As MateConstraint &lt;BR /&gt;
  &lt;/P&gt;&lt;P&gt;Dim oWPlane1 As WorkPlane &lt;BR /&gt;Dim oWPlane2 As WorkPlane &lt;BR /&gt;
  &lt;/P&gt;&lt;P&gt;Set oPt1CompDef = ThisApplication.Documents.Item(3).ComponentDefinition &lt;BR /&gt;
  &lt;BR /&gt;Set oWPlane1 = oPt1CompDef.WorkPlanes.Item(9) &lt;BR /&gt;
  &lt;/P&gt;&lt;P&gt;Set oPt2CompDef = ThisApplication.Documents.Item(6).ComponentDefinition &lt;BR /&gt;
  &lt;BR /&gt;Set oWPlane2 = oPt2CompDef.WorkPlanes.Item(4) &lt;BR /&gt;
  &lt;/P&gt;&lt;P&gt;Set oMate = oAsmCompDef.Constraints.AddMateConstraint(oWPlane1, oWPlane2, &lt;BR /&gt;
  0, kInferredLine, kInferredLine)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 23 Jul 2003 15:00:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/adding-contraints-with-vba/m-p/760386#M169452</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-07-23T15:00:35Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/adding-contraints-with-vba/m-p/760387#M169453</link>
      <description>Thanks for the response, but it wasn't the solution.  I had tried the kNoInference options before (all combinations, really).  I have a feeling that I'm going about this the wrong way.  What I would really like to see is an example where two parts (any parts) are placed in a model, then constrained using VBA.  I suspect my problem is that I'm referencing parts, not occurrences, but I'm not sure.&lt;BR /&gt;&lt;BR /&gt;Thanks for your help,&lt;BR /&gt;&lt;BR /&gt;Chris G.&lt;BR /&gt;</description>
      <pubDate>Thu, 24 Jul 2003 06:16:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/adding-contraints-with-vba/m-p/760387#M169453</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-07-24T06:16:09Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/adding-contraints-with-vba/m-p/760388#M169454</link>
      <description>I figured it out &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  I had placed a chunk of code into a temporary module a few days ago, but hadn't looked at it.  It was the solution!  I think it may have come straight out of the help files - it has excellent comments.  The problem - I was referencing the parts, not the occurrences.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
Anyway, here is the code:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
Dim oAsmCompDef As AssemblyComponentDefinition&lt;BR /&gt;&lt;BR /&gt;
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
' Get references to the two occurrences to constrain.&lt;BR /&gt;&lt;BR /&gt;
' This arbitrarily gets the first and second occurrence.&lt;BR /&gt;&lt;BR /&gt;
Dim oOcc1 As ComponentOccurrence&lt;BR /&gt;&lt;BR /&gt;
Set oOcc1 = oAsmCompDef.Occurrences.Item(1)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
Dim oOcc2 As ComponentOccurrence&lt;BR /&gt;&lt;BR /&gt;
Set oOcc2 = oAsmCompDef.Occurrences.Item(2)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
' Get the XY plane from each occurrence.  This goes to the&lt;BR /&gt;&lt;BR /&gt;
' component definition of the part to get this information.&lt;BR /&gt;&lt;BR /&gt;
' This is the same as accessing the part document directly.&lt;BR /&gt;&lt;BR /&gt;
' The work plane obtained is in the context of the part,&lt;BR /&gt;&lt;BR /&gt;
' not the assembly.&lt;BR /&gt;&lt;BR /&gt;
Dim oPartPlane1 As WorkPlane&lt;BR /&gt;&lt;BR /&gt;
Set oPartPlane1 = oOcc1.Definition.WorkPlanes.Item(3)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
Dim oPartPlane2 As WorkPlane&lt;BR /&gt;&lt;BR /&gt;
Set oPartPlane2 = oOcc2.Definition.WorkPlanes.Item(3)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
' Because we need the work plane in the context of the assembly&lt;BR /&gt;&lt;BR /&gt;
' we need to create proxies for the work planes.  The proxies&lt;BR /&gt;&lt;BR /&gt;
' represent the work planes in the context of the assembly.&lt;BR /&gt;&lt;BR /&gt;
Dim oAsmPlane1 As WorkPlaneProxy&lt;BR /&gt;&lt;BR /&gt;
Call oOcc1.CreateGeometryProxy(oPartPlane1, oAsmPlane1)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
Dim oAsmPlane2 As WorkPlaneProxy&lt;BR /&gt;&lt;BR /&gt;
Call oOcc2.CreateGeometryProxy(oPartPlane2, oAsmPlane2)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
' Create the constraint using the work plane proxies.&lt;BR /&gt;&lt;BR /&gt;
Call oAsmCompDef.Constraints.AddMateConstraint(oAsmPlane1, oAsmPlane2, 0)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
--&lt;BR /&gt;&lt;BR /&gt;
Chris Gitzlaff&lt;BR /&gt;</description>
      <pubDate>Thu, 24 Jul 2003 08:35:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/adding-contraints-with-vba/m-p/760388#M169454</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-07-24T08:35:08Z</dc:date>
    </item>
  </channel>
</rss>

