Transform face coordinates to assembly(global) coordinates

Hello,

I have an assembly with some parts.
I select a Face and try to get the Face normal and a point on theface in assembly coordinates.

Dim swSelMgr As ISelectionMgr = Nothing
Dim MathUtil As IMathUtility = Nothing
Dim myface As IFace2
Dim facecmp As IComponent2
Dim facefeat As IFeature = Nothing
Dim vecarr As Object = Nothing

Dim transface As IMathTransform = Nothing
Dim mathFaceNormalVec As IMathVector = Nothing
Dim Dfacenormalvec As Double()
Dim mathPntonface As IMathPoint = Nothing
Dim Dpntonface As Double()


swSelMgr = MyOwnClass.getRootModelDoc().SelectionManager
MathUtil = MyOwnClass.SWApplicationObj.GetMathUtility()
facefeat = myface.GetFeature()
facefeat.Select2(False, -1)
facecmp = swSelMgr.GetSelectedObjectsComponent3(1, -1)

Dfacenormalvec = myface.Normal
transface = facecmp.Transform2
mathFaceNormalVec = MathUtil.CreateVector(Dfacenormalvec)
mathFaceNormalVec = mathFaceNormalVec.MultiplyTransform(transface)
vecarr = mathFaceNormalVec.ArrayData
' Get any point on face
Dpntonface = myface.GetClosestPointOn(0.0, 0.0, 0.0)
mathPntonface = MathUtil.CreatePoint(Dpntonface)
mathPntonface = mathPntonface.MultiplyTransform(transface)
Dpntonface = mathPntonface.ArrayData


The point that I recieve lies on a parallel plane which containsthe origin of my part and not on the selected plane.
I think my error is, that I have not transformed the facecoordinates
to part coordinates. I don´t know how to get thetransformation matrix for the face. Any idea ?


Thanks in advance,

Matthias SenffSolidworksApi macros
Answers 5
SF
SF 2009-03-10 Best Answer
Matthias,

Do you want the assembly coordinates of your selection?
If so just use:

SelectionMgr::GetSelectionPoint2

Have a look at the examples there too if you need more assistance.

From the description of the function you get this:
"This method gets the selected point's coordinates, in model space,from the currently selected object." that is what you want if iunderstood correclty...

Cheers,

--Stav.
SF
SF 2009-03-11
Thanks Stav,

this helps me with my actual problem, but sooner or later I'll haveto examine the relation of the faces, lines and points in my partsand I will not always have a selection point. One idea is to usethe GetCoordinateSystemTransformByName(NameIn) fromIModelDocExtension, but I don't know if this works with the faceand also how to get the correct name for the parameter.

SF
SF 2009-03-11
Hi Matthias,

I wrote some code in the past that takes the X,Y,Z coordinates of areference point on a part in an assembly, and it translates them toX,Y,Z with respect to the assembly. Below find some of the code. Asa pre-requisite i had that the user has to select the referencepoints (so that things are clear for you)

Hope it helps,

--Stav.

Code:
Dim pFeat1 As SldWorks.Feature
Dim pFeat2 As SldWorks.Feature
Dim ent As SldWorks.Entity
Dim parComp1 As SldWorks.Component2
Dim parComp2 As SldWorks.Component2
Dim mTrans1 As SldWorks.MathTransform
Dim mTrans2 As SldWorks.MathTransform
Dim refPoint1 As SldWorks.RefPoint
Dim refPoint2 As SldWorks.RefPoint
Dim mPoint1 As SldWorks.MathPoint
Dim mPoint2 As SldWorks.MathPoint
Dim newMPoint1 SldWorks.As MathPoint
Dim newMPoint2 SldWorks.As MathPoint

Dim arrayData1 As Variant
Dim arrayData2 As Variant

pFeat1 = selMgr.GetSelectedObject6(1, 0)
ent = pFeat1
parComp1 = ent.GetComponent
mTrans1 = parComp1.Transform2
refPoint1 = pFeat1.GetSpecificFeature2()
mPoint1 = refPoint1.GetRefPoint
newMPoint1 = mPoint1.MultiplyTransform(mTrans1)
arrayData1 = newMPoint1.ArrayData
x1 = arrayData1(0)
y1 = arrayData1(1)
z1 = arrayData1(2)


pFeat2 = selMgr.GetSelectedObject6(2, 0)
ent = pFeat2
parComp2 = ent.GetComponent
mTrans2 = parComp2.Transform2
refPoint2 = pFeat2.GetSpecificFeature2()
mPoint2 = refPoint2.GetRefPoint
newMPoint2 = mPoint2.MultiplyTransform(mTrans2)
arrayData2 = newmPoint2.ArrayData
x2 = arrayData2(0)
y2 = arrayData2(1)
z2 = arrayData2(2)
JB
JB 2009-03-11
You may want to take a look at the GetInitialDist function ofthe distance mate macro athttp://www.eng-tips.com/viewthread.cfm?qid=202450.
SF
SF 2009-03-17
Thanks for the answers.

Matthias