CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products [www.cadforum.cz]
CZ | EN | DE
Login or
registration
  Visitors: 18765

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")
    Return
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
Try
    prefixProperty = customPropertySet.Item(prefixPropertyName)
Catch
    ' 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
Next
'------- End Of iLogic ------

Submited by: M.Depta, thanks

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

See also:
Tip 13965:Total length of sweeps in Inventor - wires, pipes, trusses, tubes, hoses (iLogic)
Tip 13920:Saving your Inventor model in the presentation color scheme (iLogic).
Tip 13884:How to send e-mails with an iLogic macro?
Tip 13836:How to reset view numbering in Inventor?
Tip 13744:Simple password protection of Inventor documents (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   



Featuring:
Use Google Earth images in your AutoCAD projects with the Plex.Earth Tools 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.
TOPlist