CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products []
CZ | EN | DE
Login or
  Visitors: 3655

CAD tip CAD tip # 13211:

Question CAD 
 %  platform  category 
Q - question

Automatic numbering/renaming of multi-volume bodies in a part.

A - answer If you like to use multi-volume bodies as control models for assemblies, you can save yourself the trouble of naming the files when exporting to an assembly when you need to distinguish the bodies, e.g. number them. Manually overwriting names/numbers would be inconvenient. Use the following iLogic rule (macro) to automate such 'renaming by numbering'.

The solids will be named (renamed) according to the specified prefix followed by a numeric series.

'------- start of iLogic ------
'original idea: B.Han
'check that this active document is a part file   
Dim partDoc As PartDocument
If ThisApplication.ActiveDocument.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
    MessageBox.Show("Please open a Part document", "iLogic")
End If

'define the active document
partDoc = ThisApplication.ActiveDocument

'check for custom iProperty and add it if not found
Dim prefixPropertyName As String = "Prefix"
Dim customPropertySet = partDoc.PropertySets.Item("Inventor User Defined Properties")

Dim prefixProperty As Inventor.Property
    prefixProperty = customPropertySet.Item(prefixPropertyName)
    ' Assume error means not found
    prefixProperty = customPropertySet.Add("", prefixPropertyName)
End Try

'write the part number to the Prefix iProperty if it is empty
If String.IsNullOrEmpty(prefixProperty.Value.ToString()) Then
    prefixProperty.Value = iProperties.Value("Project", "Part Number") & "_"
End If

'get input from user
Dim bodyPrefix = InputBox("Enter a prefix for the solid body names", "iLogic", prefixProperty.Value.ToString())

'write input back to custom iProperty
prefixProperty.Value = bodyPrefix

'rename all solid bodies incrementing suffix
Dim i As Integer = 1
For Each solid As SurfaceBody In partDoc.ComponentDefinition.SurfaceBodies
    solid.Name = String.Format("{0}{1:00}", bodyPrefix, i)
    i += 1
'------- End Of iLogic ------

Submited by: M.Depta, thanks

100% *  CAD 
3.2.2022    711×  
Prices - CAD eShop:
applies to: Inventor ·

See also:
Tip 13040:iLogic - display information about complexity of an Inventor part.
Tip 12828:How to quickly delete 3rd party links to external objects in Inventor?
Tip 12644:How to identify parts and assemblies imported from STEP/IGES?
Tip 12520:How to set Inventor Display style and Lighting style from an iLogic macro?
Tip 12508:How to assign an expression (not value) to a user parameter with iLogic?

Back   All CAD Tips

Have we helped you? If you want to support the CAD Forum web service, consider buying one of our CAD applications, or our custom software development offerings, or donating via PayPal (see above). You may also add a link to your web - like this "fan" link: CAD Forum - tips, utilities, blocks for Autodesk products
CAD:    OS:    Categ: 
Text:  FAQ glossary   

Export 3D VRML scenes from AutoCAD and Inventor
VRMLout More info

Please use these tips at your own risk.
Arkance Systems is not responsible for possible problems that may occur as a result of using any of these tips.