Jump to content

If Statement in CHOPs


Recommended Posts

Hello CHOPS Masters,

Is there an if statement in CHOPs?

I have 2 export CHOPs and I want to only export if the user picks a file for the FileCHOP otherwise do nothing.

Currently, if a file is not specified the exportCHOP still overrides my object parameters that I'm exporting to with 0 values.

Thanks,

Rick

Link to comment
Share on other sites

First off, you should be using the export CHOP and NOT the export flag to do this.

The Export CHOP is exactly what you want. The left input takes your channel, the right input takes a binary channel to enable-disable the export mechanism. Simple.

Now to create the binary condition for the export chop, you simply need to put down a constant CHOP and for the first channel, use the following expression:

clamp(argc(chs("/obj/model/file1/file")),0,1)

argc() simply counts the number of arguements supplied. If the string is empty it returns zero and if there is something in there, return a one guaranteed with the clamp max of 1. You don't need the clamp in this case but you never know when an unsuspecting windows user will supply a name with a space or some other foul character. :P

I am sure there are other ways to test to see if the file has actual data or not but the expression above is one that doesn't care if the SOP has an error or not. You are just parsing a string in a parm field, that's all.

Link to comment
Share on other sites

Oh, I didn't answer your first question: Is there an if statement in CHOPs?

Yes there is but in an entirely different way than what you are looking for. In CHOPs you build up your logic using channels as conditions.

Many of the CHOPs that perform logic operations will have a separate input for the condition channel as the export CHOP example above or the very handy Logic CHOP which will take in any motion channel and convert it to a binary channel based on certain conditions and then you use the output channels in other chops like count CHOP, fan CHOP, etc. Other chops will take the first channel as the logic input like the blend CHOP. The blend CHOP will blend between any number of inputs but it is the first channel incremented by ones that determines which subsequent inputs to switch to.

I find that programming experience is actually a hinderance to building these visual nodes with logic. Same for VOPs. Great news for artists as they will have a much easier time of it learning to programme visually with these nodes. I really have to switch to a different part of my brain when I programme visually with nodes as opposed to writing code.

  • Like 1
Link to comment
Share on other sites

Hi Jeff,

Thanks for your reply. I tried your suggestion but am still not having luck with this.

Here's my CHOP Setup.

FileCHOP is wired into the left input of a ExportCHOP

The ExportCHOP Node param is "/obj/model", the path parm is "tx"

I now have a ConstantCHOP wired into the right input of the ExportCHOP.

The Channel is the default 0?

The Expression is:

clamp(argc(chs("../file1/file")),0,1)

Don't I still need to click on the export flag on the exportCHOP? I tried it both ways with no luck so I'm guessing my problems are upstream.

P.S. I do agree that I need to start thinking differently when working with CHOPs/VOPs.

My first thought was if(file) export!

Thanks,

Rick

Link to comment
Share on other sites

Alright, after some tinkering around I got the your tip working but the end result is not behaving ;)

The expression works as you said it would. If there's a file specified in the FileCHOP, the constantCHOP expression returns 1 otherwise it returns 0.

Perhaps i'm having a refresh problem because the ExportCHOP does not update.

If I save the scene with nothing in the Path of the FileCHOP, nothing gets exported as it should. Now if I reopen the scene and provide a .chan file for the FileCHOP still, nothing is exported unless I starting tinkering with the CHOPS nodes (click on display, export, etc), then it will finally do what I want.

Is there no way to force it to eval on change? In the long run, I will be wrapping all this up into an otl.

Thanks,

Rick

Link to comment
Share on other sites

Try using a Switch CHOP in between your File CHOP and Export CHOP. Put Jeff's expression into the Index parameter of the Switch CHOP instead. The problem is that you don't want the File CHOP to cook if there's no filename in it as that will cause errors (the red triangle stuff) to propagate down stream. To fix the update problems, I suggest just putting the appropriate opcook -F command in the callback script of your otl file parameter.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...