PDA

View Full Version : Drawing Close Event - Not able to get it work



ssunkara
09-05-2011, 03:13 AM
Hello to All,

My objective is to run some SPPID commands during PID CLOSE event.

The following is the snippet of my code:


'SPPID Version 2009 SP2 HF11
'Visual Studio 2010
================================================== ==============================

Public Function DoValidateItem(ByRef DataSource As Llama.LMADataSource, ByRef Items As Llama._LMAItems, ByRef Context As LMForeignCalc.ENUM_LMAValidateContext) As Boolean Implements LMForeignCalc._ILMForeignCalc.DoValidateItem
Dim sFileName As String

On Error GoTo ErrHndl

Select Case Context
Case LMForeignCalc.ENUM_LMAValidateContext.LMAValidateO pen
sFileName = "drawing opened"
Case LMForeignCalc.ENUM_LMAValidateContext.LMAValidateC lose
sFileName = "drawing closed "
PID_GapNow()

Case LMForeignCalc.ENUM_LMAValidateContext.LMAValidateC reate
sFileName = "drawing created"
Case LMForeignCalc.ENUM_LMAValidateContext.LMAValidateD elete
sFileName = "drawing deleted "
Case LMForeignCalc.ENUM_LMAValidateContext.LMAValidateM odify
sFileName = "drawing modified"
End Select

DoValidateItem = True

Exit Function
ErrHndl:
MsgBox(Err.Description)
DoValidateItem = False

End Function

================================================== ============================

Private Sub PID_GapNow()

Dim objSPPIDApplication As SmartPlantPID.Application
objSPPIDApplication = GetObject(, "SmartPlantPID.Application")

If Not objSPPIDApplication Is Nothing Then
objSPPIDApplication.RunCommand(SmartPlantPID.Comma ndConstants.igcmdFitView)

End If

objSPPIDApplication = Nothing

'MsgBox("Hello")

End Sub

================================================== ============================

The above code is working only when a MsgBox is shown. I have used MsgBox("Hello"). If I do not use this MsgBox then the objSPPIDApplication.RunCommand(SmartPlantPID.Comma ndConstants.igcmdFitView) is not getting executed.

I don't want to show a dialogbox to the user.

Thanks in advance for any help.

tim
09-05-2011, 06:11 PM
I have tested your code with VB6.

When close event happens, Automation server may be busy and it's hard to manipulate SmartPlantPID.Application while closing drawing.
DoValidateItem shall be used to validate data, not to catch event for automation.

DimitryAT
09-27-2011, 12:22 AM
I have tested your code with VB6.

When close event happens, Automation server may be busy and it's hard to manipulate SmartPlantPID.Application while closing drawing.
DoValidateItem shall be used to validate data, not to catch event for automation.

As Igr docs said:
DoValidateItem
In V2009, The user can now create custom validation programs which will execute when certain drawing events occur: Open, Close, Create, Delete, Modify, and Print a drawing. These programs will reference ForeignCalc.dll and other automation dlls as needed. The user can filter on the following cases/events Open, Close, Create, Delete, Modify, and Print and add desired code for each case. A ProgID will need to be added for the Drawing ItemType in DataDictionary Manager to fire off the validation program.

welshishGraeme
05-16-2012, 03:20 AM
Hi ssunkara

I'm not using your DoValidateItem part of your code when I'm trying to gap an open drawing, but I am trying to use:


Private Sub PID_GapNow()

Dim objSPPIDApplication As SmartPlantPID.Application
objSPPIDApplication = GetObject(, "SmartPlantPID.Application")

If Not objSPPIDApplication Is Nothing Then
objSPPIDApplication.RunCommand(SmartPlantPID.Comma ndConstants.igcmdFitView)

End If

objSPPIDApplication = Nothing

'MsgBox("Hello")

End Sub

executed by PID_GapNow() in:


Private Sub Command1_Click()
Dim objPIDAutoApp As PIDAutomation.Application
Dim objPIDADrawing As PIDAutomation.Drawing
Dim objDrawing As LMDrawing
Dim objDrawings As LMDrawings
Dim objDataSource As LMADataSource


Set objDataSource = New LMADataSource

Set objDrawings = New LMDrawings
objDrawings.Collect objDataSource

Set objPIDAutoApp = CreateObject("PIDAutomation.Application")

For Each objDrawing In objDrawings
If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
Set objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(objDrawing.Attr ibutes("Name"))



If Not objPIDADrawing Is Nothing Then
MsgBox "Drawing " & objDrawing.Attributes("Name").Value & " is opened!"

