Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Dim instructions As IpfcPDFExportInstructions
Dim CoCreoSession As IpfcBaseSession
Dim outPath As String
Try
Dim run As New pfcModelsExamples
asyncConnection = Casync.Connect(DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value)
CoCreoSession = asyncConnection.Session
Dim descModel As IpfcModelDescriptor
descModel = (New CCpfcModelDescriptor).Create(EpfcModelType.EpfcMDL_DRAWING, Nothing, Nothing)
descModel.Path = "C:\Documents and Settings\Administrator\My Documents\drw0001.drw.1"
'Dim LmodDoc As IpfcModel = CoCreoSession.GetModelFromDescr(descModel)
Dim LmodDoc As IpfcModel = retrieveModelFromStdDir(CoCreoSession, EpfcModelType.EpfcMDL_DRAWING, "C:\Documents and Settings\Administrator\My Documents\drw0001.drw.1")
If Not LmodDoc Is Nothing Then
LmodDoc.Display()
CoCreoSession.CurrentWindow.Activate()
End If
instructions = (New CCpfcPDFExportInstructions).Create()
outPath = "c:\work\" + LmodDoc.InstanceName.ToLower + ".pdf"
LmodDoc.Export(outPath, instructions)
If Not LmodDoc Is Nothing Then CoCreoSession.CurrentWindow.Close()
Catch ex As Exception
MsgBox(ex.Message & vbNewLine & ex.StackTrace)
End Try
End Sub
Public Function retrieveModelFromStdDir(ByVal session As IpfcBaseSession, _
ByVal type As EpfcModelType, _
ByVal stdPath As String) As IpfcModel
Dim descModel As IpfcModelDescriptor
Dim options As IpfcRetrieveModelOptions
Dim model As IpfcModel
Try
'======================================================================
'Model is retrieved using a model descriptor object.
'This method loads the model identified by model type and path from a
'standard directory location.
'======================================================================
options = (New CCpfcRetrieveModelOptions).Create
options.AskUserAboutReps = False
descModel = (New CCpfcModelDescriptor).Create(type, Nothing, Nothing)
descModel.Path = stdPath
model = session.RetrieveModelWithOpts(descModel, options)
retrieveModelFromStdDir = model
Catch ex As Exception
MsgBox(ex.Message.ToString + Chr(13) + ex.StackTrace.ToString)
Return Nothing
End Try
End Function