Reply

Cannot find the user variables

Hi,

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?

 

Zohar

4 REPLIES

Re: Cannot find the user variables

Download the Sample for Solid Edge on GitHub by clicking the Download ZIP button. Search for the Part\SheetMetal ReportVariables sample.

 

Ultimately, the bit of code you're looking for will be in Common\VariablesHelper.vb.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: Cannot find the user variables

Hi Zohar, 

look in this thread Reading Variables from a part. I think you find some hints in my answer.

 

BR

regards

JB
VS2015, SE ST10

Re: Cannot find the user variables

Thanks,

I was on the way to find the difference between the variable and dimension types when I saw your answer. Smiley Happy

 

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.

Zohar

 

Re: Cannot find the user variables

Hello Zohar,

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.

 

BR Jürgen

regards

JB
VS2015, SE ST10