Avoid Spiderwebs with Direct References in Scripts

Categories:

Flownex Friday Tech Tips!

It’s officially Spooky Season! In between episodes of Squid Game and re-watching Hubie Halloween I thought I could make things a little less scary by demonstrating how to get rid of the spiderwebs in our projects (AKA Data Transfer Links). We use these often with scripts, which can be very powerful, but as our networks get more complex we may want to avoid the clutter/attracting spiders.

Quick Script vs Full Script

If we’re not scared of a little C# we may decide to start with a full script. I, personally, like to use a quick script so that I can use the table inputs to define my script inputs and results.

1 quick script

Calling a Specific Component

We will identify the component we want to read/write to by the unique Identifier. This can be found in the input properties for the component. In this example we’ll use a pipe component. By default this would typically be “Pipe – 0” or “Pipe” followed by some other integer. This field is editable so you can change it, but it must remain unique to that specific component.

2 component identifier

We can either specify the identifier as a string explicitly in the script:

//Referencing component "Pipe - 0"
IPS.Core.Component Pipe = Project.GetComponent("Pipe - 0");

Or we can have this as an text-type input to the script so that we can change the reference more easily. In this example we have a text variable “ComponentIdentifier”:

3 quick script input table
//Referencing component which is defined by input "ComponentIdentifier"
IPS.Core.Component Pipe = Project.GetComponent(ComponentIdentifier.ToString());

Note that we are using the ToString function to convert our text variable to a string.

Reading from Component

Now that we have our Pipe component referenced in the script we can read any of the results into our script via their display identifier using the following syntax:

//Reading from flow component
IPS.Properties.Double T_1 = Pipe.GetPropertyFromFullDisplayName("{Flow Element Results,Generic}Total temperature
") as IPS.Properties.Double;
Pipe_Temp.Value = T_1;

Note that we must use a internal variable. in this case “T_1”, to read the temperature before we assign that to the value of our script result “Pipe_Temp”.

A quick trick to determine the display name is to right-click on the result you’re interested in and select “Copy display identifiers to clipboard”.

4 display identifier shortcut

Writing to Component

The process of modifying a component input with values from the script is very similar. We can use the above trick on our Inputs for the component to find the display identifier for the pipe diameter in this example.

//Write to component
IPS.Properties.Double diameter = Pipe.GetPropertyFromFullDisplayName("{Geometry,Inlet}Diameter") as IPS.Properties.Double;
diameter.Value = Pipe_Diameter;

Summary

Here is how we’ve set up the quick script, as you can see it is really not that scary:

5 quick script final

And the snippet of code from the quick script:

//Identify Component
IPS.Core.Component Pipe = Project.GetComponent(ComponentIdentifier.ToString()); 

//Read from component
IPS.Properties.Double T_1 = Pipe.GetPropertyFromFullDisplayName("{Flow Element Results,Generic}Total temperature") as IPS.Properties.Double;
Pipe_Temp.Value = T_1;

//Write to component
IPS.Properties.Double diameter = Pipe.GetPropertyFromFullDisplayName("{Geometry,Inlet}Diameter") as IPS.Properties.Double;
diameter.Value = Pipe_Diameter;

Happy Friday and Happy Coding!

Categories

Get Your Ansys Products & Support from the Engineers who Contribute to this Blog.

Technical Expertise to Enable your Additive Manufacturing Success.

PADT’s Pulse Newsletter

Keep up to date on what is going on at PADT by subscribing to our newsletter.


By submitting this form, you are consenting to receive marketing emails from: . You can revoke your consent to receive emails at any time by using the SafeUnsubscribe® link, found at the bottom of every email. Emails are serviced by Constant Contact

Share this post:

Upcoming Events

03/28/2024

2024 Arizona Space Summit

04/03/2024

Low Frequency Updates in Ansys 2024 R1 - Webinar

04/03/2024

Venture Madness Conference Reception + Expo

04/03/2024

Stratasys F3300: Game Changing Throughput - Webinar

04/08/2024

39th Space Symposium

04/09/2024

39th Space Symposium

04/10/2024

Discovery Updates in Ansys 2024 R1 - Webinar

04/10/2024

39th Space Symposium

04/11/2024

39th Space Symposium

04/22/2024

Experience Stratasys Truck Tour: Houston, TX

04/24/2024

Structures Updates in Ansys 2024 R1 (2)

04/24/2024

Experience Stratasys Truck Tour: Houston, TX

05/07/2024

Experience Stratasys Truck Tour: Albuquerque, NM

05/08/2024

Fluent Materials Processing Updates in Ansys 2024 R1 - Webinar

05/09/2024

Experience Stratasys Truck Tour: Los Alamos, NM

05/14/2024

Simulation World 2024

05/15/2024

Simulation World 2024

05/16/2024

Simulation World 2024

05/22/2024

Optics Updates in Ansys 2024 R1 - Webinar

06/12/2024

Connect Updates in Ansys 2024 R1 - Webinar

06/26/2024

Structures Updates in Ansys 2024 R1 (3) - Webinar

06/27/2024

E-Mobility and Clean Energy Summit

07/10/2024

Fluids Updates in Ansys 2024 R1 - Webinar

08/05/2024

2024 CEO Leadership Retreat

10/23/2024

PADT30 | Nerdtoberfest 2024

Search in PADT site

Contact Us

Most of our customers receive their support over the phone or via email. Customers who are close by can also set up a face-to-face appointment with one of our engineers.

For most locations, simply contact us: