×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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

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

(OP)
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

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

(OP)
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

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

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

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

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

(OP)
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

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

Import pdf in EXCEL in a vbs script file

CODE --> vbs

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

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources