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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Example code to Save As (Save a Copy) an existing assembly using VB API

sndong-mefane
5-Regular Member

Example code to Save As (Save a Copy) an existing assembly using VB API

Hello,

There is an example code using JLINK available here: https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS153609&art_lang=en&posno=1&q=vb%20api%20assembly%20save%20as&…

But I am looking for the VB.net version. especially the VB.net version of the following portion:

in VB API, "model.Backup" does not seem to work correctly, and "model.copy/copyandretrieve" don't include the part files.

Model model = session.RetrieveModelWithOpts(modelDescriptor, pfcSession.RetrieveModelOptions_Create());

ModelDescriptor md = model.GetDescr();

is there an equivalent to "GetDescr()" in VB API?

Does "model.Backup(...)" works correctly in your VB.net code?

Stephane


This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
1 ACCEPTED SOLUTION

Accepted Solutions

For those who Need to do the same thing using VB.net, here is my solution:

Imports pfcls

Imports System

Module Module1

    Sub Main()

        Dim connection As IpfcAsyncConnection

        Dim cac As New CCpfcAsyncConnection

        Dim session As IpfcBaseSession

        Dim template As IpfcModel

        Dim path As String

        Dim descModel As IpfcModelDescriptor

        Dim opt As IpfcRetrieveModelOptions

        Dim Modi As IpfcModelDescriptor

        Dim win As IpfcWindow

 

        'Dim descModelCreate As CCpfcModelDescriptor

        path = "C:\ptc\Creo_2.0\Parametric\bin\parametric.exe"

        Try

            'Start a new Creo Session

            connection = cac.Start(path, ".")

            session = connection.Session()

            session.ChangeDirectory("C:\work4\model\")

            session.LoadConfigFile("M:\PRO_E\Creo\configs\config.pro")

            connection.EventProcess()

            session.AuthenticateBrowser("******", "*****")

            System.Threading.Thread.Sleep(5000)

            'Open and display the template assembly model located in M:\ drive

            opt = (New CCpfcRetrieveModelOptions).Create()

            opt.AskUserAboutReps = False

            descModel = (New CCpfcModelDescriptor).CreateFromFileName("axialcasing.asm")

            descModel.Path = "M:\PRO_E\Creo\start_files\templates\07_Exhaust_Casing_3D_models\Type1\"

            template = session.RetrieveModelWithOpts(descModel, opt)

            win = session.GetModelWindow(template)

            template.Display()

            Modi = template.Descr()

            Modi.Path = "C:\work4\model"

            template.Backup(Modi)

            connection.Disconnect(DBNull.Value)

        Catch ex As Exception

            MsgBox("problem")

        End Try

    End Sub

End Module

View solution in original post

1 REPLY 1

For those who Need to do the same thing using VB.net, here is my solution:

Imports pfcls

Imports System

Module Module1

    Sub Main()

        Dim connection As IpfcAsyncConnection

        Dim cac As New CCpfcAsyncConnection

        Dim session As IpfcBaseSession

        Dim template As IpfcModel

        Dim path As String

        Dim descModel As IpfcModelDescriptor

        Dim opt As IpfcRetrieveModelOptions

        Dim Modi As IpfcModelDescriptor

        Dim win As IpfcWindow

 

        'Dim descModelCreate As CCpfcModelDescriptor

        path = "C:\ptc\Creo_2.0\Parametric\bin\parametric.exe"

        Try

            'Start a new Creo Session

            connection = cac.Start(path, ".")

            session = connection.Session()

            session.ChangeDirectory("C:\work4\model\")

            session.LoadConfigFile("M:\PRO_E\Creo\configs\config.pro")

            connection.EventProcess()

            session.AuthenticateBrowser("******", "*****")

            System.Threading.Thread.Sleep(5000)

            'Open and display the template assembly model located in M:\ drive

            opt = (New CCpfcRetrieveModelOptions).Create()

            opt.AskUserAboutReps = False

            descModel = (New CCpfcModelDescriptor).CreateFromFileName("axialcasing.asm")

            descModel.Path = "M:\PRO_E\Creo\start_files\templates\07_Exhaust_Casing_3D_models\Type1\"

            template = session.RetrieveModelWithOpts(descModel, opt)

            win = session.GetModelWindow(template)

            template.Display()

            Modi = template.Descr()

            Modi.Path = "C:\work4\model"

            template.Backup(Modi)

            connection.Disconnect(DBNull.Value)

        Catch ex As Exception

            MsgBox("problem")

        End Try

    End Sub

End Module

Top Tags