Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Need help to create macro to import pdf, dwg, dxf files in catia drawing.

Status
Not open for further replies.

Rangraop

Automotive
Mar 19, 2014
21
Hello Everybody,
I would like to create large number of drawings (around 500+) and need to import pdf(mostly) or dxf or dwg for each drawing.
Let me clarify in more detail.
1. Suppose I have two folders, one folder contains drawings with part nos. like A, B, C....
and other folder contains files like pdf, dxf, dwg, png, jpg with names like A, B, C....
2. My task is to import these files into the corresponding CATDrawing(kept in other folder) with same name.
e.g. In a file A.CATDrawing, I should import the file A.pdf (it may be of any extension mentioned earlier)
Let me know if anyone has any queries regarding this.

Thanks in advance... I am trying to import pdf file to a drawing using macro since long time.. but not succeeded. I found this forum and thought of sharing with you guys.

.. Rangrao Padiyar
 
Replies continue below

Recommended for you

Thanks ferdo for your reply..
Actually I was hoping a reply from you. I have seen your recent posts and you have helped lot of members.
I have checked the post which you mentioned, I have same scenario with lot of pdf files to import. I cannot use images because of readability issue.
I have a script that imports images in drawing.. but I want to import pdf file. As I can convert pdf to dwg or dxf that will also work for me.
Right now I don't have the code with me. I'll post it very soon.

Thank you,
Rangrao
 
Hi Ferdo,

I have code, which is copied from Portable script center shared by you... :)

Can It be edited to insert pdf file. I tried by changing the extension from jpg to pdf, also removed the code to resize the pic but not succeeded. Can you check and help me on this?

My requirement is instead of logo I want to insert pdf file in a user created view.

**************************************************************
Private Const RATIONONE=0
Private Const RATIOWIDTH=1
Private Const RATIOHEIGHT=2
Dim oDocument
Dim oSheets
Dim oSheet
Dim oView
Dim oPictures


Public Sub CATMain()

on error resume next
Set oDocument = CATIA.ActiveDocument
If Err.Number <> 0 Then
Set oDocument = CATIA.Documents.Add("Drawing")
Err.Clear
End If
On Error GoTo 0

Set oSheets = oDocument.Sheets
Set oSheet = oSheets.ActiveSheet
Set oView = oSheet.Views.ActiveView
Set oPictures = oView.Pictures

MsgBox "The macro will insert a jpg file in your drawing at position x =150, y =0. The file must be in the folder C:\temp\ (which should be created before runnning the macro) and must have the name Logo. Modify the code if you want something else"

InsertPicture "c:\temp\Logo.jpg", 150, 0, RATIOHEIGHT, 100,25

End Sub

Sub InsertPicture (strPath , dblAnchorX, dblAnchorY, prRatio, dblWidth, dblHeight)
Dim objPicture

Set objPicture = oPictures.Add(strPath, dblAnchorX, dblAnchorY)
FormatPicture objPicture, prRatio,-1 ,-1 , dblWidth, dblHeight

Set objPicture = Nothing
End Sub

Public Sub FormatPicture(objPicture , prRatio , dblAnchorX, dblAnchorY, dblWidth , dblHeight )
Dim dblScalar

If dblAnchorX >= 0 Then objPicture.X = dblAnchorX
If dblAnchorY >= 0 Then objPicture.Y = dblAnchorY

If prRatio = RATIOWIDTH Then
'Picture scaled by width with fixed ratio
If dblWidth > 0 Then
dblScalar = objPicture.Width / dblWidth
objPicture.Height = objPicture.Height / dblScalar
objPicture.Width = dblWidth
End If
ElseIf prRatio = RATIOHEIGHT Then
'Picture scaled by Height with fixed ratio
If dblHeight > 0 Then
dblScalar = objPicture.Height / dblHeight
objPicture.Width = objPicture.Width / dblScalar
objPicture.Height = dblHeight
End If
Else
'Picture scaled by width & height
If dblWidth > 0 Then objPicture.Width = dblWidth
If dblHeight > 0 Then objPicture.Height = dblHeight
End If

End Sub

**************************************************************

Thanks,
Rangrao
 
Is not enough to just change the files extensions...to import dxf or dwg is simple, you can find a lot of code examples....just use

Dim drawingDocument1 As Document
Set drawingDocument1 = documents1.Open("C:\temp\test.dwg")

As you probably notice you cannot open directly pdf in CATIA, you have to use Insert-Object...I know how to do it in vbs, you have to use OLEObjects.Add , but I don't know if in CATScript is working in the same way...

Regards
Fernando

 
Hi Ferdo,
Thanks for your reply. I just tried opening the dwg file. it works, just modified to define the variables.
Can you tell how to import pdf file in vbs? I will give a try.
Thanks,
Rangrao

 
Import pdf in EXCEL in a vbs script file

Code:
Dim Xl
Dim Wb
Dim Ws
Dim Ol

Set Xl = CreateObject("Excel.Application")
Set Wb = Xl.Workbooks.Add
Set Ws = Wb.Worksheets.Add

Set Ol = Wd.OLEObjects.Add(, "c:\temp\test.pdf", True, False)

    With Ol
        .Left = Ws.Range("A1").Left
        .Height = Ws.Range("A1").Height
        .Width = Ws.Range("A1").Width
        .Top = Ws.Range("A1").Top
    End With

Xl.Visible = True

Regards
Fernando

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor