How to declare functions in a custom global library in After Effects? - after-effects

Is it possible to save all my custom expressions inside an external .jsx file, so I can call them from inside my projects?
For example, let's say I have an expression I use a lot, that ties a puppet tool point to a null object's position. I know I can I transform that expression into a function that could take, say, two arguments, but can I save it into a custom library, so that I can easily re-use it inside the project?
Right now, I'm simply copying and pasting the same code from property to property, and I'm beginning to feel there is an alternative way to do this more efficiently.
Thanks in advance!

I tested this with success, put this on top of your expression:
$.evalFile("/Users/myname/ae/functions.txt");
Then you can access whatever functions you have in your functions.txt file.
See here for more details: https://forums.creativecow.net/readpost/227/29337
The problem with this method is that you still need to include the extra line for each expression.
Anyway here is my complete setup, just in case: my expression is:
$.evalFile("/Users/myname/ae/functions.txt");
var p1 = thisComp.layer("Null 1").transform.position;
var p2 = thisComp.layer("Null 4").transform.position;
var p = p2 - p1;
printPosition(p)
And my functions.txt file contains the following:
function printPosition (p){
return " " + parseInt(p[0]) + " : " + parseInt(p[1])
}

A bit old question but I found a similar ling's solution without external files.
Add a null layer for your function
Add a marker and write your function on comment
Call eval on your comp->layer->marker->comment
When you want call your function you only need one line:
eval(thisComp.layer("FunctionLayer").marker.key(1).comment);
test(1);

