Ilogic move and rename parts

Ilogic move and rename parts

Anonymous
Not applicable
1,498 Views
3 Replies
Message 1 of 4

Ilogic move and rename parts

Anonymous
Not applicable

I would like to know if it is possible to have ilogic code to rename a part/drawing to a totally new name? not prefix or suffix.. 123.ipt/idw becomes abc.ipt/idw.

 

I have the code below, but it creates a suffix of the user input number.

Can anyone help?

 

 

SyntaxEditor Code Snippet

' Start of iLogic code -------------------------------------------------------------------------------------

' Set drawing extension'Dim DWGType As String = ".dwg"
Dim DWGType As String = ".idw"

' Get current filename
CurrentFilename = ThisDoc.PathAndFileName(False) 

' Check that the drawing for this assembly can be found
If Not System.IO.File.Exists(CurrentFilename & DWGType) Then
    MessageBox.Show("Unable to locate the drawing file below for this part:" & vbLf & vbLf & _
    CurrentFilename & DWGType & vbLf & vbLf & _
    "Please make sure it's in the same folder as this assembly, has the same name, and has the file extension '" & DWGType & "'", "Copy Part and Drawing")
    Return
End If

' Prompt user for new part number
PartNum = InputBox("You are creating a new copy of the model and drawing" & vbLf & vbLf & _
"Please input the new part number" & vbLf & vbLf & _
"Note the current model will be closed and the new one opened...." & vbLf & vbLf & _
"Proceed?", "Copy Part and Drawing",)
If PartNum = "" Then ' Cancel was hit
    Return
End If

' Get new filename (without extension)
NewFileName = CurrentFilename & "_" & PartNum

' Perform Save As
ThisDoc.Document.SaveAs(NewFileName & ".ipt", False)

' Open the current drawing
Dim DrawingDoc As DrawingDocument = ThisApplication.Documents.Open(CurrentFilename & DWGType)

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

' Perform 'Save As' on the drawing
DrawingDoc.SaveAs(NewFileName & ".idw", False)

' Make the assembly model active again...
ThisDoc.Document.Activate

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

 

0 Likes
Accepted solutions (1)
1,499 Views
3 Replies
Replies (3)
Message 2 of 4

MechMachineMan
Advisor
Advisor
Accepted solution
Replace the line like this with below:

NewFileName = ThisDoc.Path & "\" & PartNum

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 4

Anonymous
Not applicable

that worked great!

 

at the moment it saves the new files into the same directory as the old files.

 

Is it possible that the new files can be saved in a new folder at the same level as the previous folder?

The new folder would be the same name as the new filename?  (...\123\123.ipt )

 

many thanks.

0 Likes
Message 4 of 4

MechMachineMan
Advisor
Advisor
Anything is possible with code man. Look up on google: "msdn + vb.net +
string operations"

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes