Create workpoint at the intersection of two axes C#

Create workpoint at the intersection of two axes C#

Anonymous
Not applicable
1,044 Views
7 Replies
Message 1 of 8

Create workpoint at the intersection of two axes C#

Anonymous
Not applicable

I am trying to create a workpoint at the intersecion of two Z axis of two hand picked frame generator members

here's my code so far

 

ComponentOccurrence co1 = (ComponentOccurrence)(invapp.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Pick first Part"));
ComponentOccurrence co2 = (ComponentOccurrence)(invapp.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Pick second Part"));

 

PartComponentDefinition cd1 = (PartComponentDefinition)co1.Definition;
PartComponentDefinition cd2 = (PartComponentDefinition)co2.Definition;

WorkAxis cd1Z = cd1.WorkAxes["Z Axis"]; ///vb and vba sample d1.WorkPlanes.item("3")

WorkAxis cd2Z = cd2.WorkAxes["Z Axis"];

 

AssemblyDocument thisDoc = (AssemblyDocument)invapp.ActiveDocument;

 

object tempAxis1 = null;
co1.CreateGeometryProxy(cd1.WorkAxes["Z Axis"], out tempAxis1);
//thisDoc.ComponentDefinition.AdjustProxyContext(tempAxis1);
WorkAxis x1 = tempAxis1 as WorkAxis;

object tempAxis2 = null;
co2.CreateGeometryProxy(cd2.WorkAxes["Z Axis"], out tempAxis2);
WorkAxis x2 = tempAxis2 as WorkAxis;

 

WorkPoint px = thisDoc.ComponentDefinition.WorkPoints.AddByTwoLines(x1.Line, x2.Line, true);

 

0 Likes
Accepted solutions (3)
1,045 Views
7 Replies
Replies (7)
Message 2 of 8

jjstr8
Collaborator
Collaborator

I'm not sure what version you're on, but the Inventor 2017 API documentation states that the WorkPoint.AddByTwoLines method is not supported within an assembly.  Check the API documentation for your version.

0 Likes
Message 3 of 8

HideoYamada
Advisor
Advisor

Hi,

 

Inventor 2020 doesn't support it in the assembly also.

 

WorkPoints.AddByTwoLines Method 

> This method is not currently supported when creating a work point within an assembly.

 

=====

Freeradical

 Hideo Yamada

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 4 of 8

Anonymous
Not applicable

any alternative methods??

cause the reason i need the point is to measure it to the start and the end plane of the frame generator part

0 Likes
Message 5 of 8

JhoelForshav
Mentor
Mentor
Accepted solution

What Inventor does when you use AddByTwoLines in assembly environment (from UI) is creating a point and constraining it to the two axes.

 

I'm not experienced with C# but i'm sure you'll be able to translate from this example code in iLogic

 

Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oAxes As WorkAxes = oDoc.ComponentDefinition.WorkAxes
Dim A1 = oAxes.Item("Z Axis") 'This should be first axis proxy instead
Dim A2 = oAxes.Item("X Axis") 'This should be second axis proxy instead
Dim oNewPoint As WorkPoint = oDoc.ComponentDefinition.WorkPoints.AddFixed(ThisApplication.TransientGeometry.CreatePoint())
oDoc.ComponentDefinition.Constraints.AddMateConstraint(oNewPoint, A1, 0)
oDoc.ComponentDefinition.Constraints.AddMateConstraint(oNewPoint, A2, 0)

 

Message 6 of 8

JhoelForshav
Mentor
Mentor
Accepted solution
ComponentOccurrence co1 = (ComponentOccurrence)(invapp.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Pick first Part"));
ComponentOccurrence co2 = (ComponentOccurrence)(invapp.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Pick second Part"));

 

PartComponentDefinition cd1 = (PartComponentDefinition)co1.Definition;
PartComponentDefinition cd2 = (PartComponentDefinition)co2.Definition;

WorkAxis cd1Z = cd1.WorkAxes["Z Axis"]; ///vb And vba sample d1.WorkPlanes.item("3")

WorkAxis cd2Z = cd2.WorkAxes["Z Axis"];

 

AssemblyDocument thisDoc = (AssemblyDocument)invapp.ActiveDocument;

 

Object tempAxis1 = null;
co1.CreateGeometryProxy(cd1.WorkAxes["Z Axis"], Out tempAxis1);
//thisDoc.ComponentDefinition.AdjustProxyContext(tempAxis1);
WorkAxis x1 = tempAxis1 As WorkAxis;

Object tempAxis2 = null;
co2.CreateGeometryProxy(cd2.WorkAxes["Z Axis"], Out tempAxis2);
WorkAxis x2 = tempAxis2 As WorkAxis;

 

WorkPoint px = thisDoc.ComponentDefinition.WorkPoints.AddFixed(invapp.TransientGeometry.CreatePoint());
thisDoc.ComponentDefinition.Constraints.AddMateConstraint(px, x1, 0);
thisDoc.ComponentDefinition.Constraints.AddMateConstraint(px, x2, 0);

I tried to do it in C#, maybe it'll work 🙂

Message 7 of 8

Anonymous
Not applicable
Accepted solution

i did rewrote it to this but thanks

and also the conversion to the proxy is unnecessary 

this will do

 

WorkPoint px = thisDoc.ComponentDefinition.WorkPoints.AddFixed(invapp.TransientGeometry.CreatePoint());

thisDoc.ComponentDefinition.Constraints.AddMateConstraint(px, tempAxis1, 0, InferredTypeEnum.kNoInference, InferredTypeEnum.kNoInference);
thisDoc.ComponentDefinition.Constraints.AddMateConstraint(px, tempAxis2, 0, InferredTypeEnum.kNoInference, InferredTypeEnum.kNoInference);

0 Likes
Message 8 of 8

JhoelForshav
Mentor
Mentor

You are right that assigning tempaxis1 to x1 is unnecessary since tempaxis1 already is the proxy object of the members z-axis 🙂

but it has to be a proxy.