YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Connect to Model using AFSDK v2 Options · View
RJK Solutions
#1 Posted : Wednesday, November 19, 2008 10:54:10 AM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 409
Location: Cheshire, United Kingdom.
If AFSDK v1.3 connecting to a Model within a database was straightforward and simple but in AFSDK v2 OSI consider that previous approach (Models property of AFDatabase) to be obselete. Instead OSI encourages the use of "AFModel.FindModels" to search for models within an AF database.

For this example we will assume that we know the model exists so will reference it directly using the AFDatabase.Elements object and convert the element to a model (as we know it is a model).


Code:
Private Function ConnectToModel(ByVal WhichModel As String) As Boolean

        Dim ret As Boolean = False

        Try
            If (AfMod Is Nothing) Then AfMod = CType(AFDB.Elements(WhichModel), Modeling.AFModel)
            ret = Not (AfMod Is Nothing)
        Catch ex As Exception
            ret = False
        End Try

        Return ret

    End Function


Simple!
Now you have your model and can manipulate as you see fit.


OSIsoft PI System Specialists
PI consultancy on PI Systems, PISDK, AFSDK, OLEDB etc and PI custom developments. Well pretty much anything to do with PI!


Sponsor  
 
jen
#2 Posted : Thursday, December 04, 2008 2:43:39 AM
Rank: Member
Groups: Member

Joined: 9/30/2008
Posts: 14
Location: Hongkong
What if I haven't created a model yet, (since the functionality of creating a model in PI System Explorer cannot be access)?
Thanks!
RJK Solutions
#3 Posted : Wednesday, December 17, 2008 2:38:13 PM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 409
Location: Cheshire, United Kingdom.
Hi Jen,

You can create models within PI SystemExplorer:

-Create an AFDatabase.
-Within "Elements" right click on the root element and select "New Model".

You can also do this via AFSDK:

*Assumes you have an object AFDB defined as AFDatabase.

Code:

' Create an Element Template for the model.
Dim ModelTemplate As AFElementTemplate = AFDB.ElementTemplates.Add("JenModelTemplate")
ModelTemplate.InstanceType = GetType(AFModel)

' Create the model object, assign it the Element Template created above.
Dim TheModel As AFModel = CType(AFDB.Elements.Add("JenModel", ModelTemplate), AFModel)
TheModel.Description = "This is a model for Jen."

AFDB.ApplyChanges()



OSIsoft PI System Specialists
PI consultancy on PI Systems, PISDK, AFSDK, OLEDB etc and PI custom developments. Well pretty much anything to do with PI!


Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.