Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

MotionBuilder Forum
Welcome to Autodesk’s MotionBuilder Forums. Share your knowledge, ask questions, and explore popular MotionBuilder topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Appending Existing Item/s in FBList via Python

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
ronel_dejesus
758 Views, 3 Replies

Appending Existing Item/s in FBList via Python

My mistake. I only solved my second problem from the previous post.

 

I'm trying to do a Python script where I want to append an Item from an FBList to another FBList. What I want to happen is, I don't want to prevent appending the same Item in the other FBList once it is already appended. I know how if/else condition works, I just don't know yet how to properly apply it in this case. Here's the sample BTW.

 

def addHeadCall(control, event):

   addOpt = optList.Items[optList.ItemIndex]

   headList.Items.append(addOpt)

   print addOpt, "has been added to Head"

 

I'm sorry,  I'm still completely new to Python especially for Motionbuilder. I can only apply a few of my knowledge for MEL scripting.

Again, thanks in advance for the help.

Labels (2)
3 REPLIES 3
Message 2 of 4

Solved it on my own. Thanks anyways

 

def addHeadCall(control, event):
    s = len(headScroll.Items)
    addOpt = optList.Items[optList.ItemIndex]
    p = (addOpt + " has been added to Head Index") 
    if  s == 0:
        headScroll.Items.append(addOpt)
        print p
    elif 0 < s < 5:
        e = 0 #count for existing item
        for item in headScroll.Items:
            if addOpt == item:
                e = e + 1
        if e == 0:
            headScroll.Items.append(addOpt)   
            print p

 

 But if there's an alternative way, please inform me. Thanks in advance

Message 3 of 4
vdebaie
in reply to: ronel_dejesus

would something like this work?

def addHeadCall(control, event):
    addOpt = optList.Items[optList.ItemIndex]
    if addOpt not in headScroll.Items:
        headScroll.Items.append(addOpt)
        print (addOpt + " has been added to Head Index")



Message 4 of 4
ronel_dejesus
in reply to: vdebaie

Woah! This is way lot simpler and shorter. Thanks, man. I didn't know there's a "not in".

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report