calculating point or shape real position

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
Jasim
Posts: 3
Joined: Wed Jun 07, 2023 12:17 am

calculating point or shape real position

Post 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
User avatar
hayasidist
Posts: 3526
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: calculating point or shape real position

Post 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
Jasim
Posts: 3
Joined: Wed Jun 07, 2023 12:17 am

Re: calculating point or shape real position

Post by Jasim »

Thank You 😍😍😍
it took me a lot to understand 😂
You are a Genius!
Post Reply