how get coordinates AssemblyConstraint in Autodesk inventor API

how get coordinates AssemblyConstraint in Autodesk inventor API

kkk_rbhbkkk
Participant Participant
885 Views
8 Replies
Message 1 of 9

how get coordinates AssemblyConstraint in Autodesk inventor API

kkk_rbhbkkk
Participant
Participant

Greetings. I wanted to ask if there is any way to get the coordinates of the middle point of the constraint as in the figure?

09241ac8-6d02-4c96-80c7-1a5a7104aa59.jpg

0 Likes
886 Views
8 Replies
Replies (8)
Message 2 of 9

kacper.suchomski
Mentor
Mentor

Hi

You can simply measure the distance of the cylinder (axis) from any construction plane (assuming the plane and axis are parallel, of course).
Do you have something else in mind?

 


Kacper Suchomski

EESignature


YouTube - Inventor tutorials | LinkedIn | Instagram

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 3 of 9

kkk_rbhbkkk
Participant
Participant

Hi

I apologize. You must have misunderstood. I have an assembly that was not created by me. I need to find the coordinates of all the x,y,z points where the parts of this assembly were connected. Using the Autodesk Inventor API

0 Likes
Message 4 of 9

Andrii_Humeniuk
Advisor
Advisor

Hi @kkk_rbhbkkk . This is an example of how to get axis coordinates in MateConstraint:

Private Sub Main()
	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument	
	Dim oMT As MeasureTools = ThisApplication.MeasureTools
	Dim oUOfM As UnitsOfMeasure = oDoc.UnitsOfMeasure
	Dim oCstrs As AssemblyConstraints = oDoc.ComponentDefinition.Constraints
	For Each oCstr As AssemblyConstraint In oCstrs
		If oCstr.Type = ObjectTypeEnum.kMateConstraintObject Then
			Dim oAxis As WorkAxisProxy
			If oCstr.EntityOne.Type = ObjectTypeEnum.kWorkAxisProxyObject Then
				oAxis = oCstr.EntityOne
			Else If oCstr.EntityTwo.Type = ObjectTypeEnum.kWorkAxisProxyObject Then
				oAxis = oCstr.EntityTwo
			End If
			If oAxis IsNot Nothing Then		
				Dim dX, dY, dZ As Double
				dX = Abs(oUOfM.ConvertUnits(oAxis.Line.Evaluator.RangeBox.MinPoint.X, kCentimeterLengthUnits, oUOfM.LengthUnits))
				dY = Abs(oUOfM.ConvertUnits(oAxis.Line.Evaluator.RangeBox.MinPoint.Y, kCentimeterLengthUnits, oUOfM.LengthUnits))
				dZ = Abs(oUOfM.ConvertUnits(oAxis.Line.Evaluator.RangeBox.MinPoint.Z, kCentimeterLengthUnits, oUOfM.LengthUnits))
				MessageBox.Show("X - " & dX & vbLf & _
								"Y - " & dY & vbLf & _
								"Z - " & dZ & vbLf, oCstr.Name)
			End If
		End If
	Next
End Sub

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 5 of 9

kkk_rbhbkkk
Participant
Participant

Thank you. Is this method suitable for other types of constraints?

0 Likes
Message 6 of 9

Andrii_Humeniuk
Advisor
Advisor

This method is suitable for any cases, if it is adjusted. In this case it is set to look for a MateConstraint, and if it has at least one axis it measures relative to the center of the assembly as per your question and the screenshot.


If the answer was useful for you and solved your question, please mark it as "SOLUTION", it will be useful for other users. Thank you.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 7 of 9

kkk_rbhbkkk
Participant
Participant
Sorry. I probably misunderstood something, but when migrating to C#, I get errors. EntityOne has no Type property. And from the code we get coordinates abs, although relative to general coordinates the constraint can be in negative coordinates
0 Likes
Message 8 of 9

Andrii_Humeniuk
Advisor
Advisor

A simple way to solve this problem:

MeasureTools oMT = m_InvApp.MeasureTools;
UnitsOfMeasure oUOM = oAsmDoc.UnitsOfMeasure;
AssemblyConstraints oCstrs = oAsmDoc.ComponentDefinition.Constraints;
foreach (AssemblyConstraint oCstr in oCstrs)
{                
    if (oCstr.Type == ObjectTypeEnum.kMateConstraintObject)
    {
        WorkAxisProxy oAxis = null;
        try
        {
            oAxis = oCstr.EntityOne as WorkAxisProxy;
        }
        catch (Exception)
        {
            try
            {
                oAxis = oCstr.EntityTwo as WorkAxisProxy;
            }
            catch (Exception) { }
        }
        if (oAxis != null)
        {
            double dX, dY, dZ;
            dX = oUOM.ConvertUnits(oAxis.Line.Evaluator.RangeBox.MinPoint.X, UnitsTypeEnum.kCentimeterLengthUnits, oUOM.LengthUnits);
            dY = oUOM.ConvertUnits(oAxis.Line.Evaluator.RangeBox.MinPoint.Y, UnitsTypeEnum.kCentimeterLengthUnits, oUOM.LengthUnits);
            dZ = oUOM.ConvertUnits(oAxis.Line.Evaluator.RangeBox.MinPoint.Z, UnitsTypeEnum.kCentimeterLengthUnits, oUOM.LengthUnits);
            MessageBox.Show("X: " + dX + "\nY: " + dY + "\nZ: " + dZ, oCstr.Name);
        }
    }
}

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 9 of 9

kkk_rbhbkkk
Participant
Participant

Hello, this method is not correct because oAxis = oCstr.EntityOne as WorkAxisProxy Is always an object of the kFaceProxyObject class. And when I try to transfer them to WorkAxisProxy I get an error 

kkk_rbhbkkk_0-1686310810740.png

 

0 Likes