I'm trying to find and edit a part variable with API.
I've created a part with one protrusion and edited it's variable table to give names to the needed vars.
The strange thing is that I don’t see these vars using the API. I only keep getting the 4 system vars of the part ("PhysicalProperties_Density", "PhysicalProperties_Accuracy", and two more without names).
I also see only these vars using Spy for Solid Edge under ActiveDocument -> Variables
For Each oVar As SolidEdgeFramework.variable In ObjApp.ActiveDocument.Variables Try If oVar.DisplayName.ToLower = "x" Then oVar.Value = 0.1234 Catch ex As Exception End Try Next
What I'm missing?
I was on the way to find the difference between the variable and dimension types when I saw your answer.
I have another question (more VB then SE):
I'm looking for a feature by it's edgebar name.
I'm doing this with a loop
For Each f In oFeatures If f.EdgebarName.ToLower = Fname Then …… Next
I believe there must be a better way to do this without the loop.
since the Features object is a collection of Features there is no easier method than to loop all elements and compare the name.
Solid Edge has no lookup function (which would do the same in internal code).
But you could write an extension like this:
Module PartExtensions <Extension()> Public Function LookupByEdgebarName(ByVal Features As SEPart.EdgebarFeatures, Name As String) As Object If Features Is Nothing Then Return Nothing For i As Integer = 1 To Features.Count Try If String.Equals(Features.Item(i).EdgebarName, Name, StringComparison.InvariantCultureIgnoreCase) Then Return Features.Item(i) End If Catch ex As Exception End Try Next Return Nothing End Function End Module
Then you can find the feature by:
Dim Feature As Object = Features.LookupByEdgebarName("abc")
This uses late binding and you have to import System.Runtime.CompilerServices.