cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

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

VB API not able to connect -- some error-- help

Ragnarok8979
6-Contributor

VB API not able to connect -- some error-- help

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

 

 

Ragnarok8979_0-1626268955781.pngRagnarok8979_1-1626268982456.png

your help really be appreciated. Thanks

 

14 REPLIES 14

@remy ..you input on this please

remy
21-Topaz I
(To:Ragnarok8979)

Hi @Ragnarok8979 

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?

Ragnarok8979
6-Contributor
(To:remy)

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

 

Ragnarok8979_0-1626331917024.pngRagnarok8979_1-1626331943675.png

 

remy
21-Topaz I
(To:Ragnarok8979)

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? 

 

 

Ragnarok8979
6-Contributor
(To:remy)

Thanks...gonna look those article right away.

 

and for vb i am using Microsoft excel. 

Zynk
5-Regular Member
(To:Ragnarok8979)

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

 

Ragnarok8979
6-Contributor
(To:Zynk)

Ragnarok8979_0-1626317898419.png

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:

  • When defining object variables you need to add Set cAC = New CCpfcAsyncConnection. This isn't required when using simple variables like strings, integers, boolean, etc.
  • When trying to execute tModel.Export() you need to add Call tModel.Export(). However, it seems to be inconsistent when adding this is required. For example, when using CreoWindow.Activate it is not required.
  • Some VB commands aren't supported in VBA.
    • Try/Catch is not available in VBA. You will have to use the VBA On Error GoTo
    •  Ctype is not available in VBA. In VBA, Dim two separate variables and Set one object type equal to a different object type to convert. Example:
      • 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?

RPN
17-Peridot
17-Peridot
(To:Ragnarok8979)

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. 

Ragnarok8979
6-Contributor
(To:RPN)

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.

Announcements


Top Tags