![]() |
【转帖】ransform face coordinates to assembly9global0 coordinates
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 the face 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 contains the origin of my part and not on the selected plane. i think my error is, that i have not transformed the face coordinates to part coordinates. i don´t know how to get the transformation matrix for the face. any idea ? thanks in advance, matthias senff 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 i understood correclty... cheers, --stav. in this world i am nobody... and nobody is perfect ;) !!! --------- solidworks office 2008 sp4.0 dell precision pws390 nvidia quadro fx 3450/4000 sdi thanks stav, this helps me with my actual problem, but sooner or later i'll have to examine the relation of the faces, lines and points in my parts and i will not always have a selection point. one idea is to use the getcoordinatesystemtransformbyname(namein) from imodeldocextension, but i don't know if this works with the face and also how to get the correct name for the parameter. hi matthias, i wrote some code in the past that takes the x,y,z coordinates of a reference point on a part in an assembly, and it translates them to x,y,z with respect to the assembly. below find some of the code. as a pre-requisite i had that the user has to select the reference points (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) in this world i am nobody... and nobody is perfect ;) !!! --------- solidworks office 2008 sp4.0 dell precision pws390 nvidia quadro fx 3450/4000 sdi you may want to take a look at the getinitialdist function of the distance mate macro at answer thanks for the answers. matthias quick |
所有的时间均为北京时间。 现在的时间是 09:30 AM. |