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: 

Copy filename to part number for all parts and sub-assemblies in assembly

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
587 Views, 4 Replies

Copy filename to part number for all parts and sub-assemblies in assembly

here's a macro I wrote to copy the filename to the Part Number iProperty for all parts and sub-assemblies contained in a top-level assembly. I wrote this after using a bunch of custom iParts and all the Part Numbers were the same for each part! (my fault of course, but a pain to fix one at a time). Use at your own risk. Enjoy!

--------------------------------------------------------------------------


Public Sub SetAllComponentPartNumbersToFileName()

Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = GetActiveAssembly
If oAsmDoc Is Nothing Then Exit Sub

SetAssemblyComponentPartNumbersToFileName oAsmDoc

End Sub



Public Function GetActiveAssembly() As AssemblyDocument

If ThisApplication.ActiveDocument.DocumentType = kAssemblyDocumentObject Then
Set GetActiveAssembly = ThisApplication.ActiveDocument
Else
MsgBox "Must have an assembly active", vbOKOnly, "Error"
End If

End Function




Public Function SetAssemblyComponentPartNumbersToFileName(oAsmDoc As AssemblyDocument)

Dim sFile As String
Dim sPart As String
Dim oDoc As Document
Dim oPropSet As PropertySet
Dim oProp As Property
Dim oRefFileDesc As ReferencedFileDescriptor
For Each oRefFileDesc In oAsmDoc.ReferencedFileDescriptors

If oRefFileDesc.DocumentType = kPartDocumentObject _
Or oRefFileDesc.DocumentType = kAssemblyDocumentObject Then

' get the part number string
sFile = oRefFileDesc.FullFileName
sPart = Right(sFile, Len(sFile) - InStrRev(sFile, "\"))
sPart = Left(sPart, InStrRev(sPart, ".") - 1)

Set oDoc = oRefFileDesc.ReferencedDocument
' get part number iProp
Set oPropSet = oDoc.PropertySets.Item("Design Tracking Properties")
Set oProp = oPropSet.Item("Part Number")
oProp.Value = sPart

End If

' recursive to descend into all assemblies
If oRefFileDesc.DocumentType = kAssemblyDocumentObject Then
SetAssemblyComponentPartNumbersToFileName (oRefFileDesc.ReferencedDocument)
End If

Next oRefFileDesc

End Function
4 REPLIES 4
Message 2 of 5
j.romo
in reply to: Anonymous

thank you this works great

Message 3 of 5
jaredhowell1337
in reply to: Anonymous

Hi Josh,

 

This ilogic rule is exactly what I need! I renamed a load of parts in Vault as the company I have just joined were in a desperate need for CAD re-structure.  However I didn't tick "update part numbers" on all the rename processes.  Absolute sickener!

 

Anyway I am getting this error with your code (see attached).  Could you tell me where I've gone wrong please?

 

Thanks in advance!

---------------------------------------------------------------------------

Inventor 2012

Windows 7 64-Bit SP1

Intel(R) Xeon(R) CPU X5570 @ 2.93GHz

NVIDIA Quadro FX 3800 (Avail. Graphics Memory 4067MB - Ded. 1024 MB)

12 GB RAM
Message 4 of 5

Many apologies! After a closer read of your initial post you said macro, not iLogic!!!

 

I've created the macro and guess what....

 

It worked perfectly!! 

 

Cheers mate!

---------------------------------------------------------------------------

Inventor 2012

Windows 7 64-Bit SP1

Intel(R) Xeon(R) CPU X5570 @ 2.93GHz

NVIDIA Quadro FX 3800 (Avail. Graphics Memory 4067MB - Ded. 1024 MB)

12 GB RAM
Message 5 of 5
jdkriek
in reply to: Anonymous

Note: this thread was started on 09-22-2006 so responces from the orginal poster may be slow 😉

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


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

Post to forums  

Autodesk Design & Make Report