Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

How To Close Unattended Engineer from Code?

I'm launching Unattended Enginneer from a Process.Start() call with arguments to load a project and line item. I have a single process step in the process that generates an NX model, writes step output, and emails the file.

 

I'm using AfterProcessStepChange to send the email, and I'd like to close engineer after the email sends. I don't need to save, but I'd like to check the line item back in.  

 

    Private Sub RsEngineer_AfterProcessStepChange(ByVal sender As Object, ByVal e As RsAfterProcessStepChangeEventArgs) Handles g_RsEngineer.RsAfterProcessStepChange

        Try
            'Using ID instead of name because ID is stable, name WILL CHANGE before release
            'Check which process step user has stepped into
            'MsgBox("AfterProcessStepChange: Process Step " & e.ProcessStep.ProcessStepID)

            Select Case e.ProcessStep.ProcessStepID
                Case 3
                    SendEmail(Rootpart.Inputs(1).OutputEmailAddress, Rootpart.Model3D(1).OutputAttachFilesString)

            End Select

        Catch ex As Exception
        End Try
    End Sub
9 REPLIES

Betreff: How To Close Unattended Engineer from Code?

Hi ElChrisP,

 

what do you have in your XML File?

 

ChangeType="0 or Blank–Open, 1-Save, 2-Release, 3-Transmit, 4-Delete"

 

If you use ChangeType="0" in your input xml it should only open ... and when finished it should close automatically.

 

Best Regards

Christian

Betreff: How To Close Unattended Engineer from Code?

[ Edited ]

Thanks for the reply, Christian.

 

I'm not using an XML file at this point, I'm using the project database option.

 

        Dim rsProcess As New ProcessStartInfo
        rsProcess.FileName = g_docAccess.InstallFolder & "rsEngineer.exe"
        If InStr(profileName, "Azure") > 0 Then
            rsProcess.Arguments = "/PROFILE " & Profile & " /USERID " & userID & " /PASSWORD " & password & " /PROJECT " & Project & " /LINEITEM " & LineItem & " /PROCESS " & Process
        ElseIf InStr(profileName, "Local") > 0 Then
            rsProcess.Arguments = "/PROFILE " & Profile & " /PROJECT " & Project & " /LINEITEM " & LineItem & " /PROCESS " & Process
        Else
            rsProcess.Arguments = "/PROFILE " & Profile & " /PROJECT " & Project & " /LINEITEM " & LineItem & " /PROCESS " & Process
        End If

I'm not opposed to using the input XML option, but I couldn't find an obvious way to create the XML. What's the best way to construct the file with the necessary inputs?

 

Chris

Betreff: How To Close Unattended Engineer from Code?

Are you opening the NX component only and creating the step file or also modifying it?

 

In the first case you could also use the step214ug.cmd

Betreff: How To Close Unattended Engineer from Code?

The NX model is being assembled prior to step output, so I assume I need the full NX process step to build it.

 

I'm looking at the KB article on exporting XML programatically, is that the place to start to get a base XML file I could pass to UE?

Betreff: How To Close Unattended Engineer from Code?

If you send me a PM I can send you via mail the nugget for the UE.

 

It is not that difficult to do this. Otherwise we can have also a phonecall and we will get through this. I have done also some stuff regarding this so I can assist a bit.

Betreff: How To Close Unattended Engineer from Code?

Hi Chris,

 

I think this can be closed as solved Smiley Wink

 

BR

Christian

Solution
Solution
Accepted by topic author EIChrisP
‎07-05-2016 10:44 AM

Betreff: How To Close Unattended Engineer from Code?

