Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Constarining Axis in C#?

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
dagush
700 Views, 2 Replies

Constarining Axis in C#?

Dear All,

 

  I'm just learning to program Inventor, and I am a bit lost. Basically, I would like to do this:

 

http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/How-to-programmatically-constrain-two-...

 

 (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.-

 

2 REPLIES 2
Message 2 of 3
nagwani
in reply to: dagush

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();  
        }
    }
}

 

Message 3 of 3
dagush
in reply to: nagwani

Dear Ishwar,

 

  It worked!!!!

  THANKS A LOT!!!

 

  all the best

 

gus.-

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report