I don't think that is possible.
But you can accomplish a lot by saving the expression as a preset (by dragging the actual layer property to the Effects & Presets window.
Note than you can the apply a preset to several layers by selecting them and using the Animation->Apply Animation Preset function
Hope that helps a little.

Related

Is there a way to get scrollstate from Lazyrow

I have made a LazyRow that i now want to be able to get the scrollposition from. What i understand Scrollablerow has been deprecated. (correct me if im wrong) The thing is that i cant make a scrollablerow so i thought lets make a lazy one then. but i have no clue how to get scrollposition from the lazyrow. i know how to get index but not position if that eaven exists. here is what i have tried.
val scrollState = rememberScrollState()
LazyRow(scrollState = scrollstate){
}
For LazyScrollers, there are separate LazyStates.
I think there's just one, in fact, i.e. rememberLazyListState()
Pass that as the scroll state to the row and then you can access all kinds of info. For example, you could get the index of the first visible item, as well as its offset. There are direct properties for this stuff in the object returned by the above initialisation. You can also perform some more complex operations using the lazyListState.layoutInfo property that you get.
Also, ScrollableRow may be deprecated as a #Composable, but it is just refactored, a bit. Now, you can use the horozontalScroll() and verticalScroll() Modifiers, both of which accept a scrollState parameter, which expects the same object as the one you've created in the question.
Usually, you'd use LazyScrollers since they're not tough to implement and also are super-performant, but the general idea is that they are used with large datasets whereas non-lazy scrollers are okay for small sized lists and stuff. This is because the lazy ones cache only a small fraction of the entire list, making your UI peformant, which is not something regular scrollers do, and not a problem for small datasets.
They're like equivalents of RecyclerView from the View System

How does one bypass SyntaxError when parsing code?

I am using openpyxl to read an excel file that will have changing values over time. The following function will take string inputs from the excel sheets to make frames for Tkinter.
def make_new_frame(strng, frame_location, frame_name, frame_list):
if not(frame_name in frame_list):
frame_list.append(frame_name)
exec("global %s" %(frame_name)) in globals()
exec("%s = Frame(%s)"%(frame_name, frame_location))
.... etc.
The code itself is quite long but I think this is enough of a snapshot to address my problem.
Now this results in the following error while parsing:
SyntaxError: function 'make_new_frame' uses import * and bare exec, which are illegal because it is a nested function
Everything in the code I included parsed and executed just fine several times, but after I added a few more lines in later versions in this function, it keeps spitting out the above error before executing the code. The error references the third line in the function, (which, I repeat, has been cleared in the past).
I added "in globals()" as recommended in another SO post, so that solution is not working.
There is a solution online here that uses setattr, which I have no idea how to use to create a widget without eventually using exec.
I would really appreciate if someone could tell me how to bypass the error while parsing or provide an alternative means for a dynamically changing set of frame names.
Quick Note:
I am aware that setting a variable as global in python is generally warned against, but I am quite certain that it will serve useful for my code
Edit 1: I have no idea why this was downvoted. If I have done something incorrectly, please let me know what it is so I can avoid doing so in the future.
I think this is an X/Y problem. You are asking for help with solution Y instead of asking for help on problem X.
If your goal is to create an unknown number of Frame objects based on external data, you can store references to the frame in a list or dictionary without having to resort to using exec and dynamically created variable names.
exec is a perfectly fine function, but is one of those things that you should never use until you fully understand why you should never use it.
Here's how to solve your actual problem without using exec:
frames = {}
def make_new_frame(strng, frame_location, frame_name, frames):
if not(frame_name in frames):
frames[frame_name] = Frame(frame_location)
return frames[frame_name]
With that, you now have a dictionary (frames) that includes a reference for every new frame by name. If you had a frame named "foo", for example, you could configure and pack it like this:
frames["foo"].configure(background="red", ...)
frames["foo"].pack(...)
If preserving the order of the frames is important you can use an OrderedDict.

How to define a primitive device in Proteus?

I'm trying to make my own full adder and some other devices as a sub-circuit in "Proteus" and use them several times in a bigger circuit.
The problem is when you copy a sub-circuit you need to rename all of its inner parts, otherwise, the parts with a same name in two sub-circuits would be considered as one, therefore you'd get some errors.
So I'd like to know if there is a way to define a full adder of my own and use it like "74LS183" which is a primitive device, and by primitive I mean it has been defined in the library.
From answer posted here
It's in the Proteus Help file:
SCHEMATIC CAPTURE HELP (F1) -> MULTI-SHEET DESIGNS -> Hierarchical Designs
See the section "Module Components":
Any ordinary component can be made into a module by setting the Attach Hierarchy Module checkbox on the Edit Component dialogue form.
The component's value is taken to be the name for the associated circuit,
and the component's reference serves as the instance name.
after this you can use your new implementation of that component with your new name. for making it available at library see "External Modules" section of proteus help.
The problem with copying is solved in "Proteus 8".not completely but sort of.
I mean you can copy a subcircuit without a need to change it's inner parts, but you must change the subcircuit name and I mean the bigger name above the subcircuit not the little one below it.
so there is no need to define a primitive.

On FW/1 where is a good place to intercept actions with semicolons

I want to make sure that requests that look like:
index.cfm?action=main.data;a=1;b=2 does not crash. Right now it is trying to
This is a follow up to Is it possible to access the matrix parameters (name-value pair separated by semicolon) in ColdFusion?
On FW/1 where is a good place to intercept actions with semicolons?
Matrix params apply to the request uri, not the query string. They're not matrix params if they occur after the question mark, so the direct question you're asking doesn't really make sense, (in that you have an invalid/corrupt action variable, and thus whatever you're attempting may well be the wrong way to go about it - but without more details it's hard to suggest a better way).
The answer to the more general "how do I modify the action value before FW/1 picks it up?" is: before setupRequestDefaults is called, which means before onRequestStart is called, which means overriding the FW/1 version with your own one, something like...
function onRequestStart ( string targetPath )
{
var ActionVar = variables.framework.action;
if ( StructKeyExists(Url,ActionVar) ) Url[ActionVar] = fiddleWithAction(Url[ActionVar]);
if ( StructKeyExists(Form,ActionVar) ) Form[ActionVar] = fiddleWithAction(Form[ActionVar]);
super.onRequestStart( argumentcollection=arguments );
}
Where fiddleWithAction is a function to do whatever needs doing (in this instance, a ListFirst(string,';') would do it).
But again, this is very likely not the best way to achieve whatever it is you're trying to do.

Regex to change method call parameter

Regexs make me cry, so, I came here for help.
I'm looking for some tips on Find & Replace in Panic's Coda. I know the F&R
is pretty advance but I'm just looking for the best way to do this.
I'm trying to rewrite a 'template engine' (very basic) I have going on with a
webapp I'm coding in PHP (CodeIgniter).
Currently I'm calling my template like so:
$this->load->view('subviews/template/headerview');
$this->load->view('subviews/template/menuview');
$this->load->view('subviews/template/sidebar');
$this->load->view('The-View-I-Want-To-Load'); // This is the important line
$this->load->view('subviews/template/footerview');
However it's inefficient using five lines of code every time I want to
load up a different page, in every different controller. So I rewrote it like this:
$data['view'] = 'The-View-I-Want-To-Load';
$this->load->view('template',$data);
That way if I need to make any major changes to the design it can
easily be done from the template.php view file (which contains the header, menu, sidebar views etc. etc.).
However I use the previous 5-lines all over the place in many
different controllers and functions. So, my question is --- How can I
find and replace the old template engine (5 lines of code) for the new
one - substituting in the name of the view in the important, unique
line for the one in $data['view]?
Does that make any sense?! If not I'll try and rephrase! I mean, is there a way of doing this via a Regex or something? Or am I on completely the wrong lines here?
your regex will look something like this :
\$this->load->view\('subviews/template/headerview'\);\n\$this->load->view\('subviews/template/menuview'\);\n\$this->load->view\('subviews/template/sidebar'\);\n\$this->load->view\('([^']*)'\);\n\$this->load->view\('subviews/template/footerview'\);
and replace with
\$data['view'] = '$1';\n\$this->load->view('template',\$data);