Measure the distance between 2 co-ordinate systems

Measure the distance between 2 co-ordinate systems

Saikiran_arakeri
Enthusiast Enthusiast
525 Views
6 Replies
Message 1 of 7

Measure the distance between 2 co-ordinate systems

Saikiran_arakeri
Enthusiast
Enthusiast

I am trying to measure the distance between 2 co-ordinate systems, I want the output to be in terms if X,Y & Z distances. I want this so that I can create a new co-ordinate system there at the that point and then Constrain both these CS's.

 

@JelteDeJong @WCrihfield @A.Acheson 

0 Likes
Accepted solutions (2)
526 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Saikiran_arakeri.  What type of measurement do you need?  Is a simple, straight point to point distance OK?  If so, you can try something like this:

 

Dim oCM As CommandManager = ThisApplication.CommandManager
Dim UCS1 As UserCoordinateSystem = oCM.Pick(SelectionFilterEnum.kUserCoordinateSystemFilter, "Pick First UCS")
Dim UCS2 As UserCoordinateSystem = oCM.Pick(SelectionFilterEnum.kUserCoordinateSystemFilter, "Pick Second UCS")
Dim dDistance As Double = UCS1.Origin.Point.DistanceTo(UCS2.Origin.Point)

 

Are both UCS's in the context of the top level of the 'active' assembly?  Or is one (or both) defined within sub assembly type components?  If one (or both) are defined down within components, then you may need to get the proxy version of them that is in the context of the top level assembly, so that you will be able to measure between them.  You mentioned creating a new UCS 'at that point'.  At what point?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Here is another example which includes X, Y, & Z data, as you requested.

Dim oCM As CommandManager = ThisApplication.CommandManager
Dim UCS1 As UserCoordinateSystem = oCM.Pick(SelectionFilterEnum.kUserCoordinateSystemFilter, "Pick First UCS")
If UCS1 Is Nothing Then Exit Sub
Dim UCS2 As UserCoordinateSystem = oCM.Pick(SelectionFilterEnum.kUserCoordinateSystemFilter, "Pick Second UCS")
If UCS2 Is Nothing Then Exit Sub
Dim oOPt1 As Inventor.Point = UCS1.Origin.Point
Logger.Info("oOPt1.X = " & oOPt1.X & " oOPt1.Y = " & oOPt1.Y & " oOPt1.Z = " & oOPt1.Z)
Dim oOPt2 As Inventor.Point = UCS2.Origin.Point
Logger.Info("oOPt2.X = " & oOPt2.X & " oOPt2.Y = " & oOPt2.Y & " oOPt2.Z = " & oOPt2.Z)
Dim dMinDist As Double = oOPt1.DistanceTo(oOPt2)
Dim dXDiff As Double = (oOPt1.X - oOPt2.X)
Dim dYDiff As Double = (oOPt1.Y - oOPt2.Y)
Dim dZDiff As Double = (oOPt1.Z - oOPt2.Z)
MsgBox("Min. Distance = " & dMinDist _
& vbCrLf & "Positional Difference:" _
& vbCrLf & "X = " & dXDiff _
& vbCrLf & "Y = " & dYDiff _
& vbCrLf & "Z = " & dZDiff, vbInformation, "UCS to UCS Positional Difference")

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 7

Saikiran_arakeri
Enthusiast
Enthusiast

Thanks, that worked.

 

Just needed a little help here, 

I am trying to create a User Co-ordinate system in an assembly, I have used the code lines below

 

otg = Invapp.TransientGeometry;

Gwp1 = Assydocdef.WorkPoints.AddFixed(otg.CreatePoint());
Gwp2 = Assemnlydocdef.WorkPoints.AddFixed(otg.CreatePoint());
Gwp3 = Assemblydocdef.WorkPoints.AddFixed(otg.CreatePoint());

 

GCSdef = Assemblydocdef.UserCoordinateSystems.CreateDefinition();

 

GCSdef.SetByThreePoints(Gwp1, Gwp2, Gwp3);

 

GCS = Assydocdef.UserCoordinateSystems.Add(GCSdef);

 

I am getting an error in this line GCS = Assydocdef.UserCoordinateSystems.Add(GCSdef);

 

Can you please look into it?

0 Likes
Message 5 of 7

WCrihfield
Mentor
Mentor

Hi @Saikiran_arakeri.  In that code you just posted, I see that you are using two different variable names in multiple places for what seems to be an AssemblyComponentDefinition type object ("Assydocdef" & "Assemnlydocdef").  Are those both supposed to be representing the definition of the same assembly?  Why are you using two different variables?  If you are trying to create WorkPoints within two different assemblies, you will not be able to directly use all 3 WorkPoints directly to create one UCS in one of the assemblies.  All 3 WorkPoints will need to exist within the same 'context' (model origin 3D coordinate space).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 7

Saikiran_arakeri
Enthusiast
Enthusiast

Hey @WCrihfield I later realized doing that mistake 😅, anyways the problem is solved now. I am able to create a UCS using the matrix. Thank you so much for the reply.

0 Likes
Message 7 of 7

WCrihfield
Mentor
Mentor

OK. Good to hear.  I didn't even think of this earlier, but the documentation tells us that the UserCoordinateSystemDefinition.SetByThreePoints (and GetByThreePoints) methods will not work in assemblies.  What that documentation does not tell us is that those methods would not actually throw any errors themselves,  but later when you try to use a UCS definition that was defined that way in an assembly, the Add method with throw an error.  It works OK in parts though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes