Page 1 of 1

calculating point or shape real position

Posted: Fri Jun 09, 2023 4:48 am
by Jasim
Hi :D
I am new to Moho scripting
I am trying to get the real or world position of a selected shape, I use layer position and see if the layer is flipped but my main problem is how to calculate the origin
if the origin is (0,0) then the results are fine else I get strange results sometimes outside the composition dimensions :lol:

Code: Select all

        flipH=moho.layer.fFlipH.value
        flipV=moho.layer.fFlipV.value
        LayerxPos=moho.layer.fTranslation.value.x
        LayeryPos=moho.layer.fTranslation.value.y
        
        Centerx = moho:Mesh():SelectedCenter().x
        Centery = moho:Mesh():SelectedCenter().y
        if flipH == true then
            Centerx =(Centerx-LayerxPos)*-1
            print ("flipped x")
        else
            Centerx =Centerx+LayerxPos   
        end
        if flipV == true then
            Centery =(Centery-LayeryPos)*-1
            print ("flipped y")
        else
            Centery =Centery+LayeryPos
        end

Re: calculating point or shape real position

Posted: Fri Jun 09, 2023 9:22 am
by hayasidist
take a look at the bakeVector() function in this: https://www.mediafire.com/file/ob4vvnin ... e.zip/file
that will help you understand some of the transforms that change the stored vector fPos (same applies to the SelectedCenter vector you're working with) to be the visual "on screen" vector position in a vector layer that hasn't been moved / rotated etc.

hope that helps

Re: calculating point or shape real position

Posted: Sat Jun 10, 2023 2:49 am
by Jasim
Thank You 😍😍😍
it took me a lot to understand 😂
You are a Genius!