Here are two more sections of VBA examples converted to C#. These functions are related to constraints and other demos for assemblies that did not fit in one of the other sections. This is the seventh post with converted Help examples.
Note: One of the VBA examples caused a serious error and I logged a Change Request for it. The converted code for this macro is in the C# project but the function name is not added to the combo box. See this post for more information about these projects.
This project has the following functions:
Download Inventor_Help_Examples_CSharp_Asmb_Gen_Constraints
FixAllOccurrences
CreateShrinkwrapSubstitute
AssociativeBodyCopy
InsertConstraint
MateConstraint
MateConstraintOfWorkPlanes
MateConstraintWithLimits
CreateiMateDefinitionSample
iMateResultCreationSample
Here is the InsertConstraint function
// Assembly Insert Constraint Add API Sample
//Description
//This sample demonstrates the creation of an
//assembly insert constraint.
//Before running the sample, you need to open an
//assembly that contains at least two parts.
// Select circular edges on the two parts that
//will be used for the constraint and run the
//sample code. (Set the priority of the Select
//command and use the Shift-Select to select
//multiple edges.)
public void InsertConstraint()
{
// Set a reference to the active assembly
AssemblyDocument oDoc =
(AssemblyDocument)
ThisApplication.ActiveDocument;
AssemblyComponentDefinition oAsmCompDef =
(AssemblyComponentDefinition)
oDoc.ComponentDefinition;
// Set a reference to the select set.
SelectSet oSelectSet = default(SelectSet);
oSelectSet =
ThisApplication.ActiveDocument.SelectSet;
// Validate the correct data is in the
//select set.
if (oSelectSet.Count != 2)
{
MessageBox.Show
("Select two circular edges for the insert.");
return;
}
// Get the two edges from the select set.
Edge oEdge1 = null;
Edge oEdge2 = null;
try
{
oEdge1 = (Edge)oSelectSet[1];
oEdge2 = (Edge)oSelectSet[2];
}
catch
{
MessageBox.Show
("Select two circular edges for the insert.");
return;
}
//Note: this code does not test to see if
//the edges are circular edges (they need to be)
// Create the insert constraint
//between the parts.
InsertConstraint oInsert =
default(InsertConstraint);
oInsert = oAsmCompDef.Constraints.
AddInsertConstraint
(oEdge1, oEdge2, true, 0);
}
-Wayne


Subscribe