Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Hi,
i have all set up VB api in my pc along with i have marked vb reference in creo as well but when i try to run below code i am getting error;
'globale Variablen:
Dim asyncConnection As IpfcAsyncConnection
Dim cAC As CCpfcAsyncConnection
Dim hSession As IpfcBaseSession
Dim hCurMdl As IpfcModel
Function Connect2ProE() As Boolean
Set cAC = New CCpfcAsyncConnection
Set asyncConnection = cAC.Connect(Null, Null, Null, Null)
Set hSession = asyncConnection.session
Connect2ProE = True
End Function
Private Sub but_connect_proe_Click()
bProeConnect = Connect2ProE()
End Sub
your help really be appreciated. Thanks
You need assistance with your VB code throwing an error. Let's clarify a little my scope: I cover several Creo Toolkit offerings and VB is not part of that. i'm sorry.
Now given the screencapture, the error code does not look like a Creo error.
Do you have a mean to test your connexion to the Creo session? other than with this code?
Hey Remy,
thanks alot to jumping in.
what i feel is that creo is not able to connect with vb api..below is error i see
indeed connexion fails.
Did you search the knowledge base with IpfcAsyncConnection? A number of articles have been written ranging from changing PATH env var to settings in Visual Studio:
https://www.ptc.com/en/support/article/CS149910
https://www.ptc.com/en/support/article/CS341502
https://www.ptc.com/en/support/article/CS225432
https://www.ptc.com/en/support/article/CS337504
alternatively do you have benchmark VB application that connect to Creo?
Thanks...gonna look those article right away.
and for vb i am using Microsoft excel.
Hi
Long time before i worked on this area. Here is a code snippet which converts drw to pdf.
Sub Main() Dim asyncConnection As pfcls.IpfcAsyncConnection = Nothing 'conn Dim cAC As pfcls.CCpfcAsyncConnection Dim session As pfcls.IpfcBaseSession Dim tModel As pfcls.IpfcModel Try cAC = New pfcls.CCpfcAsyncConnection 'asynconn cAC = CreateObject("pfcls.pfcAsyncConnection") asyncConnection = cAC.Connect("", "", "", 5) session = asyncConnection.Session Dim descModel As pfcls.IpfcModelDescriptor Dim expdf As pfcls.IpfcPDFExportInstructions Dim pdfopt As pfcls.IpfcPDFOption Dim EpfcPDFOPT_LAUNCH_VIEWER As Boolean EpfcPDFOPT_LAUNCH_VIEWER = False descModel = (New pfcls.CCpfcModelDescriptor).Create(pfcls.EpfcModelType.EpfcMDL_DRAWING, "test.drw", Nothing) expdf = (New pfcls.CCpfcPDFExportInstructions).Create() pdfopt = (New pfcls.CCpfcPDFOption).Create() pdfopt.OptionValue = (New pfcls.CMpfcArgument).CreateBoolArgValue(EpfcPDFOPT_LAUNCH_VIEWER) expdf.FilePath = "c:\work\test.pdf" tModel = session.CurrentModel tModel.Export("c:\work\test.pdf", CType(expdf, pfcls.IpfcExportInstructions)) Catch ex As Exception MsgBox(ex.Message.ToString + Chr(13) + ex.StackTrace.ToString) Finally asyncConnection.Disconnect(2) End Try End Sub
any idea why this code showing red highlighted(not working)
While similar, VB is not VBA. Excel uses VBA. When translating VB examples into VBA, you will need to translate the code to work in VBA. Examples:
Dim model As IpfcModel
Dim solidMdl As IpfcSolid
Set model = session.CurrentModel
Set solidMdl = model
Thank for tour reply bro!!
my main concern right now is , i am not able to connect creo with vb abi. i have done pro_comm_msg.exe pvariable set, vb_register.bat also ran, ticked on vb referancing in excel. still not able to connect creo with vb api.
You may need to run vb_register.bat using right click>run as admin.
@Ketan_Lalcheta @NM_9425708 @HanSolo97 @RPN @lhoogeveen if you guys could resolve my issue?
At the end it is Toolkit, did you add PRO_COMM_MSG_EXE to the System variables and you run vb_api_register.bat?
No connection if path to pro_comm_msg is not specified.
yes bro that is done. i can also see vb reference in excel. but dont know why i am not able to connect. could you please help me further.
just to let you know nmsd.exe not running. how can i make that run. i try double clicking on that but didn't worked
@Ragnarok8979 could you please try the below ?
1) Start Creo Parametric with elevated previlages .Use Run as Administrator or start parameteric.exe from a command prompt window that is launched as 'Run as Admin'
2) Start MS Excel application also as "Run as Administrator"
3) Now try executing your VBA Excel script and see if the connection succeeds.
4) Also, try changing the line Set asyncConnection = cAC.Connect(Null, Null, Null, 50) 'this mean that try attempting to connect to Creo for 50 seconds.