Saving the pieces with a new part number to folders

Saving the pieces with a new part number to folders

dypro
Advocate Advocate
588 Views
8 Replies
Message 1 of 9

Saving the pieces with a new part number to folders

dypro
Advocate
Advocate

Hello everyone,

my company has decided that when we create an assembly in a folder, every piece within the assembly should be saved in a folder in the same folder the assembly is.

Up to this point there is no problem. Here is the catch: every piece has to have a part number relative to wich one is bigger, the bigger the piece, the smaller the number starting with 001, 002, 003.... (obviously this does not aply if there are content center parts)

On top of that, each part has to be in a folder named after the assembly and that part number

 

For example if an assembly is called 0440-3-Z-1000.iam

and it's made out of 4 pieces 3 normal ipts and one from the content center

the pieces should have the part numbers: 001, 002 and 003 starting with the bigger piece.

The content center piece should remain untouched.

The folder of the assembly is called 0440-3-Z-1000 and the folder of each file should be 0440-3-Z-1000-001 (with the 001 part inside), 0440-3-Z-1000-002 (with the 002 part inside) and 0440-3-Z-1000-003 (with the part inside)

 

Is there a way to automate this? we have assemblies with hundreds of parts sometimes and it will be a nightmare if we don't find a way to make this automatically.

 

(It is better if the part number is assigned by one lisp and the folder and save thing is made by another one)

 

Thankyou all, I hope you can help me

0 Likes
589 Views
8 Replies
Replies (8)
Message 2 of 9

dypro
Advocate
Advocate

BUMP

Anyone help pls?

0 Likes
Message 3 of 9

Mathias_CompC
Enthusiast
Enthusiast

Is it something like this you are looking for?

If not System.IO.Directory.Exists(folder)
System.IO.Directory.CreateDirectory(folder)

for each oDoc in ThisDoc.Document.AllReferenced documents
oDoc.SaveAs()
Next

 and/or do you want the component references to update?

 

Important consideration, do you use vault?

What version are you on?

0 Likes
Message 4 of 9

dypro
Advocate
Advocate

hi again @Mathias_CompC 

I need the rule to create a folder with the name I posted earlier for each ipt, then to save the ipt into that folder.

not sure what " and/or do you want the component references to update?" does mean....

I use inventor pro 2021 and the vault is 2021 as well

0 Likes
Message 5 of 9

Mathias_CompC
Enthusiast
Enthusiast

Creating a folder and saving a copy of a part or assembly is not an issue, the component reference I'm referring to is if you would also like to replace the part in the assembly to the new one.

If so it's a bit trickier. And, on top of that, if you check out a file from vault you can not(!) move that file and check it in from another location. What you need to do if you want Vault to keep track of the files is to actually use Vault to move the files first, I'm not sure how much of the automation interface is available in the 2021-client( I know that I'm not versed enough to do it in 2021 ).

If you however save a copy of the part locally, update the reference in the assembly and check in the new file with the assembly you could have a new structure. I'm very happy I'm not your vault manager....

0 Likes
Message 6 of 9

dypro
Advocate
Advocate

The assembly should be saved in a folder.

Most of the parts in the assembly are created in another folder (most of them will be in the same folder called AUXILIAR).

Then you run the macro to make the part number of the pieces become 001,002,003 and so on starting with the piece with most weight.

Then you run the other macro that creates as many folders as the last part number that was used.

Each of them with the name of the assembly+the part number of the piece they are meant to hold (nameoftheassembly-001, nameoftheassembly-002, and so on) 

Then you move/copy the piece with 001 part number to the "nameoftheassembly-001" folder, the piece with 002 part number to the "nameoftheassembly-002" folder and so on

If you moved them, that's it; if you copied them, replace the original parts with the copied ones and erase the originals.

For the purpose of the macro, let's say that the assembly is not "checked in" in the vault so there is no problem 

0 Likes
Message 7 of 9

Mathias_CompC
Enthusiast
Enthusiast

That should definitely be doable, to get you started I'd suggest the fine works at: hjalte.nl ,  and it's less eloquent but still competent: ransensoftware.com

0 Likes
Message 8 of 9

dypro
Advocate
Advocate

hello @Mathias_CompC I already know about Jelte de Jong, ransensoftware was new to me, but the very first thing that sais is that "You need to be a decent C++ programmer and have a good working knowledge of Windows MFC"

I learned a bit of C++ on my own like 20 years ago (totally forgotten) and I don't even know what Windows MFC stands for.

No matter that, I tried finding something useful right now and I found this:

 

 

Option Explicit
Public Sub ShowDocuments2()
    ' Get the Documents collection object.
    Dim invDocs As Documents
    Set invDocs = ThisApplication.Documents
    Dim sExt As String
    ' Iterate through the contents of the Documents collection.
    Dim invDocument As Document
    Dim SubDoc As Document
    Dim Asm As AssemblyDocument
    Dim DocsInAsm As DocumentsEnumerator
    For Each invDocument In invDocs
        ' Display the full filename of the document in the Immediate window.
         sExt = Right(invDocument.FullFileName, 3)
        If sExt = "IAM" Then
             Set Asm = invDocument
             Set DocsInAsm = Asm.AllReferencedDocuments
             Debug.Print "Assembly " & invDocument.FullFileName & " has " & DocsInAsm.Count & " sub documents"
             For Each SubDoc In DocsInAsm
                 Debug.Print "   SubDoc " & SubDoc.FullFileName
             Next
        End If        
    Next
End Sub

 

 

That I think should list opened documents, but that would also list other docs, not just the one assembly that I need
(anyway I tried it and I did not manage to make it work) 

 

0 Likes
Message 9 of 9

Mathias_CompC
Enthusiast
Enthusiast

I would be very willing to help any forum member with what assistance I can. If you need development services there are probably many that are willing to work with you, but I don't believe this is the correct forum for this.

0 Likes