VBA - Open Document from search

Michael Laursen

VBA - Open Document from search

Hi all,

I have been working on a VBA macro that can retrieve a document(txt) from the database and open it in notepad.

How do i open any search result in theire repective editor/viewer..? in this case i would like to open the document i NotePad.

Thx for your help 

 

Maybe it can be done in EKL..?

 

/Michael

 

 

Fernando Petre

RE: VBA - Open Document from search
(in response to Michael Laursen)

Hi,

It can be done in same way like in V5.

 

Best regards

Fernando

https://picasaweb.google.com/102257836106335725208

https://picasaweb.google.com/103462806772634246699/

Michael Laursen

RE: VBA - Open Document from search
(in response to Fernando Petre)

Thx Fernando,

Okay, so how do you search a txt document and open it from Enovia in V5...?

/Michael

Fernando Petre

RE: VBA - Open Document from search
(in response to Michael Laursen)

From 3DEXPERIENCE DS documentation:

File Object

File Object


Represents a file.

The File object is operating system independent. Using it instead of those available with the platform you use makes your macro portable.

The File object derives from the FileComponent object from which it inherits the Path property. It aggregates:

  • A Folder object: its parent folder accessible using the ParentFolder property also inherited from the FileComponent object
  • A TextStream object that represents the file contents as a text stream, returned thanks to the OpenAsTextStream method.

Retrieving the File Object

Use the GetFile method of the FileSystem object, returned thanks to the FileSystem property of the Application object, to return an existing file.

Dim oFile As File
Set oFile = CATIA.FileSystem.GetFile("C:\tmp\myFile.txt")

In the same way, use the other properties and methods of the FileSystem object to create, copy, delete, and check for the existence of a file.

Using the File Object

Use the Size property to return the size of a file. The size is expressed in bytes.

Dim oSize As Long
Set oSize = oFile.Size

Best regards

Fernando

https://picasaweb.google.com/102257836106335725208

https://picasaweb.google.com/103462806772634246699/

Fernando Petre

RE: VBA - Open Document from search
(in response to Fernando Petre)

Sorry, I believe is not what you need.

Best regards

Fernando

https://picasaweb.google.com/102257836106335725208

https://picasaweb.google.com/103462806772634246699/

Michael Laursen

RE: VBA - Open Document from search
(in response to Fernando Petre)

I found this code in the 3DExperience Automation Help file. With this i can search a part or product and open it in CATIA. However, this code does not work for documents(In my case a txt file)


Sub CATMain()
Dim oSearchService As SearchService
    Set oSearchService = CATIA.GetSessionService("Search")
'Return a SearchService object from the Application object using the GetSessionService method.
    Dim oDatabaseSearch As DatabaseSearch
    Set oDatabaseSearch = oSearchService.DatabaseSearch
'Return the DatabaseSearch object aggregated to the SearchService object using the DatabaseSearch property.
    oDatabaseSearch.BaseType = "VPMReference"
    oDatabaseSearch.AddEasyCriteria "V_Name", "Bracket"
'Create the search parameters:
    oSearchService.Search

    Dim cPLMEntities As PLMEntities
    Set cPLMEntities = oDatabaseSearch.Results
    Dim oPLMOpenService As PLMOpenService
    Set oPLMOpenService = CATIA.GetSessionService("PLMOpenService")
    Dim oEditor As Editor
    Dim oPLMEntity As PLMEntity
    For Each oPLMEntity In cPLMEntities
        oPLMOpenService.PLMOpen oPLMEntity, oEditor
    Next

End Sub

 


In order to search the document, i changed the "Bold" to:


oDatabaseSearch.BaseType = "Document"
    oDatabaseSearch.AddEasyCriteria "Title", "Bracket"


Now it's able to search the document.. but still wont open the Document in NotePad.

Any suggestions..?

 

BTW. Are there any Teacherbased VBA courses for 3DExperience..?  

 

/Michael

 


Edited By:
Michael Laursen[Grundfos Holding A/S] @ Nov 07, 2016 - 01:45 PM (Europe/Copenhagen)

Fernando Petre

RE: VBA - Open Document from search
(in response to Michael Laursen)

I just searched and I found CAT-EN-VBA-F-V6R131 but is not what I would expect, is really just fundamentals.

....

Best regards

Fernando

https://picasaweb.google.com/102257836106335725208

https://picasaweb.google.com/103462806772634246699/

Michael Laursen

RE: VBA - Open Document from search
(in response to Fernando Petre)

Hi All,

I just found out that the Automation API does not support opening document from database search result in 3DExperience. At least not yet.. :-)

/Michael

Edited By:
Michael Laursen[Grundfos Holding A/S] @ Nov 07, 2016 - 05:35 PM (Europe/Copenhagen)