'Begin AutoGap on active drawing
PID_GapNow
'Dim auto As New AutoGapAll.AutoGapAllCmd
'auto.GapAll PIDDataSource.PIDMgr.Application.RADApplication
'End AutoGap on active drawing

objPIDADrawing.CloseDrawing True
End If
End If

I'm getting an error message saying: Compile error: User-defined type not defined

at Dim objSPPIDApplication As SmartPlantPID.Application

is there a project reference I need to include or can you see some other problem - thanks a lot

welshishGraeme
05-16-2012, 03:55 AM
Hi DimitryAT, could answer this question?

DimitryAT
05-16-2012, 06:02 AM
You can add reference to \Program Files\SmartPlant\P&ID Workstation\Program\sppid.tlb if you need SmartPlantPID.Application object, but why do you want it?

welshishGraeme
05-16-2012, 06:11 AM
Hi again DimitryAT

all I'm trying to do is GapNow after each drawing has opened and before each is closed. I've tried AutoGAP but that doesn't seem to work for me.

Thanks DimitryAT for any help you can offer.

DimitryAT
05-16-2012, 06:25 AM
I think it is not necessary to have SmartPlantPID.Application object in order to run commands.
You already have drawing object, so after if you can invoke command like this:



If Not objPIDADrawing Is Nothing Then
MsgBox "Drawing " & objDrawing.Attributes("Name").Value & " is opened!"
objPIDADrawing.Application.Application.RunCommand (SmartPlantPID.CommandConstants.igcmdHelp)
...

welshishGraeme
05-16-2012, 06:50 AM
now I'm getting error code 424, object required at objPIDADrawing.Application.Application.RunCommand (smartplantpid.CommandConstants.igcmdHelp).

when I type this command in, after the second Application. there is no prompt for further input. Does this suggest I have a project reference missing?1809

DimitryAT
05-16-2012, 07:53 AM
If you spell command correct, then you don't need to have command reference.
Could you try to use command objPIDADrawing.Application.Application.RunCommand 27168 or objPIDAutoApp.Application.RunCommand 27168 ?



If Not objPIDADrawing Is Nothing Then
objPIDADrawing.Application.Application.RunCommand 27168
...

welshishGraeme
05-16-2012, 08:08 AM
Hi DimitryAT

objPIDADrawing.Application.Application.RunCommand 27168 works for me - thankyou very much

(i'm still trying to find my spelling mistake - time for some new glasses maybe)

B)

DimitryAT
05-16-2012, 09:48 AM
Hi welshishGraeme,

Maybe I am not correct about spelling, I'll try to explain...
Property Application of object objPIDADrawing.Application is declared by Igr as Object.
In such case we never see prompt for further input (because Object type doesn't have declared items).
To call some function or access some property of this object, we have 2 possibilities:
1) delcare object of type, which we need and assign our object to it.
2) directly call functions/acess properties on object
In case this object doesn't have such a function, we will get runtime error (object does not support this method or something similar).
Probably, your code does not run because of SmartPlantPID.CommandConstants.igcmdHelp ?

Btw, does this command (RunCommand 27168) do what you want - gap now?

welshishGraeme
05-16-2012, 10:28 PM
Hi DimitryAT

Thank you for your explanation.

objPIDADrawing.Application.Application.RunCommand 27168 does work and do exactly what I needed, thank you. :)

I'd really like to know where you found RunCommand 27168, there must be a lot of easy to access commands available based on this.

For instance, when issuing drawings, we have one user who has to open up each drawing, run gap now, then print a pdf then close.
I think I've seen some pdf methods (i believe one of them was to do with resolution), would it be quite simple to add something like RunCommand "Print PDF"?

DimitryAT
05-17-2012, 12:54 AM
Hi DimitryAT
I think I've seen some pdf methods (i believe one of them was to do with resolution), would it be quite simple to add something like RunCommand "Print PDF"?

I think it is more reliable to use some PDF-printer (like FreePDF) and use objPIDADrawing.PrintOut("printername")

welshishGraeme
05-17-2012, 01:10 AM
That is awsome DimitryAT.

Is there a way to implement "OUR" code in SmartPlant P&ID Drawing Manager. I need to make a dll and modify the code a bit (I'm guessing) - any clues would be appreciated, so I can run this app on a selection of drawings rather than all. Normally when creating a transmittal we would only want to issue some of the drawings not all of them.

Thanks for all your help DimitryAT

This has been a really good weeks work so far - this site rocks!