how to copy folder containing .idw drawings and rename them with other reference

how to copy folder containing .idw drawings and rename them with other reference

2020mme013
Enthusiast Enthusiast
495 Views
4 Replies
Message 1 of 5

how to copy folder containing .idw drawings and rename them with other reference

2020mme013
Enthusiast
Enthusiast

hi

I have one folder in which there are .idw files and I have to create each files 20 different drawings with other reference number of each. the .idw file should copy the all drawing details instead of keeping the same reference number to its name. I am trying with VBA. please anyone knows about this type of automation help me. Thanks in advance

0 Likes
Accepted solutions (1)
496 Views
4 Replies
Replies (4)
Message 2 of 5

BM_Ashraf
Advocate
Advocate

Hi,

Not sure if this Add-in the right one for you, but might be helpful in replacing References. 
Notice, you can only copy form Part or Assembly not from Drawing.

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.

Blue Mech

Add-ins for Inventor!

0 Likes
Message 3 of 5

2020mme013
Enthusiast
Enthusiast

hey, Thanks for your reply can you please provide me some piece of code. 

0 Likes
Message 4 of 5

BM_Ashraf
Advocate
Advocate
Accepted solution

Sure,

Here is a similar iLogic Rule.

'This Rule is done By MechDS 28.07.2022 
'For Help Please contact me Email: zezo15330@gmail.com 
'Youtube 
'https://www.youtube.com/MechInventor
'Grab cad
'https://grabcad.com/mech.inventor-1 

Dim oDoc As Document = ThisApplication.ActiveEditDocument

Dim oDChack As Boolean = True
Dim oDSuffix As String = ".idw"

'Current file path 
Dim oPath As String = System.IO.Path.GetDirectoryName(oDoc.FullDocumentName)

'Get current filename without extension
Dim CurrentFilename As String = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullDocumentName)
'MsgBox (CurrentFilename)
'Get current path
Dim Path As String = oPath

'Check that the drawing for this part can be found
If Not System.IO.File.Exists(System.IO.Path.ChangeExtension(oDoc.FullDocumentName, oDSuffix)) Then
 	   oDChack = Fasle
	   MessageBox.Show("Couldn't find the Drawing document!" & vbLf & vbLf & "Drawing won't be copied" , "Document Type")	 
End If

' Prompt user for job number
Dim NewFileName As String = InputBox("You are creating a new copy of this Document and its 2D drawing file" & vbLf & vbLf & _
"Please input a new name for the design" & vbLf & vbLf & _
"Note the current part will be closed and the new one opened...." , "Save As", "")
If NewFileName = "" Then ' Cancel was hit
    Return
End If

oAnsewer = MsgBox("Do you want to save the file to the same Path", MsgBoxStyle.YesNo, "Path")

If oAnsewer = vbNo Then 

		'Create new FolderBrowserDialog 
		Dim Dialog = New FolderBrowserDialog()
		
		'Start search path
		Dialog.SelectedPath = oPath
		Dialog.ShowNewFolderButton = True
		Dialog.Description = "Please select a folder"
		
		' Check Path 
		If DialogResult.OK = Dialog.ShowDialog() Then
			Path = Dialog.SelectedPath
        End If 
End If

 'MessageBox.Show(Path, "PAth")
 
' Perform Save As of Part
On Error Resume Next 
Call oDoc.SaveAs(Path & "\" & NewFileName & ".ipt", False)

'Drawing check 
If oDChack = False Then
	
   Exit Sub 

End If 

Dim DrawingDoc As DrawingDocument = ThisApplication.Documents.Open(oPath & "\" & CurrentFilename & oDSuffix, False)

' Replace reference to part model
Dim oFD As FileDescriptor
oFD = DrawingDoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
Call oFD.ReplaceReference(Path & "\" &NewFileName & ".ipt")
DrawingDoc.Update()

' Perform 'Save As' on the drawing - change this to reflect your drawing type .dwg or .idw
   DrawingDoc.SaveAs(Path & "\" & NewFileName & oDSuffix, False)

' Make the assembly model active again...
oDoc.Activate()

' End of iLogic code ---------------------------------------------------------------------------------------------

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.

Blue Mech

Add-ins for Inventor!

0 Likes
Message 5 of 5

2020mme013
Enthusiast
Enthusiast

Simply you are genius... Thanks for this AddIn, this is very useful for me. 

0 Likes