Parenting Selected Surfaces by Script
Introduction
This knowledge base article will describe how to use FRED’s scripting language to move selected surfaces from one object tree node to another. The destination node is chosen from a dialog populated by valid nodes on the object tree, where valid nodes are defined to be all Custom Elements currently defined.
At the time of this article, FRED does not support multiple item copy/paste operations on the object tree. The original idea for this script was to be able to use FRED’s “Object Selection Mode” to choose surfaces directly in the 3D view and then re-parent them on the object tree using the script. This allows you to move multiple objects at a time, which can be convenient when working with large models (such as imported CAD) which have many nodes that need to be re-organized.
Download the FRED file: moveTocustomElementDialog.frd
How to use this Script
Consider the following geometry and object tree, consisting of two subassemblies, three custom elements and three surfaces.
Surfaces can be selected directly from FRED’s 3D view by activating the object selection mode (Menu > 3D View > Object Selection Mode, or F8) and selecting a region of the 3D view inside of which the desired surfaces are contained. Correspondingly, the selected surfaces are now highlighted on the object tree view.
Once the desired surfaces have been selected, we can run the embedded script. This script will open up a dialog containing all of the valid custom element nodes into which these surfaces can be moved.
The user will choose one of the custom element nodes and hit “OK” to proceed with re-parenting the highlighted surfaces.
NOTE: You must run the embedded script from the toolbar button so that you maintain the highlighted surfaces on the object tree. If you run the embedded script using the right click mouse option on the object tree, the surfaces will no longer be highlighted and the functionality will be lost.
How the Script Works
The pseudocode for the script works in the following way:
- Loop over the object tree to determine how many valid custom elements are on the object tree
- Re-dimension the array for the Drop List dialog box according to the count in (1)
- Loop over the object tree again to populate the array for the Drop List dialog box with the full names of the custom element nodes
- Define and call the dialog box
- Loop over the highlighted surfaces and re-parent them to the custom element chosen by the user from the dialog box
The key scripting functionality that is used in this script is:
ReDim – Used to re-dimension the dialog box drop list array using a variable
IsCustomElement – Checks to see if the node is a custom element
IsSurface – Checks to see if the node is a surface
Begin Dialog…End Dialog – Defines a user dialog
DropListBox – Creates a drop down list using an array of strings
IsEntitySelected – Checks to see if the node is highlighted on the object tree