copy an external file using ilogic

baroHakam
Explorer

copy an external file using ilogic

baroHakam
Explorer
Explorer

Hi,

I am looking for a command or code to copy an external file using ilogic. To clarify this issue, I want to tell you my case. I have an ipart in a folder that this ipart has a drawing with the same name in this folder. I have written a code to save a copy from this ipart with a new name but i want simultaneously to copy the drawing with the new name of ipart. Until now I have all of the addresses for new drawing including path and file name with the extension but I don't know how to copy it. I don't want to open the drawing and then save a copy. my code is as follows:

thanks.

 

oFileName = ThisDoc.FileName(False) 'without extension

'Craeting New File
Do oNewPartName = InputBox("Please give complete name for the new file" , "CheckBox", "") oNewPartNumber=Left(oNewPartName,8) oCheck = Left(Mid(oNewPartName, 9), 1) If oCheck = "_" And IsNumeric(oNewPartNumber) = True Then Exit Do Else End If Loop 'Save New File FileToSave = ThisDoc.Path & "\" & oNewPartName & ".ipt" 'Copy Drawing 'Path of the original Drawing Dim oOrigPath As String = ThisDoc.Path 'Name of the original Drawing Dim oOrigName As String=ThisDoc.Path & "\" & oFileName & ".dwg" 'Path of the new Drawing Dim oNewPath As String = ThisDoc.Path 'Name of the new Drawing Dim oNewName As String = ThisDoc.Path & "\" & oNewPartName & ".dwg" If (System.IO.File.Exists(oOrigName)) = True Then 'I want to copy oNewName in the same folder of oOrigName??????? Else
Messagebox.Show("There is no Drawing for this Part") End If

 

0 Likes
Reply
Accepted solutions (1)
530 Views
2 Replies
Replies (2)

JelteDeJong
Mentor
Mentor
Accepted solution

making a copy is not dificult:

 

System.IO.File.Copy( oOrigName , oNewName  )

the problem starts when you open the new file. The refrence in the file will be to the original file. I guess you also want to change that and that is only possible by opening the file.

the following code will open the original file, replace the refrence, saveas and close it.

Dim drawinDoc As DrawingDocument = ThisApplication.Documents.Open(oOrigName, False)

For Each oFD As FileDescriptor In drawinDoc.File.ReferencedFileDescriptors
    If oFD.FullFileName = oOrigName Then
        oFD.ReplaceReference(FileToSave)
    End If
Next

drawinDoc.SaveAs(oNewName, False)
drawinDoc.Close()

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

baroHakam
Explorer
Explorer

Dear my friend,

 

that works. before I used the following and confront Error:

 

System.IO.File.Copy( oOrigPath & oOrigName , oNewName  )

thanks 

0 Likes