Get Shape Points

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
MehdiZangenehBar
Posts: 114
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Get Shape Points

Post by MehdiZangenehBar »

My main goal is to save all vector data and import it in another software (something like SVG). But, I'm little confused about the shape data. Please download following file: https://drive.google.com/file/d/1oBj75F ... drive_link
You can see there is one shape, but 3 sub shape. how I can split points on those 3 shapes?
https://drive.google.com/file/d/1Snuco_ ... drive_link
The thing that I need is 3 table of points based on what you can see in the image.
User avatar
synthsin75
Posts: 10264
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Get Shape Points

Post by synthsin75 »

You'll probably need to check which curves are in the shape. If that fails, you may need to check end points and adjacent points on the curve to build your tables.
User avatar
MehdiZangenehBar
Posts: 114
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Re: Get Shape Points

Post by MehdiZangenehBar »

synthsin75 wrote: Sat Aug 10, 2024 9:14 pm You'll probably need to check which curves are in the shape. If that fails, you may need to check end points and adjacent points on the curve to build your tables.
Thanks, I used adjacent method and it works:

Code: Select all

-- **************************************************
-- General information about this script
-- **************************************************

ScriptName = "MZ_Test_Script"
MZ_Test_Script = {}

function MZ_Test_Script:OnMouseDown(moho, mouseEvent)
end

function MZ_Test_Script:DoLayout(moho, layout)
	layout:AddChild(LM.GUI.Button('Get Points Table', MOHO.MSG_BASE))
end

function MZ_Test_Script:HandleMessage(moho, view, msg)
    MZ_Test_Script:GetPointsTable(moho)
end

-- **************************************************
-- Functions
-- **************************************************

function MZ_Test_Script:GetPointsTable(moho)
    local doc = moho.document
    local frame = moho.frame
	local layer = moho:LayerAsVector(doc:LayerByName('Foot'))
	local mesh = layer:Mesh()
	local shape = mesh:Shape(0)

    local points_table = {}
    local points_sub_table = {}
    table.insert(points_table,points_sub_table)
    for i = 0, shape:CountPoints() - 1 do
        if (i > 0) then
            if mesh:ArePointsAdjacent(shape:GetPoint(i),shape:GetPoint(i-1)) == false then
                points_sub_table = {}
                table.insert(points_table,points_sub_table)
            end
        end
        table.insert(points_sub_table,mesh:Point(shape:GetPoint(i)))
    end

    return points_table
end
It seems work correctly on the test file, but the only problem is, it will create 4 tables, which last one has only one point, do you know how we can fix that?
User avatar
synthsin75
Posts: 10264
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Get Shape Points

Post by synthsin75 »

That's why I mentioned endpoints. You're tables don't seem to be getting the points in the correct table.

Code: Select all

    for i,v in ipairs(points_table) do
		for d,k in ipairs(v) do
			print(i, "    ", d, "    ", tostring(k:IsEndpoint()))
			k.fSelected = k:IsEndpoint()
		end
	end
If you add this code, you can see how the endpoints are being put in the tables.
The first curve is correct, 24 points with no endpoints. But your second curve only shows 3 points with one endpoint, and it's other endpoint is ending up in the errant 4th table.
User avatar
MehdiZangenehBar
Posts: 114
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Re: Get Shape Points

Post by MehdiZangenehBar »

synthsin75 wrote: Sun Aug 11, 2024 2:55 pm That's why I mentioned endpoints. You're tables don't seem to be getting the points in the correct table.

Code: Select all

    for i,v in ipairs(points_table) do
		for d,k in ipairs(v) do
			print(i, "    ", d, "    ", tostring(k:IsEndpoint()))
			k.fSelected = k:IsEndpoint()
		end
	end
If you add this code, you can see how the endpoints are being put in the tables.
The first curve is correct, 24 points with no endpoints. But your second curve only shows 3 points with one endpoint, and it's other endpoint is ending up in the errant 4th table.
So, what the final code should be?
User avatar
MehdiZangenehBar
Posts: 114
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Re: Get Shape Points

Post by MehdiZangenehBar »

This file is imported from old Moho version 9.5 to 14, it seems it has so many internal problem, please someone approve this:
two points are in the same curve, but point:Curve(0) return different curve:
https://drive.google.com/file/d/17490I3 ... drive_link
Post Reply