iLogic code for saving and replacing a part in assembly file

iLogic code for saving and replacing a part in assembly file

harisali110
Participant Participant
957 Views
3 Replies
Message 1 of 4

iLogic code for saving and replacing a part in assembly file

harisali110
Participant
Participant

Hi All,

 

I am new to iLogic and I am looking to create a code for the following application:

Preface: The user already has a new assembly document open and runs the code to do the following:

  1. iLogic loads a specific 'original' part file in the assembly document
  2. iLogic makes a 'copy' of this part (save as) and prompts the user to enter a new filename for this part and where to save this 'copy' of the part
  3. iLogic then replaces the 'original' with the 'copy'

The general application is that I want to make a library of 'original' parts so that the user can use them in their assembly as a 'copy' to make further modifications to the 'copy' which doesn't affect the 'original' parts in any way.

 

I've already tried the "Save & Replace" bonus feature in iLogic but as I understand it, you have to select the part in the tree or in the graphics window to proceed with the "Save & Replace" and there is no way around it.

 

Thanks in advance to all the iLogic experts here for helping me out.

 

Haris

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

A.Acheson
Mentor
Mentor
Accepted solution

Hi @harisali110  welcome to the forum. Here is one method to do this which includes a dialogue box to select the part file, place it at a location in the assembly then saves a new file and replaces the original. Let us know if that works. I have left in notes to describe the functioning to aid in learning. 

'Create a new FileDialog object.
    Dim FileDlg As Inventor.FileDialog 

  	ThisApplication.CreateFileDialog(FileDlg)

    'Define the filter to select part and assembly files or any file.
    FileDlg.Filter = "Inventor Files (*.ipt)|*.ipt|All Files (*.*)|*.*"
	
    'Set the title for the dialog.
    FileDlg.DialogTitle = "Save Copy As Utility"
 	'Set the title for the dialog.
  
    'Set the initial directory that will be displayed in the dialog.
    FileDlg.InitialDirectory = "C:\Users\Enter Name Here"

	FileDlg.ShowOpen
    
	'Deal with a canceled file Selection
 	If FileDlg.FileName = Nothing  Then Return

    'Set a reference to the assembly component definintion.
    Dim AsmCompDef As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
	
	'Post the filename To the Private Event queue.
   	ThisApplication.CommandManager.PostPrivateEvent(Inventor.PrivateEventTypeEnum.kFileNameEvent, FileDlg.FileName)
    
	'Get the control definition for the Place Component command.
    Dim ctrlDef As Inventor.ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd")
	 
	'Execute the command.
    ctrlDef.Execute2(True)


For Each Occ As ComponentOccurrence In AsmCompDef.Occurrences
	If Occ.Definition.Document.FullFileName = FileDlg.FileName Then
		'Select the occurrence just added
		ThisApplication.CommandManager.DoSelect(Occ)
	End If
Next

'Get the command (Button in the productivity tab)
ctrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyBonusTools_SaveAndReplaceComponentCmd")

'Execute the command.
ctrlDef.Execute()

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 4

harisali110
Participant
Participant

@A.Acheson Thanks! This is basically what I am looking for. I can play around with this now to get a suitable format. 

Message 4 of 4

e2000773
Enthusiast
Enthusiast

How would this be modified to work with ”place from vault”- filedialog? Is there any way?

0 Likes