Dear All,
I'm just learning to program Inventor, and I am a bit lost. Basically, I would like to do this:
(i.e., take two object Z axes and contraint them to be the same), but in C#. In particular, what puzzles me is that I cannot make
'Get the Z-axis work axis from the occurrent.
Dim oPartAxis As WorkAxis
Set oPartAxis = oPartOcc.Definition.WorkAxes.Item(3)
in C# because the Definition object has not a WorkAxes instance... I gues I need some casting done, but I do not know what... Any help woul dbe greatly appreciated!!!
best
gus.-
Solved! Go to Solution.
Solved by dagush. Go to Solution.
Solved by nagwani. Go to Solution.
Hi Gus
The sample C# console application demonstrates the assembling (mate constraint) of two parts using work axes.
Hope this helps
-Ishwar N
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Inventor; using System.Runtime.InteropServices; namespace InventorConsole { class Program { static void Main(string[] args) { // Get Inventor application Inventor.Application _app = null; _app = Marshal.GetActiveObject("Inventor.Application") as Inventor.Application ; // Get active assembly document Inventor.AssemblyDocument aDoc = null; aDoc= _app.ActiveDocument as AssemblyDocument; // Get Assembly Component Definition Inventor.AssemblyComponentDefinition aCompDef = null; aCompDef = aDoc.ComponentDefinition as AssemblyComponentDefinition; // Get the occurrence to assemble Inventor.ComponentOccurrence aOcc1 = null; aOcc1 = aCompDef.Occurrences[1]; // Get the occurrence to assemble Inventor.ComponentOccurrence aOcc2 = null; aOcc2 = aCompDef.Occurrences[2]; // Get the Defition from occurrence Inventor.PartComponentDefinition pPartDef1 = null; pPartDef1 = aOcc1.Definition as PartComponentDefinition; // Get the Defition from occurrence Inventor.PartComponentDefinition pPartDef2 = null; pPartDef2 = aOcc2.Definition as PartComponentDefinition; // Get the z workaxis of both parts Inventor.WorkAxis pPartAxis1 = pPartDef1.WorkAxes[3]; Inventor.WorkAxis pPartAxis2 = pPartDef2.WorkAxes[3]; // Convert to Axes to assembly geometry proxy object axisProxy1 = null; Inventor.WorkAxisProxy pWorkAxisProxy1=null; aOcc1.CreateGeometryProxy(pPartAxis1, out axisProxy1); pWorkAxisProxy1 = axisProxy1 as WorkAxisProxy; // Convert to Axes to assembly geometry proxy object axisProxy2 = null; Inventor.WorkAxisProxy pWorkAxisProxy2 = null; aOcc2.CreateGeometryProxy(pPartAxis2, out axisProxy2 ); pWorkAxisProxy2 = axisProxy2 as WorkAxisProxy; // Assemble parts aCompDef.Constraints.AddMateConstraint(pWorkAxisProxy1, pWorkAxisProxy2, 0.0); aDoc.Update(); } } }