Adding Metadata to Solid Edge Objects Using the API
Textual information in the form of metadata can be added in Solid Edge in various ways:
- File Properties – can be added and accessed both manually and programmatically.
- Block Labels – Limited to the Draft environment and can be hidden if required.
- Property Tables – These are found on the Tools tab of the ribbon, Properties group, in the Part and Sheetmetal environments. Custom properties can be defined in a tabular format which can then be attached to geometrical objects like edges or faces. This information can also be queried, both interactively and using the API.
All of the above information is accessible to the end user by one means or the other though.
There are often scenarios in programming where information needs to be attached to geometrical entities in Solid Edge and retrieved without being exposed to the user. Attribute sets can be used for this as described in this article.
To attach an attribute set called “RouteDataSet” to an object, say a Line2d:
Dim seAttrSet As Object = NothingseAttrSet = seLine2d.AttributeSets.Add(“RouteDataSet”)
Note: Besides this, AttributeSets has the usual Remove and Item methods and the Count property.
Declare datasets and assign values to add to the attribute set:
Dim sData As String = String.Empty
Dim bData As Boolean = False
Dim iData As Integer = 0sData = “GTR001N4”
bData = True
iData = 155
Add each type of data to the set using the appropriate attribute type constant:
seAttrSet.Add(“RouteName“, SolidEdgeConstants.AttributeTypeConstants.seStringANSI)
seAttrSet.RouteName = sDataseAttrSet.Add(“IncludedInPaintCalculations“,SolidEdgeConstants.AttributeTypeConstants.seBoolean)
seAttrSet.IncludedInPaintCalculations = bData
seAttrSet.Add(“EstimatedLength“, SolidEdgeConstants.AttributeTypeConstants.seInteger)
seAttrSet.EstimatedLength = iData
Note how the first String argument which is the name of the attribute set automatically becomes a property on the next line when assigning it a value. This facilitates adding any number of named attributes to a set.
The other data types are:
Note: Besides this, the AttributeSet has the usual Remove and Item methods and the Count and SetName properties where the later returns the name of an attribute set.
To check the existence of an attribute set on an object, an additional method called IsAttributeSetPresent can be used:
If seLine2d.IsAttributeSetPresent(“RouteDataSet”) Then
seAttrSet = seLine2d.AttributeSets(“RouteDataSet”)seAttribute = seAttrSet(“RouteName”)
sData = seAttribute.Value()
seAttribute = seAttrSet(“IncludedInPaintCalculations”)
bData = seAttribute.Value()
seAttribute = seAttrSet(“EstimatedLength”)
iData = seAttribute.Value()
End If
Here’s a simple application to illustrate attribute sets:
And the source code is as below. Try this with a line selected on a drawing sheet:
Imports SolidEdgeFramework
Imports SolidEdgeFrameworkSupport
Public Class Form1
Dim seApp As SolidEdgeFramework.Application = Nothing
Dim seDoc As SolidEdgeDocument = Nothing
Dim seSel As SelectSet = Nothing
Dim seLine2d As Line2d = Nothing
Dim seAttrSet As Object = Nothing
Dim seAttribute As Object = Nothing
Dim sData As String = String.Empty
Dim bData As Boolean = False
Dim iData As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
seApp = Runtime.InteropServices.Marshal.GetActiveObject(“SolidEdge.Application”)
seDoc = seApp.ActiveDocument
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
seSel = seDoc.SelectSet
seLine2d = seSel.Item(1)
seAttrSet = seLine2d.AttributeSets.Add(“RouteDataSet”)
sData = “GTR001N4”
bData = True
iData = 155
seAttrSet.Add(“RouteName”, SolidEdgeConstants.AttributeTypeConstants.seStringANSI)
seAttrSet.RouteName = sData
seAttrSet.Add(“IncludedInPaintCalculations”, SolidEdgeConstants.AttributeTypeConstants.seBoolean)
seAttrSet.IncludedInPaintCalculations = bData
seAttrSet.Add(“EstimatedLength”, SolidEdgeConstants.AttributeTypeConstants.seInteger)
seAttrSet.EstimatedLength = iData
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
seSel = seDoc.SelectSet
seLine2d = seSel.Item(1)
If seLine2d.IsAttributeSetPresent(“RouteDataSet”) Then
seAttrSet = seLine2d.AttributeSets(“RouteDataSet”)
seAttribute = seAttrSet(“RouteName”)
sData = seAttribute.Value()
seAttribute = seAttrSet(“IncludedInPaintCalculations”)
bData = seAttribute.Value()
seAttribute = seAttrSet(“EstimatedLength”)
iData = seAttribute.Value()
MessageBox.Show(“String Data = ” & sData & vbCrLf &
“Boolean Data = ” & bData & vbCrLf &
“Numerical Data = ” & iData & vbCrLf
)
End If
End Sub
End Class
Most graphics objects support AttributeSets in the Part, Sheetmetal, Draft and Assembly environments. Some common examples are:
- Part: Sketch, Line2d, Circle2d, Arc2d, Profile, CoordinateSystem, RefPlane, etc.
- Assembly: All those from Part and additionally GroundRelation, Occurrence, Tube, Wire, AsmRefPlane, etc.
- Draft: DrawingView, Layer, Group, Sheet, etc.
Tip: Solid Edge Document objects themselves do not directly support attribute sets but there is an easy way to store attributes at the document level. Here are some suggestions. Use the 2D Model Sheet in Draft and the base coordinate systems in the 3D environments since these objects are guaranteed in the respective file types. Read an article on how to access the 2D Model Sheet using the API here.
Another important feature of the attributes scheme is querying which can be done at the document level. To assess how many objects have the “RouteDataSet” attribute set in a document:
Dim seRouteObjects As SolidEdgeFramework.QueryObjects =
seDocument.AttributeQuery.AttributeQuery.QueryByName(“RouteDataSet”, “RouteName”)
Then you can count the number of objects and access an item:
seRouteObjects.Count
seRouteObjects.Item
The Revision Notes app also uses attribute sets extensively, for example, to differentiate a revision note group from other groups.
Hope you find many uses for this hidden gem of the Solid Edge API in your apps as well.
~Tushar Suradkar
Comments