000

Index Labels

Using iLogic to Trim a File Name to Populate iProperties

.
Issue:
You name your files with long file names consisting of a part number and some other information, and you’d like to extract that information from the file name to automatically populate the iProperties. For instance you have a file name made up of a part number and a revision number such as:
34-0987 Rev 2.ipt



Solution:
Combining the part number and revision number in the file name is actually the convention I use every day at the office. We employ a very structured part numbering/file naming system that allows us to keep an organized file system. Having the revision number in the file name removes all guess work involved with rolling component revision levels in assemblies. 

I use a simple iLogic rule in my files to extract the information from the file names and write it to the part number and revision number iProperties. The trick is using VB text string manipulation functions to strip off the information not needed.

For instance this line of code uses the VB Left function to count from the left of the string and keep only the first 7 characters for the iLogic ThisDoc.FileName(False) function:

iProperties.Value("Project", "Part Number") = (Left(ThisDoc.FileName(False),7))

The False option of the FileName function specifies the file name without the extension (34-0987 Rev 2.ipt becomes just 34-0987 Rev 2).
The VB Left function syntax is:  Left (string, length)

So this line returns: 34-0987 to the Part Number iProperty.

This next line returns the revision number by starting at the left of the file name and keeping only one character.

iProperties.Value("Project", "Revision Number") = (Right(ThisDoc.FileName(False),1))

The VB Right function syntax is:  Right (string, length)

So this line returns: 2 to the Revision Number iProperty. 
 
But what if some of our revision numbers vary in the number of characters? 
For instance: 34-0987 Rev 10 and/or 34-0987 Rev 0.3

In that case we’d use the Mid function such as this:
iProperties.Value("Project", "Revision Number") = (Mid(ThisDoc.FileName(False),13))

This line starts at the 13th character from the left and keeps everything from there on. 

So it returns: 
10 (where 34-0987 Rev 10 is the part number)
0.3 (where 34-0987 Rev 0.3 is the part number)
2 (where 34-0987 Rev 2 is the part number)

The VB Mid function syntax used here is:  Mid (string, start)

If we had a long file name such as 34-0987, 4x4 Steel Bracket, Rev 5.ipt we could use the Mid function to selectively write part of the file name to the Description iProperties by specifying not only the start but also the length of the text string to select. In this case starting at character 10 and  selecting the next 17 characters. 

iProperties.Value("Project", "Description") = (Mid(ThisDoc.FileName(False),10,17))

This returns: 4x4 Steel Bracket as the description. This illustrates the use of the Mid function with a Length, but of course to use that line effectively, your description would need to always remain the same number of characters. However, you might be able to use the Len function to get the character count of the string and create a function in the code to calculate the number of characters remaining once the file name and Rev number are subtracted, see the link below for more on the Len function and other VB String Manipulation tools.

The VB Mid function syntax for specifying the length also is:  Mid (string, start, length)
You can find more information on VB Text String Manipulation here:
http://msdn.microsoft.com/en-us/library/e3s99sd8%28v=vs.80%29.aspx

Thanks to Quinn for the subject of this topic.

Blog Archive

Labels

3D Modeling 3D Sketch Inventor AI Design AI in Manufacturing AI Tools Architecture Artificial Intelligence AutoCAD AutoCAD advice AutoCAD Basics AutoCAD Beginners AutoCAD Civil3D AutoCAD commands AutoCAD efficiency AutoCAD features AutoCAD File Management AutoCAD Layer AutoCAD learning AutoCAD print settings AutoCAD productivity AutoCAD Teaching AutoCAD Techniques AutoCAD tips AutoCAD training. AutoCAD tricks AutoCAD Tutorial AutoCAD workflow AutoCAD Xref Autodesk Autodesk 2025 Autodesk AI Tools Autodesk AutoCAD Autodesk Fusion 360 Autodesk Inventor Autodesk Inventor Frame Generator Autodesk Inventor iLogic Autodesk Recap Autodesk Revit Autodesk Software Autodesk Video Automation Automation Tutorial Basic Commands Basics Beginner Beginner Tips BIM BIM Implementation Block Editor ByLayer CAD comparison CAD Design CAD File Size Reduction CAD line thickness CAD Optimization CAD Productivity CAD software clean CAD file cleaning command Cloud Collaboration command abbreviations Construction Technology Contraints Create resizable blocks CTB STB Data Reference Data Shortcut design software Design Workflow Digital Design Digital Twin Drafting Standards Drawing Automation Dref Dynamic Block Dynamic Block AutoCAD Dynamic Blocks Dynamic doors Dynamic windows eco design editing commands energy efficiency Engineering Engineering Design Engineering Innovation Engineering Technology engineering tools Excel Express Tools External Reference Fast Structural Design Fusion 360 Generative Design green building Grips heavy CAD file Heavy CAD Files iLogic Industry 4.0 Insight Inventor API Inventor Drawing Template Inventor Frame Generator Inventor Graphics Issues Inventor IDW Inventor Tips Keyboard Shortcuts Learn AutoCAD Machine Learning in CAD maintenance command Management Manufacturing Innovation Metal Structure ObjectARX .NET API Organization OVERKILL OVERKILL AutoCAD Palette PDF Plot Style AutoCAD Practice Drawing Printing Quality professional printing Professional Tips PTC Creo PURGE PURGE AutoCAD ReCap reduce CAD file size Resizable Block Revit Revit Best Practices Revit Workflow Ribbon screen shortcut keys Shortcuts Siemens NX Sketch Small Firms Smart Block Smart Factory SolidWorks Steel Structure Design sustainability Sustainable Manufacturing toolbar Tutorial User Interface (UI) Workbook Workspace XLS Xref