Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need iLogic/VB code to save all parts in an assembly to new files...

8 REPLIES 8
Reply
Message 1 of 9
JamesNordgren
2789 Views, 8 Replies

Need iLogic/VB code to save all parts in an assembly to new files...

Hello All,

This is directed to Curtis, although anyone's input is certainly welcome...

 

I have an assembly (lets call it a tank cover) which is configured using an iLogic input form.  The assembly will have about 20-30 parts, depending on the options the user selects.  I t works very well as a standalone configurator, but I want to make it into a tool which can be used by others.  Currently, this can be done using the 'Copy Design' function from Vault, but that is not the workflow I want for several reasons, not important here.

 

So how can I:

  1. Get the set of all components in the assembly
  2. SaveCopyAs and Replace each component in the set with a new filename ("a job# already entered by user in my form" prefixed to original filename) to a user-selected path
  3. Save the assembly with a new name (same job# prefixed to original name) to the same user-selected path

 

I would like this rule or section of code to run only when the user clicks a "Save Local Files" button at the bottom of my form (which only becomes active after user fills in required parameters)

 

I figure someone out there has a canned solution for this or very similar to it...  Any help is so appreciated.

 

Thanks

 

James

 

8 REPLIES 8
Message 2 of 9
adam.nagy
in reply to: JamesNordgren

Hi James,

 

You want to do the above just so that the rules will be available in other/new files?

If so, then what about creating external rules instead which could be used from any part/assembly?

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 9

Hi Adam, thanks for the reply.
Actually, I am trying to do more of a "Copy Design" function. I have a nice assembly which runs an iLogic Form, which has all the inputs and options to configure the assembly. It works great, but it requires Copy Design from the vault to get a "job-specific" instance of the configured assembly. Basically, I want users to be able to be able to insert or open the read-only Master assembly from vault, run the configurator, and then have it copy-design itself to the path the user selects in the configurator.

I hope that makes sense, and thanks again for your help.

James



[Description: cid:image8e4647.jpg@9776527f.9c6f431a]

James Nordgren
Mechanical Engineer
Research & Development

Email: jnordgren@deltastar.com

Delta Star Inc.
3550 Mayflower Drive
Lynchburg
Virginia 24501

Tel: 434 845-0921
Web: www.deltastar.com
Message 4 of 9
adam.nagy
in reply to: JamesNordgren

Hi James,

 

If it's a single level (simple assembly with parts) then you could do something like this:

Sub CopyAssembly()
    Const newFolder As String = "C:\temp\asm\"
    Const prefix As String = "new_"
    
    Dim fileMgr As FileManager
    Set fileMgr = ThisApplication.FileManager
    ' In case folder or file already exists
    ' we get an error that we can ignore
    On Error Resume Next
    Call fileMgr.FileSystemObject.CreateFolder(newFolder)
    
    Dim asm As AssemblyDocument
    Set asm = ThisApplication.ActiveDocument
    
    Dim fileName As String
    fileName = fileMgr.FileSystemObject.GetFileName(asm.FullFileName)
    Call asm.SaveAs(newFolder + prefix + fileName, True)
    
    ' Just open it in the background
    Set asm = ThisApplication.Documents.Open(newFolder + prefix + fileName, False)
    
    Dim fileDesc As FileDescriptor
    For Each fileDesc In asm.file.ReferencedFileDescriptors
        fileName = fileMgr.FileSystemObject.GetFileName(fileDesc.FullFileName)
        Call fileMgr.CopyFile(fileDesc.FullFileName, newFolder + prefix + fileName)
        Call fileDesc.ReplaceReference(newFolder + prefix + fileName)
    Next
    On Error GoTo 0
     
    asm.Update
    asm.Save
    asm.Close
End Sub

I hope this helps.

Cheers,



Adam Nagy
Autodesk Platform Services
Message 5 of 9
frank.schalla
in reply to: adam.nagy

Hello Adam

 

great can you give me the right way to do this also with a multi level assembly ?

Please i need this badly 🙂

Thank's for your help

 

Message 6 of 9

You may test Inventor plugin Hierarchy Clone for Inventor.

It can be found in the ADN PLUGIN OF THE MONTH CATALOG

http://labs.autodesk.com/utilities/ADN_plugins/catalog/

(see Inventor section).

This utility is delivered with the source VB code, so you may learn a lot on the "Copy Design" internals.

Cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 7 of 9
azem.bunjaku
in reply to: adam.nagy

I've been looking for a code that does kind of like this one you posted.

There is a function in assembly called Save and Replace Component.

 

I would like to do Save and Replace Component and at the same time save a copy of the related drawing.

Then I also need to replace the model reference in the drawing of course.

 

Thanks a lot!

 

BR

Azem

Message 8 of 9
Anonymous
in reply to: JamesNordgren

Sorry to awaken an old thread but was this solved for an assembly document with sub-assemblies?

Trying to do the exact same thing as you describe.

 

 

Thanks,

Max

Message 9 of 9
P_Korgaonkar
in reply to: Anonymous

Hey Guys,

Trying to do the exactly same,

Can any one help?

 

Regards

Parag 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report