I am in need of getting the closest possible location on a PRESELECTED planar face for this example. I am using DPartEents_UserSelectionPreNotify to capture the preselected object, then using DMouseEvents_MouseMoveNotify which gives me the X and Y Location in Pixels on the monitor. See Code Below. this gives me the appearance of having the location but is quite far away in model space. I Need it relative to the face that is preselected. I Know what one of the XYZ Values are from the face. i need to take that known value along with i am assuming the rotation of the model and
Public Function GetXYZFromModelViewXY(ByVal ModDoc As ModelDoc2, ByVal ModViewX As Double, ByVal ModViewY As Double, ByVal ReferenceFace As Face2, ByVal SetToFace As Boolean) As Double()
GetXYZFromModelViewXY = Nothing
Dim ModViewLocation() As Double = Nothing
Dim ModelViewPoint As MathPoint = Nothing
If IsNothing(ModDoc) = False And IsNothing(ReferenceFace) = False Then ModelViewPoint = iSwApp.IGetMathUtility.CreatePoint(New Double(2) {ModViewX, ModViewY, 0})
If IsNothing(ModDoc.IActiveView) = False And IsNothing(ModelViewPoint) = False Then
Dim ModelSpacePoint As MathPoint = ModelViewPoint.IMultiplyTransform(ModDoc.IActiveView.Transform.Inverse)
If IsNothing(ModelSpacePoint) = False Then
ReDim ModViewLocation(2)
For i = 0 To 2
ModViewLocation(i) = ModelSpacePoint.ArrayData(i)
Next
End If
ModelSpacePoint = Nothing
End If
ModelViewPoint = Nothing
Return ModViewLocation
End Function
this will return the location that i use to create a temporary body as a preview of what will happen if a user selects the face. The temporary body is not selectable so i do not have any issues with that.
This second image shows the issue as the preview is supposed to be flat to the face as the feature above it is. if i move the mouse to the right it completely disappears into the block. this is all relative to the rotation angle of the model.
i am assuming i need to take my x y and z values that i am recieving from this function and triangulate the distances so the value that would put it on the face is correct.
for example i am recieving in meters
x = 0.0374432120
Y = 0.0037049424
Z = -0.0212748091
in this case Y should equal 0.0
attached is also the model view orientation transformation matrix. i might not need to use it but i am assuming it is what determines my rotational angle.
Sorry if this is confusing. post any comments that could help or help me better understand how to use transforms.
SolidworksApi macros