Cancel
Showing results for 
Search instead for 
Did you mean: 

NX Remoting: Selection Recipes

Creator
Creator

Hi,

 

I have a script that works fine when executed using NX (e.g. as a Journal) but not during a remote session (see script and error below). Can anyone confirm this is a bug or give suggestions for a workaround?

 

Kind regards,

Tim

 

NX version: NX 1847 build 2400.

 

Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
 
 
Module Module1
    Dim theSession As Session
    Dim theUFSession As UFSession
 
    Sub Main(ByVal args() As String)
 
        theSession = Activator.GetObject(GetType(Session), "http://localhost:4567/NXOpenSession")
        theUFSession = Activator.GetObject(GetType(UFSession), "http://localhost:4567/UFSession")
 
        Dim workFemPart As NXOpen.CAE.FemPart = CType(theSession.Parts.BaseWork, NXOpen.CAE.FemPart)
 
        Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Create Stacked Selection Recipe Dialog")
 
        Dim caePart1 As NXOpen.CAE.CaePart = CType(workFemPart, NXOpen.CAE.CaePart)
        Dim selRecipeBuilder1 As NXOpen.CAE.SelRecipeBuilder
        selRecipeBuilder1 = caePart1.SelectionRecipes.CreateSelRecipeBuilder()
 
        Dim nullNXOpen_TaggedObject As NXOpen.TaggedObject = Nothing
        Dim selRecipeAttributeStrategy1 As NXOpen.CAE.SelRecipeAttributeStrategy = Nothing
        selRecipeAttributeStrategy1 = selRecipeBuilder1.AddAttributeStrategy(NXOpen.CAE.CaeSetGroupFilterType.GeomFace, NXOpen.CAE.SelRecipeBuilder.InputFilterType.EntireModel, nullNXOpen_TaggedObject)
 
        Dim nullNXOpen_Expression As NXOpen.Expression = Nothing
        Dim nullNXOpen_Unit As NXOpen.Unit = Nothing
 
        Dim lowvalueattributes1(0) As NXOpen.NXObject.AttributeInformation
       lowvalueattributes1(0).Type = NXOpen.NXObject.AttributeType.String
        lowvalueattributes1(0).Category = Nothing
        lowvalueattributes1(0).Title = "Load"
        lowvalueattributes1(0).TitleAlias = Nothing
        lowvalueattributes1(0).BooleanValue = False
        lowvalueattributes1(0).IntegerValue = 0
        lowvalueattributes1(0).RealValue = 0.0
        lowvalueattributes1(0).StringValue = "1000N"
        lowvalueattributes1(0).TimeValue = Nothing
        lowvalueattributes1(0).CompTimeValue.Day = 0
        lowvalueattributes1(0).CompTimeValue.Minute = 0
        lowvalueattributes1(0).ReferenceValue = Nothing
        lowvalueattributes1(0).Inherited = False
        lowvalueattributes1(0).IsOverride = False
        lowvalueattributes1(0).Locked = False
        lowvalueattributes1(0).OwnedBySystem = False
        lowvalueattributes1(0).Required = False
        lowvalueattributes1(0).Unset = False
        lowvalueattributes1(0).Array = False
        lowvalueattributes1(0).PdmBased = False
        lowvalueattributes1(0).NotSaved = False
        lowvalueattributes1(0).ArrayElementIndex = 0
        lowvalueattributes1(0).Unit = nullNXOpen_Unit
        lowvalueattributes1(0).Expression = nullNXOpen_Expression
 
        Dim highvalueattributes1(0) As NXOpen.NXObject.AttributeInformation
        highvalueattributes1(0).Type = NXOpen.NXObject.AttributeType.String
        highvalueattributes1(0).Category = Nothing
        highvalueattributes1(0).Title = "Load"
        highvalueattributes1(0).TitleAlias = Nothing
        highvalueattributes1(0).BooleanValue = False
        highvalueattributes1(0).IntegerValue = 0
        highvalueattributes1(0).RealValue = 0.0
        highvalueattributes1(0).StringValue = "1000N"
        highvalueattributes1(0).TimeValue = Nothing
        highvalueattributes1(0).CompTimeValue.Day = 0
        highvalueattributes1(0).CompTimeValue.Minute = 0
        highvalueattributes1(0).ReferenceValue = Nothing
        highvalueattributes1(0).Inherited = False
        highvalueattributes1(0).IsOverride = False
        highvalueattributes1(0).Locked = False
        highvalueattributes1(0).OwnedBySystem = False
        highvalueattributes1(0).Required = False
        highvalueattributes1(0).Unset = False
        highvalueattributes1(0).Array = False
        highvalueattributes1(0).PdmBased = False
        highvalueattributes1(0).NotSaved = False
        highvalueattributes1(0).ArrayElementIndex = 0
        highvalueattributes1(0).Unit = nullNXOpen_Unit
        highvalueattributes1(0).Expression = nullNXOpen_Expression
 
        selRecipeAttributeStrategy1.SetUserAttributes(False, "", False, 0, lowvalueattributes1, highvalueattributes1)
        selRecipeBuilder1.RecipeName = "SelectionRecipeLoad"
 
        Dim nXObject1 As NXOpen.NXObject = selRecipeBuilder1.Commit()
        Dim selectionRecipe1 As NXOpen.CAE.SelectionRecipe = CType(nXObject1, NXOpen.CAE.SelectionRecipe)
 
        selectionRecipe1.Display.Update()
        selRecipeBuilder1.Destroy()
 
    End Sub
