Replace assembly component in new folder. Inventor 2020. VBA or Apprentice

Replace assembly component in new folder. Inventor 2020. VBA or Apprentice

coderuna
Participant Participant
986 Views
2 Replies
Message 1 of 3

Replace assembly component in new folder. Inventor 2020. VBA or Apprentice

coderuna
Participant
Participant

My flow

 

I use Design Assistant now, but it is so boring 🙂

 

I copy Assembly, SubAssembly, Parts and Drawings from old folder to new folder and rename files from ABC 1 to ABC 2... with windows cmd.

 

What I should do next is to replace or actually resolve files from new folder. And I would like to do it with some automation.

 

For example I am using VBScript in Winautomation for SAP GUI but I dont think I can use this VBScript for Inventor.

 

I found VBA Example

 

Public Sub CReplace()

Dim oOccurrence As ComponentOccurrence
Set oOccurrence = ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.Item(1)
oOccurrence.Replace "<filename>", True


End Sub

 

I have files:

 

A.iam (main assembly)

B.iam:1 (SubAssembly)

C.iam:1 (SubAssembly)

 D:1.ipt (Part)

  E.idw (Drawing)

 

*** Item (1), I don`t ge it, all files have :1 on the end and another assembly might have different number of files.

How to choose item with file name for example:

 

"change B.iam (old folder) to Bxxx.iam (new folder)"

"change C.iam (old folder) to Cxxx.iam (new folder)"

"change D.ipt (old folder) to Dxxx.iam (new folder) with Exxx.idw"

 

Any ideas

 

 

 

 

0 Likes
987 Views
2 Replies
Replies (2)
Message 2 of 3

dutt.thakar
Collaborator
Collaborator

@coderuna 

 

I think instead of using Design assistant, if you are not using Vault you can use iLogic Design Copy which allows you to copy the assembly with structure and you can rename it. (The limitation with rename is you can only add prefix and suffix to an existing name, you can not change the base name, don't know why it is like that.)

 

Please see below, the screencast for the iLogic Design Copy tool and some documentation as well.

 

https://knowledge.autodesk.com/support/inventor/learn-explore/caas/screencast/Main/Details/4292f9b9-...

 

https://www.synergis.com/2014/09/23/copy-files-easily-with-ilogic-design-copy-even-without-ilogic-ru...

 

Second thing, if you still want to do with iLogic or VB Script, what you can do is, use ItemByName property for an occurrence for replacing it, so in this case "ITEM(1)" will not work, Item(1) means the first occurrence that is in the assembly.

 

Try the below code, I have not tested it

 

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oOcc As ComponentOccurrence = oDoc.componentDefinition.ItemByName("Name you see in the browser")
oOcc.Replace("filename.ipt",True)

 

In the above code, you can keep the second argument either True or False (Marked in bole)

True means: if you have "A01" assembly and it is placed three times in the main assembly (i.e. A01:1, A01:2, A01:3) it will replace all.

False means: it will only replace "A01:1" and not "A01:2" and "A01:3" even though it is the same.

 

I hope this will be helpful.

 

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
Message 3 of 3

coderuna
Participant
Participant

Copy with iLogic or DesignAssistant takes time. Point is that I copy files from one folder to the other and rename them. Now I would like to run a script which will replace all parts in opened Assembly (new one) path from old folder to new folder.

0 Likes