Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

CATIA V5 EXPORT MACRO

Status
Not open for further replies.

blamik303

Mechanical
Jun 23, 2014
3
NO
Hi guys

I'm newbie in CATIA Automation but I try to create some script/ macro to allows me to Export files from Active Window. I found some script for Export PDF/ DXF but this is not working as desired. Macro should let user choose directory where files should be exported (from Browse For Folder dialog box) and export the PDF/ DXF of active drawing in CATIA.

I have no Idea how to handel with this but I'm trying to "bound" few macros that I found on Google:

Sub CATMain()

Dim Doc As Document
Set Doc = CATIA.ActiveDocument

' Test the document's type, if it is not a drawing document the macro stops
If TypeName(Doc) = "DrawingDocument" Then
Dim DocDocument As DrawingDocument
Set DocDocument = Doc
Else
MsgBox "This macro can be run with a drawing document only."
Exit Sub
End If

Const WINDOW_HANDLE = 0
Const NO_OPTIONS = &H1
Dim objShellApp
Dim objFolder
Dim objFldrItem
Dim objPath

Set objShellApp = CreateObject("Shell.Application")
Set objFolder = objShellApp.BrowseForFolder(WINDOW_HANDLE, strTitle, NO_OPTIONS)

'~ If IsNoData(objFolder) Then
'~ WScript.Echo "You choose to cancel. This will stop this script."
'~ Wscript.Quit
'~ Else
'~ Set objFldrItem = objFolder.Self
'~ objPath = objFldrItem.Path

BrowseForFolderDialogBox = objPath

Set objShellApp = Nothing
Set objFolder = Nothing
Set objFldrItem = Nothing

'~ End If
Dim Doc As Document
Set Doc = CATIA.ActiveDocument

Doc.ExportData objPath & "\PDF\" & objFile.FileName & ".pdf", "pdf"
Doc.ExportData objPath & "\DXF\" & objFile.FileName & ".dxf", "dxf"
Set specsAndGeomWindow = CATIA.ActiveWindow
specsAndGeomWindow.Close

End Sub


Could someone help me on this?
 
Replies continue below

Recommended for you

Hi,

First observation is that after line BrowseForFolderDialogBox = objPath you should put a Msgbox just to check if you really got the path...then search with Google how to do it ( see this for example).

Looking there, I found that

Code:
Sub CATMain()

Const WINDOW_HANDLE = 0
Const NO_OPTIONS = 0
Set objShell = CreateObject("Shell.Application") 
Set objFolder = objShell.BrowseForFolder _
 (WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, "C:\Scripts") 
Set objFolderItem = objFolder.Self 
objPath = objFolderItem.Path

MsgBox objPath
End Sub

is working fine to get the path where I want to save the file.

Can you continue and post the final code?



Regards
Fernando

 
Hi Guys

Here's an updated code:

Code:
Sub CATMain()

'Retrive the active document

	Dim Doc As Document
	Set Doc = CATIA.ActiveDocument

'Test the document's type, if it is not a drawing document the macro stops
	If TypeName(Doc) = "DrawingDocument" Then
		Dim DocDocument As DrawingDocument
		Set DocDocument = Doc
	Else
		MsgBox "This macro can be run with a drawing document only."
	Exit Sub
	End If

Const WINDOW_HANDLE = 0
Const NO_OPTIONS = 0
Set objShell = CreateObject("Shell.Application") 
Set objFolder = objShell.BrowseForFolder _
 (WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, "C:\Scripts") 

Set objFolderItem = objFolder.Self 
objPath = objFolderItem.Path

MsgBox objPath

Set objFolderItem = CreateObject("Scripting.FileSystemObject")

Dim ShortPartNo, strFolderPath
ShortPartNo = Left(Doc.Name, 8)
MsgBox ShortPartNo
strFolderPath = objPath &"\"& ShortPartNo & "\"
MsgBox strFolderPath
If Not objFolderItem.FolderExists(strFolderPath) Then
objFolderItem.CreateFolder(strFolderPath)
End If

Doc.ExportData strFolderPath &  ShortPartNo& ".pdf", "pdf"

End Sub

In script I had to rename current part name cause I have a problem with Drawing file name. It looks like it's getting something like: Part Number+ some characters (probably from UUID).

But I need some help.

How can I force CATIA to overwrite already exported PDF file? Next question is how to bound script with other to make it more automatic? When I save drawing I would like to start my script automaticly. And other thing is how to force CATIA to remember first selected path i.e. at the beginning I choose a directory where to save exported files, but next time it should already remember this direction.

Could someone check the code?
 
Hi,

Are you working under a PDM system (like Enovia VPM for example) or with system files (CATIA files saved directly on HDD)?
You cannot use CATIA save command (from drop down menu) and then automatically run macro but you can save CATIA file within macro.
The path where to save is remembered during the execution of the macro.
Are you using this macro in a batch process or just once (for a single file opened in CATIA) and then again later?
You can overwrite any file with macro if is not already opened and if you have write access.
What is exactly the problem with the drawing name (search Google about UUID)?


Regards
Fernando

 
Hi ferdo

ferdo said:
Are you working under a PDM system (like Enovia VPM for example) or with system files (CATIA files saved directly on HDD)?

I'm working with CATIA V5 Team Center Integration. So far we don't have any plugin for CATIA Integration in Team Center to export and save PDF and DXF automaticly. That's why I decided to create scripts that's at least export PDF and DXF per "on click" and store on HDD, and later we can easily by drag and drop put them into TC.

ferdo said:
The path where to save is remembered during the execution of the macro.

Currently script is"asking" me each time I start it where to export the files. It would be perfect if for each session user could choose where to export the files, and decide whether CATIA will remember the selection or user will be able to select new directory every single time.

ferdo said:
Are you using this macro in a batch process or just once (for a single file opened in CATIA) and then again later?

Currently we are storing 3 types of files: master drawing (either it's in CATIA or NX), PDF and DXF. Export, when it goes about NX, it's made automaticly when saving master drawing, but for CATIA there's no such option in TC. That's why we need to make it manually. So I'm trying to make it at least "half-automated" process for now.

ferdo said:
You can overwrite any file with macro if is not already opened and if you have write access.

I put already
Code:
CATIA.DisplayFileAlerts = False
at the end and it helps.

ferdo said:
What is exactly the problem with the drawing name (search Google about UUID)?

Parts and Products files have no problem but when it goes about CATDrawings file name have some problems. Please refer to attached picture.



[URL=https://imagizer.imageshack.us/v2/418x121q90/840/2hav.jpg]


 
When you said is a problem with the drawing names I was almost sure that you are using a PDM system...
You can't avoid about asking the path running macro each time, eventually you have to input a fix path inside the macro, without option to browse. You can move files after using another method (a program manager, vbscript...).
For the drawing name you can try to get the name of the first link (meaning the part from where the drawing was created). This is easy working with system files, you can get the name of the part/product and also the path but I don't know how is working with TC.


Regards
Fernando

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top