Page 1 of 1

Points of Segment

Posted: Mon Aug 12, 2024 6:42 pm
by MehdiZangenehBar
We can get a segment of the shape using
M_Shape:GetEdge(edgeID, curveID, segID)
We can also get one of the points on the curve using:
M_Point:GetEndpointEdge(curveID, segID)
My question is how we can get second point?
In other word, any function to get two points that made a shape segment?

Re: Points of Segment

Posted: Mon Aug 12, 2024 11:10 pm
by KuzKuz
Each point on the curve has its own ID, which is different from the ID of a point in the mesh.
If you have an endpoint on the curve and the curve itself, and you need to get the neighboring point, you can check the point's ID on the curve using M_Curve:PointID(point).
If PointID == 0, then the neighboring point will have the ID PointID + 1. If PointID ~= 0, then the neighboring point will have the ID PointID - 1.

Re: Points of Segment

Posted: Tue Aug 13, 2024 9:39 am
by MehdiZangenehBar
KuzKuz wrote: Mon Aug 12, 2024 11:10 pm Each point on the curve has its own ID, which is different from the ID of a point in the mesh.
If you have an endpoint on the curve and the curve itself, and you need to get the neighboring point, you can check the point's ID on the curve using M_Curve:PointID(point).
If PointID == 0, then the neighboring point will have the ID PointID + 1. If PointID ~= 0, then the neighboring point will have the ID PointID - 1.
Thanks!
I'm little confused,
Is it possible for you to write it like a functions?

Re: Points of Segment

Posted: Tue Aug 13, 2024 10:31 am
by KuzKuz
Try taking a look at how my script MR Curve Tool works.
There's a lot of code related to points and curves.
If you can't figure it out, I will write the function you need.
https://mohoscripts.com/script/mr_curve_tool

Re: Points of Segment

Posted: Tue Aug 13, 2024 10:49 am
by MehdiZangenehBar
KuzKuz wrote: Tue Aug 13, 2024 10:31 am If you can't figure it out, I will write the function you need.
Yes! please do it!
it is very hard for me to read 4740 lines of code from someone else to undrstand which is which.

Re: Points of Segment

Posted: Tue Aug 13, 2024 11:03 am
by KuzKuz
Alright, I will write the code that returns the neighboring point on the curve. However, I recommend that you study other people's scripts.
You don't need to read 4740 lines of code to understand how curves and points work.
Use the search function to find methods related to curves and study how they are used.
That's how I learned.

Re: Points of Segment

Posted: Tue Aug 13, 2024 11:19 am
by MehdiZangenehBar
KuzKuz wrote: Tue Aug 13, 2024 11:03 am Alright, I will write the code that returns the neighboring point on the curve. However, I recommend that you study other people's scripts.
You don't need to read 4740 lines of code to understand how curves and points work.
Use the search function to find methods related to curves and study how they are used.
That's how I learned.
Thank you!
Yea, That is my method as well, but in this case I'm looking for a more spicific function that support's all conditions, not only cases you implemented in that code, so yes, I need help from you to write a fuction that covers all cases.
For example when point have more than one curve.

Re: Points of Segment

Posted: Tue Aug 13, 2024 11:49 am
by MehdiZangenehBar
Please take a look at my other topic to undrstand why I need that function: viewtopic.php?t=37310
The problem is when I iterate over Shape > Points, the point order goes in the wrong direction:
https://drive.google.com/file/d/1dJbbig ... sp=sharing
This script might help you to find it better:

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
-- **************************************************

MZ_Test_Script.counter = 0

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

    mesh:DeselectPoints()
    if MZ_Test_Script.counter < shape:CountPoints() then
        local point = mesh:Point(shape:GetPoint(MZ_Test_Script.counter))
        point.fSelected = true
        print(MZ_Test_Script.counter)
        if MZ_Test_Script.counter == 27 or MZ_Test_Script.counter == 31 then print('Point goes to the wrong direction.') end
        MZ_Test_Script.counter = MZ_Test_Script.counter + 1
    end
end

Re: Points of Segment

Posted: Tue Aug 13, 2024 12:22 pm
by KuzKuz
MehdiZangenehBar wrote: Tue Aug 13, 2024 11:19 am
KuzKuz wrote: Tue Aug 13, 2024 11:03 am Alright, I will write the code that returns the neighboring point on the curve. However, I recommend that you study other people's scripts.
You don't need to read 4740 lines of code to understand how curves and points work.
Use the search function to find methods related to curves and study how they are used.
That's how I learned.
Thank you!
Yea, That is my method as well, but in this case I'm looking for a more spicific function that support's all conditions, not only cases you implemented in that code, so yes, I need help from you to write a fuction that covers all cases.
For example when point have more than one curve.
Can you describe in detail what this function should do? What is the final result you want to achieve? As I understand it, simply accessing the neighboring point won't be enough for you? Please clarify what you mean by "covers all cases"?

Re: Points of Segment

Posted: Tue Aug 13, 2024 12:23 pm
by KuzKuz
MehdiZangenehBar wrote: Tue Aug 13, 2024 11:49 am Please take a look at my other topic to undrstand why I need that function: viewtopic.php?t=37310
The problem is when I iterate over Shape > Points, the point order goes in the wrong direction:
https://drive.google.com/file/d/1dJbbig ... sp=sharing
This script might help you to find it better:

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
-- **************************************************

MZ_Test_Script.counter = 0

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

    mesh:DeselectPoints()
    if MZ_Test_Script.counter < shape:CountPoints() then
        local point = mesh:Point(shape:GetPoint(MZ_Test_Script.counter))
        point.fSelected = true
        print(MZ_Test_Script.counter)
        if MZ_Test_Script.counter == 27 or MZ_Test_Script.counter == 31 then print('Point goes to the wrong direction.') end
        MZ_Test_Script.counter = MZ_Test_Script.counter + 1
    end
end
If you just need to change the direction in your code:

Code: Select all

MZ_Test_Script.counter = nil

function MZ_Test_Script:GetPointsTable(moho)
    local doc = moho.document
    local frame = moho.frame
	local layer = moho:LayerAsVector(moho.layer)
	local mesh = layer:Mesh()
	local shape = mesh:Shape(0)
	if MZ_Test_Script.counter == nil then
		 MZ_Test_Script.counter = shape:CountPoints()-1
	end

    mesh:DeselectPoints()
    if MZ_Test_Script.counter >= 0 then
        local point = mesh:Point(shape:GetPoint(MZ_Test_Script.counter))
        point.fSelected = true
        print(MZ_Test_Script.counter)
        if MZ_Test_Script.counter == 27 or MZ_Test_Script.counter == 31 then
			print('Point goes to the wrong direction.')
		end
        MZ_Test_Script.counter = MZ_Test_Script.counter - 1
    end
end

Re: Points of Segment

Posted: Tue Aug 13, 2024 3:32 pm
by MehdiZangenehBar
Sorry, you didn't get it at all!