End Module

Error string: "Object of type 'System.Type[]' cannot be converted to type 'System.Int32'."

 

Remote_SelectionRecipe_Error.png

5 REPLIES 5

Re: NX Remoting: Selection Recipes

Siemens Experimenter Siemens Experimenter
Siemens Experimenter

Is it a run time exception or the program is not getting compiled?

 

Also I dont see the remoting libraries in your code and I guess they are required for enabling remoting. See the example in ugopen/SampleNXOpenApplications/.NET/RemotingExample/Client

Re: NX Remoting: Selection Recipes

Creator
Creator

It's a run-time error. 

 

The remote session works fine. I believe the error has to do with the Structure (NXOpen.NXObject.AttributeInformation) which has an element called Type of type Enum (NXOpen.NXObject.AttributeType) which is maybe incorrectly converted to a System.Type before executing the SetUserAttributes function.

Re: NX Remoting: Selection Recipes

Valued Contributor
Valued Contributor

try converting it into array. Remoting doesnt support attribute collection. convert it into array of it. Or set it one by one instead.

highvalueattributes1.ToArray()

Faced same issue and got solved using this.

Re: NX Remoting: Selection Recipes

Creator
Creator

Hi Rahul,

 

Yes I'm also familiar with the array-conversion of NX collections (lost quite some time figuring that one out Smiley Happy) to for instance enable iteration but these variables are arrays (arrays of NXObject.AttributeInformation which in themselves are Structures). 

 

Regards,

Tim

Re: NX Remoting: Selection Recipes

Valued Contributor
Valued Contributor

Hi, Try Using this function to set attribute values.

 

 

private bool SetAtributeVal(string attrTitle, string AttRVal)
{
try
{
Part workPart = theSession.Parts.Work;
NXObject[] objects1 = new NXOpen.NXObject[1];
objects1[0] = workPart;
AttributePropertiesBuilder attributePropertiesBuilder1;
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objects1, NXOpen.AttributePropertiesBuilder.OperationType.None);
attributePropertiesBuilder1.SetAttributeObjects(objects1);
attributePropertiesBuilder1.Title = attrTitle;
attributePropertiesBuilder1.StringValue = AttRVal;
attributePropertiesBuilder1.Commit();
attributePropertiesBuilder1.Destroy();
Logger.WriteLog("Attribute set: " + attrTitle);
return true;
}
catch (Exception ex)
{
Logger.WriteLog("Unable to set attribute: " + attrTitle + " with val: " + AttRVal + " due to " + ex.Message);
return false;
}
}