hello all,
I have large assemblies with sub-assemblies and parts in it. What i want to do is, name and number every assembly and part (excluding the content center parts) with some pre-defined coding.
For example: Lets say i have an assembly with 12 sub-assemblies and 35 parts. I want the assemblies named with PR1A[1], PR1A[2],.....PR1A[12] and parts with PR1P[1],.....PR1P[35].
is this possible with ilogic?
is there a way to say
"for i=1 to [total number of parts]
do this and that"
thanks in advance
Not knowing how many files you need to rename, but by any chance do you have vault?
If so there is functionality within the vault that allows you to create a numbering scheme.
With that you could accomplish what you are looking to do by renaming these files within the vault and using this numbering scheme you created.
Something else to consider is if you do not have vault, and you rename these parts, you run the risk of breaking links and having a real assembly mess on your hands.
If this solved your issue please mark this posting "Accept as Solution".
Or if you like something that was said and it was helpful, Kudos are appreciated. Thanks!!!!
You will need to think VERY carefully about actually renaming parts in an assembly because iLogic rules typically run on the current document - so renaming files that are already open is going to cause you a little grief! The other comment in your post that worries me is about renaming Content Center parts. I'ts probably a subject for another post, but if you rename a CC nut or bolt so it suits your current assembly, you are potentially breaking another assembly. (Unless all your placed CC parts go into a job-specific folder.)
As suggested above, Vault is absolutely the right solution for the problem you describe. However, if you want to rename/renumber on something more logical, like Part Number or Stock Number, the following might help: (You'll find this code pops up all over this forum - I can't remember the original author to give them credit.) Oh - and as it's written, it only does something when it finds a part, but I'm sure you can tweak as necessary.
fmgr = ThisApplication.Filemanager
For Each file In fmgr.files
doc = ThisApplication.Documents.ItemByName (file.fullfileName)
compdef = doc.ComponentDefinition
If (doc.documenttype = 12291) Then 'Found an ASSEMBLY
For Each occ In compdef.Occurrences
'Insert Try Catch here for catching exceptions thrown by suppressed components.
If (occ.definition.type = 83886592) Then 'Found a PART
'Add whatever you like here for the PART file
'Remember to add the occ.Name into everything to catch the part file itself
'If you forget it, you'll get the host Assembly
'This reads the Part number from each part in the assembly and writes it to a message box.
MessageBox.Show("Part name: " & iProperties.Value(occ.Name, "Project", "Part Number"))
End If
skippedPart:
Next occ
End If
Next file
InventorVb.DocumentUpdate() 'Update
The above will "crash" (as in throw an exception) if it comes across suppressed components.
You can insert the following Try Catch to skip suppressed components if you need it:
Try
occ.Name = ""
Catch ex As Exception 'If exception throw, go straight to next component.
'MessageBox.Show(ex.message)
Goto skippedPart
End Try
sorry for the late reply.
i think i'm a little bit misunderstood. I see that i wasn't very specific about the naming and numbering and naturally you guys thought i wanted to change file name. What i wanted to change was some iproperty value of parts and assemblies. Stock number, part number etc.
Other thing i wanted to do was exclude the content center parts from this rule. I don't want to rename cc part's part name, stock number etc. I want them excluded.
pcrawley i've inserted the code you've provided to one of my assemblies and there is a problem with it. It sorts every occurence of every part. If i wanted to use it to number the parts i have, it would try to increase the counter for every occurence.
i hope i'm making some sense and thanks for all the replies.
I just answered your question"is there a way to say "for i=1 to [total number of parts]do this and that" and gave you the code for that.
I didn't write you an application specific to your needs. You should probably approach you local reseller for something specific.
and i just said the code you've posted solves it for [total number of occurences of all parts]
it definitely helps but not the answer i was looking for. When it comes to vb i'm swimming in dark waters and i try to get all the help i can.
i don't know what i said has caused the hostility.
did it. below code does what i wanted to do. thx all
Dim openDoc As Document openDoc = ThisDoc.Document i = New integer(){1,2,3} j = New integer(){1,2,3} Dim docFile As Document i=1 j=1 If openDoc.DocumentType = 12291 Then For Each docFile In openDoc.AllReferencedDocuments If docFile.DocumentType = 12290 Then iProperties.Value(docFile.DisplayName, "Project", "Project") = "PR"+CStr(i) i=i+1 End If If docFile.DocumentType = 12291 Then iProperties.Value(docFile.DisplayName, "Project", "Project") = "PRoj"+CStr(j) j=j+1 End If Next End If