Prompted name change when placing parts in an assembly

Prompted name change when placing parts in an assembly

Welbilt_Designer_3
Enthusiast Enthusiast
695 Views
5 Replies
Message 1 of 6

Prompted name change when placing parts in an assembly

Welbilt_Designer_3
Enthusiast
Enthusiast

I could use some advice concerning the changing of part names when placed in an assembly.

 

What I have so far is a form that appears when a prototype part is placed into an assembly Using Inventors place command (image 1)

 

When the rename button is selected the "save as" screen appears already set to the project folder the part is being added to so I can enter the appropriate name. (image 2)

 

This all works fine except that the name in the model tree is not changing even though it has been changed in iProperties and in the project folder (image 3)

 

Our designers want the name in the model tree to match the panel name to avoid confusion when checking the BOM, Any ideas?

 

I am doing this with a rule linked to a form that is set to activate when the panel is placed into a assembly. Here is the rule I am currently using.

 

 Code Snippet

'define the active document
oDoc = ThisDoc.Document

'create a file dialog box
Dim oFileDlg As inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)

'set Part type
oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"

'set the directory to open the dialog at
oFileDlg.InitialDirectory = ThisDoc.WorkspacePath()

'set the file name string to use in the input box
oFileDlg.FileName = iProperties.Value("Project", "Part Number")

'work with an error created by the user backing out of the save 
oFileDlg.CancelError = True
On Error Resume Next

'specify the file dialog as a save dialog (rather than a open dialog)
oFileDlg.ShowSave()


'catch an empty string in the imput
If Err.Number <> 0 Then
MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
ElseIf oFileDlg.FileName <> "" Then
MyFile = oFileDlg.FileName

'save the file 
oDoc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As
End If

 

I  

0 Likes
Accepted solutions (1)
696 Views
5 Replies
Replies (5)
Message 2 of 6

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi Danny,

 

As the name of part and location are changed. Component need to replace the part.

 

In addition to existing iLogic code, following changes (highlighted in red color) are required to replace part.

 

 

'define the active document
oDoc = ThisDoc.Document

'create a file dialog box
Dim oFileDlg As inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)

'set Part type
oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"

'set the directory to open the dialog at
oFileDlg.InitialDirectory = ThisDoc.WorkspacePath()
workPath = ThisDoc.WorkspacePath() 'set the file name string to use in the input box oFileDlg.FileName = iProperties.Value("Project", "Part Number")
oldName = iProperties.Value("Project", "Part Number")
'work with an error created by the user backing out of the save oFileDlg.CancelError = True On Error Resume Next 'specify the file dialog as a save dialog (rather than a open dialog) oFileDlg.ShowSave() 'catch an empty string in the imput If Err.Number <> 0 Then MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled") ElseIf oFileDlg.FileName <> "" Then MyFile = oFileDlg.FileName 'save the file oDoc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As End If

'Assuming that only one part is added with that name
Component.Replace(oldName & ":1", workPath & MyFile & ".ipt", True)

True : Replace all instances of this component. For ex: part:1, part:2 ..... part:n
False : Replace only single instance of that component. For ex: only part:1 will be replaced.


Please feel free to contact if there is any doubt.

 

If solves your problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,

 


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 6

Welbilt_Designer_3
Enthusiast
Enthusiast

Thanks Chandra, I appreciate the advice.

 

 The component replace code throws an error "only works in an assembly", I went with it anyway assuming that once the part was placed it would update but id didn't work.  I don't know if what I am trying to do is even possible since the rule bust be part of the panel and I am trying to update in the assembly.

 

Is there a way to make the name / tag match the part name assigned in iProperties without the component replace? or a way to initiate a secondary action to run the component replace?

 

0 Likes
Message 4 of 6

MechMachineMan
Advisor
Advisor

Doesn't the built-in "Save And Replace" feature handle this automatically?


--------------------------------------
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 5 of 6

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@Welbilt_Designer_3 wrote:

... the name in the model tree is not changing even though it has been changed in iProperties and in the project folder

 


 

Hi WelbiltDesigner,

 

I suspect there might be overrides on the bowser display name.

 

If you add this line does it fix the browser name issue:

oDoc.DisplayName = ""

 


Also here is a link to the original thread (just to keep things tied together):

https://forums.autodesk.com/t5/inventor-forum/file-rename-popup/m-p/7105907#M644833

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 6 of 6

Welbilt_Designer_3
Enthusiast
Enthusiast

That fixed it, The name in the assembly list now matches the part name in iProperties.

 

Thank you very much and thanks to everyone who contributed

0 Likes