Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > PYTHON Development
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Find Lowest Position of Object

 Post Reply Post Reply
Author
Message
Motion4D View Drop Down
Member
Member
Avatar

Joined: 2013 Jan 15
Online Status: Offline
Posts: 59
Post Options Post Options   Quote Motion4D Quote  Post ReplyReply Direct Link To This Post Topic: Find Lowest Position of Object
    Posted: 2018 Aug 10 at 11:19am
I'm looking for a way to find the lowest position of an object, whether primitive or poly. I thought this would be easy, just get the bounding box and find get it's minimum position. It seems the python bounding box doesn't have this kind of function. I can use GetRad() but that doesn't technically find the lowest position either. I'm pretty sure Xpresso even has this ability but as far as python I'm kind of stumped:/


Edited by Motion4D - 2018 Aug 10 at 11:36am
Back to Top
MaximeA View Drop Down
Forum Moderator
Forum Moderator

Forum Moderator

Joined: 2018 Jan 04
Location: France - Nantes
Online Status: Online
Posts: 101
Post Options Post Options   Quote MaximeA Quote  Post ReplyReply Direct Link To This Post Posted: Yesterday at 3:07am
Hi Motion4D, there is no such function in the SDK.
Since the Bounding box is in local space in some situation, if you are looking for global space minus, it can give you a wrong result.
So the only reliable way to do it is by iterating over all points and get its global position.

Here a quick sample.
import c4d

def main():
    objs = doc.GetActiveObjects(0)
    for obj in objs:
        if not obj.CheckType(c4d.Opolygon):
            continue

        pts = obj.GetAllPoints()
        if not pts:
            continue

        mg = obj.GetMg()

        minPos = c4d.Vector(obj.GetPoint(0) * mg).y
        minId = None

        for i in xrange(obj.GetPointCount()):
            bufferMin = c4d.Vector(obj.GetPoint(i) * mg).y
            minPos = min(minPos, bufferMin)
            if minPos == bufferMin:
                minId = i

        print "{} : MinId = {} : MinPos = {}".format(obj.GetName(), minId, minPos)

    return True


if __name__=='__main__':
    main()

If you have any questions please, let me know :)
Cheers,
Maxime!
MAXON
SDK Specialist
Back to Top
Motion4D View Drop Down
Member
Member
Avatar

Joined: 2013 Jan 15
Online Status: Offline
Posts: 59
Post Options Post Options   Quote Motion4D Quote  Post ReplyReply Direct Link To This Post Posted: Yesterday at 11:16am
Hey MaximeA!

Thank you that detailed explanation and all of the helpful code! 

Worked perfectly for poly objects. Is it possible to find on Primitives as well? I'm assuming GetPoint() doesn't work for them?

At that point would you have to make a copy, convert to poly, find lowest point, delete copy?
Back to Top
Motion4D View Drop Down
Member
Member
Avatar

Joined: 2013 Jan 15
Online Status: Offline
Posts: 59
Post Options Post Options   Quote Motion4D Quote  Post ReplyReply Direct Link To This Post Posted: Yesterday at 12:34pm
So I found that the GetBBox() function in the Utils module will do it even for primitives. All you have to do is feed in a standard zero'd out matrix for the second argument. It gives you the Center position along with the Radius number needed to find the lowest position:) At least it's working so far.

Edited by Motion4D - Yesterday at 12:38pm
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.125 seconds.