Editing Constraints of parts in C#

Editing Constraints of parts in C#

Anonymous
Not applicable
617 Views
1 Reply
Message 1 of 2

Editing Constraints of parts in C#

Anonymous
Not applicable

I'm trying to build a c# program where I can test a simulation for a robot project
I have made angle constraints in inventor and now I want to be able to send numbers to specific joint.

With the code listed below I can get all the constraints from a selected part and get the name of the specific constraints.

 

I find it confusing that most of the documentation is in VB so this is what I have discovered on my own, perhaps this isn't at all the way to do it. So any help or suggestion, even an entirely differend approach is more than welcome.

 

kind regards, 

Maarten Witteveen

 

Inventor.SelectSet selSet=asmDoc.SelectSet;
try
{
Inventor.ComponentOccurrence compOcc;

//getting all objects from the selection in inventor

foreach (object obj in selSet)
{
compOcc = (Inventor.ComponentOccurrence)obj;

//loops through entire list of constraints
for (int i = 1; i < compOcc.Constraints.Count+1; i++)
{

if (compOcc.Constraints[i].Name == "Angle:4")
{
Console.WriteLine("got here");

//get current value of angle:4 and set to desired position
//update view
}
}
}
}

0 Likes
618 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

Okay using alot of VB scripts as examples I finaly managed to update the joints for my project with a scrollbar in C#

For all that might happen to come across this post and need the same thing, Look below.

 

public partial class Form1 : Form
{
Inventor.Application invApp;

public Form1()
{
InitializeComponent();
try
{
//connect to inventor
invApp = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
}
catch
{
try
{
//starten van inventor session
Type invType = Type.GetTypeFromProgID("Inventor.Application");
invApp = (Inventor.Application)System.Activator.CreateInstance(invType);
invApp.Visible = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
MessageBox.Show("openen van sessies mislukt...");
}

}
}

 

private void trackBar1_Scroll(object sender, EventArgs e)
{
textBox1.Text = trackBar1.Value.ToString();

if (invApp.Documents.Count == 0)
{
MessageBox.Show("Geen geopend document gevonden...");
}

if (invApp.ActiveDocumentType != Inventor.DocumentTypeEnum.kAssemblyDocumentObject)
{
MessageBox.Show("Geen groepen gevonden...");
}

Inventor.AssemblyDocument asmDoc = (Inventor.AssemblyDocument)invApp.ActiveDocument;

for (int i = 1; i < asmDoc.ComponentDefinition.Parameters.Count + 1; i++)
{
if (asmDoc.ComponentDefinition.Parameters[i].Name == "d54")
{
Console.WriteLine(asmDoc.ComponentDefinition.Parameters[i].Name);
double value = asmDoc.ComponentDefinition.Parameters[i].Value;
 Inventor.Parameter invParam = asmDoc.ComponentDefinition.Parameters[i];

 

//I am used to working with degrees, could also use the trackbar to do it in radians
invParam.Value = Math.PI * trackBar1.Value/180;
invApp.ActiveDocument.Update();
}
}
}
}

 

 

0 Likes