Description Applies one or more keywords to one or more items of the same type (ex. entities, materials, coatings, etc.). The item is specified by an argument indicating the item type (ex. source, geometry, material, etc.) and the item node number. Specifying the item type is critical because of how FRED stores node numbers internally. For example, it is possible to have two items with node #5, one being a geometry element and one being a material definition. Specifying the item type is required to remove any ambiguity about which node #5 is being referenced.
Syntax kwRet = KeywordsApplyToItems( itemType, kws( ), items() )
Parameters kwRet (Long) Returned value indicating the number of keyword assignments made to items. For example, if the kws() array contains two keyword nodes and the items() array contains four items, the returned value would be 8 if the keyword assignments were successful.
itemType As String String indicating the type of item being queried. Options are:
kws() As Long Array of keyword node numbers for the keywords that will be assigned to the items. All valid keywords in this array will be assigned to all valid items in the items() array.
items() As Long Array of item node numbers for the items that are being assigned keywords. All valid items in this array are assigned all valid keywords in the kws() array.
Example The example below constructs a list of two keywords that will be assigned to a list of items, constructs a list of items that will be assigned the keywords (using a custom subroutine called BuildNodeList), and then performs the keyword assignment operation.
Sub Main
ClearOutputWindow()
'Keywords we want to assign Dim kws(1) As Long kws(0) = KeywordFind( "Black Paint" ) kws(1) = KeywordFind( "Mechanics Views" )
'Items we want to assign to Dim items() As Long, parentNode As Long parentNode = FindFullName( "Geometry.Secondary baffle" ) BuildNodeList( parentNode, items() )
'Perform the assignment operation Dim numAssignments As Long numAssignments = KeywordsApplyToItems( "ent", kws(), items() ) Print numAssignments & " keyword assignments were made to items."
End Sub
Sub BuildNodeList( ByVal in_startNode As Long, _ ByRef in_nodeList() As Long )
'Build a list of nodes descended from an entity by using 'name matching.
ReDim in_nodeList( GetEntityCount()-1 )
'Full name of the node whose descendents we want to find Dim startName As String startName = GetFullName( in_startNode )
Dim curEnt As Long, entCount As Long Dim curName As String entCount = 0 For curEnt = 4 To GetEntityCount()-1 curName = GetFullName( curEnt ) If InStr( curName, startName ) > 0 Then in_nodeList(entCount) = curEnt entCount += 1 End If Next
'Compress the node list ReDim Preserve in_nodeList( entCount-1 )
End Sub
See Also
|