With Christian's help I was able to create valid xml output for unattended engineer. The only approach I could get to work was creating a string and reading it into an XmlDocument to validate it.

 

    Public Function GenerateXmlOutput() As String
        Dim startLoadString As String
        Dim endLoadString As String
        Dim loadString As String
        Dim outputXmlDocument As XmlDocument = New XmlDocument
        Dim xmlInputFolder As String = g_DocAccess.MasterDocumentsFolder & "..\XML_Input\"

        ' start from the top
        startLoadString = "<?xml version='1.0' encoding='utf-8'?>" & vbcrlf &
                          "<Model Project_ID='" & Rootpart.ProjectID & "'" &
                            " LineItem_ID='0'" &
                            " Application='LindePOC'" &
                            " Units='M'" &
                            " UserName='" & Rootpart.UserID & "'" &
                            " CustomerName='" & Rootpart.CustomerName & "'" &
                            " ChangeType='1'" &
                            " SaveMode='2'>" & vbcrlf

        ' add closing tag
        endLoadString = "</Model>"

        ' append child
        startLoadString &= "<Part Process='BatchProcess'" &
                                " ID='0'" &
                                " Name='LindeApplication'" &
                                " PartFamily='LindeApplication'" &
                                " PartFamilyID='1'>" & vbcrlf

        ' prepend closing tag
        endLoadString = "</Part>" & vbcrlf & endLoadString

        '<Subpart ID="22" Name="Inputs" SpecID="2">
        startLoadString &= "<Subpart ID='22' Name='Inputs' SpecID='2'>" & vbcrlf
        endLoadString = "</Subpart>" & vbcrlf & endLoadString

        '<Part Name="Inputs: 1" ID="37" PartFamily="Inputs" PartFamilyID="3">
        startLoadString &= "<Part Name='Inputs: 1' ID='37' PartFamily='Inputs' PartFamilyID='3'>" & vbcrlf
        endLoadString = "</Part>" & vbcrlf & endLoadString

        ' series property
        startLoadString &= "<Property Name='Series'>" & Rootpart.Inputs(1).Series & "</Property>" & vbcrlf

        If Rootpart.Inputs(1).IsHPV Then
            startLoadString &= "<Subpart ID='85' Name='HPV' SpecID='11'>" & vbcrlf
            endLoadString = "</Subpart>" & vbcrlf & endLoadString

            startLoadString &= "<Part ID='97' Name='HPV: 1' PartFamily='UIHPV' PartFamilyID='13'>" & vbcrlf
            endLoadString = "</Part>" & vbcrlf & endLoadString

            startLoadString &= "<Property Name='HPV01'>" & Rootpart.Inputs(1).HPV(1).HPV01 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV02'>" & Rootpart.Inputs(1).HPV(1).HPV02 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV03'>" & Rootpart.Inputs(1).HPV(1).HPV03 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV04'>" & Rootpart.Inputs(1).HPV(1).HPV04 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV05'>" & Rootpart.Inputs(1).HPV(1).HPV05 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV06'>" & Rootpart.Inputs(1).HPV(1).HPV06 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV07'>" & Rootpart.Inputs(1).HPV(1).HPV07 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV08'>" & Rootpart.Inputs(1).HPV(1).HPV08 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV09'>" & Rootpart.Inputs(1).HPV(1).HPV09 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV10'>" & Rootpart.Inputs(1).HPV(1).HPV10 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV11'>" & Rootpart.Inputs(1).HPV(1).HPV11 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV12'>" & Rootpart.Inputs(1).HPV(1).HPV12 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV13'>" & Rootpart.Inputs(1).HPV(1).HPV13 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV14'>" & Rootpart.Inputs(1).HPV(1).HPV14 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV15'>" & Rootpart.Inputs(1).HPV(1).HPV15 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV16'>" & Rootpart.Inputs(1).HPV(1).HPV16 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV17'>" & Rootpart.Inputs(1).HPV(1).HPV17 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV18'>" & Rootpart.Inputs(1).HPV(1).HPV18 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV19'>" & Rootpart.Inputs(1).HPV(1).HPV19 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='HPV20'>" & Rootpart.Inputs(1).HPV(1).HPV20 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='OutputEmailAddress'>" & Rootpart.Inputs(1).HPV(1).OutputEmailAddress & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='IsHPV'>" & Rootpart.Inputs(1).HPV(1).IsHPV & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='IsOutputIGES'>" & Rootpart.Inputs(1).HPV(1).IsOutputIGES & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='IsOutputJT'>" & Rootpart.Inputs(1).HPV(1).IsOutputJT & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='IsOutputSTEP203'>" & Rootpart.Inputs(1).HPV(1).IsOutputSTEP203 & "</Property>" & vbcrlf
            startLoadString &= "<Property Name='IsOutputSTEP214'>" & Rootpart.Inputs(1).HPV(1).IsOutputSTEP214 & "</Property>" & vbcrlf

        End If
        ' put the halves together, easier to read when debugging
        loadString = startLoadString & endLoadString
        ' load the string into an xml document to validate
        outputXmlDocument.loadXml(loadString)
        ' save the output 
        Return outputXmlDocument.Save(xmlInputFolder & Rootpart.ProjectID & Rootpart.LineItem & RootPart.Inputs(1).ModelCode & ".xml")

        'Return
    End Function

Then I created a process to launch unattended engineer and wait for it to complete so that I can send an email.

    Public Sub SubmitToUE()

        Dim profile As String = "Linde_Local_8100"
        Dim outputFilename As String = GenerateXmlOutput()
        Dim xmlInFile As String = outputFilename & ".xml"

        Dim rsProcess As New System.Diagnostics.Process()
        rsProcess.StartInfo.FileName = g_docAccess.InstallFolder & "rsEngineer.exe"
        rsProcess.StartInfo.Arguments = " /U /PROFILE " & profile & " /XMLIN '" & xmlInFile
        'rsProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

        Try
            rsProcess.Start()
            rsProcess.WaitForExit()

            'MsgBox("Exiting UE Process")

            SendEmail(Rootpart.Inputs(1).OutputEmailAddress, Rootpart.Model3D(1).OutputAttachFilesString)

            'MsgBox("Email Sent")

        Catch ex As Exception
            MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

I looked for an event to trigger sending the email from UE, but couldn't find any that fire. It seems like there's still a better way to do this, and I'm open to suggestions, but this will work for the moment.

 

Chris

Betreff: How To Close Unattended Engineer from Code?

Hi Chris,

 

in regard of sending an email

Try following.

 

Create a property for example String   visible !!!!

 

In this string property create a code like this

 

If Me.Whatever <> “” Then
	Sendemail()
        Result = “Ok”
Else
        Result = “Not ok”
End If

Me.Whatever stands for a property you have and that has to be filled out.

 

If the property is visible (no UI needed) it will be calculated and it will perform the email Smiley Wink

 

Best Regards

Christian

Betreff: How To Close Unattended Engineer from Code?

[ Edited ]

That did the trick. Thanks Christian. I ended up writing one xml file to process the model, and a second to send the email to ensure the files were ready to send.