000

Index Labels

Ilogic - Add Standard Virtual Parts From an Excel File

.
Issue:
You have a number of standard Virtual parts that you find yourself adding over and over. You'd like to have the ability to add them based on a predefined list.

You saw the post about adding these parts from a text file, but you'd like to be able to add standard iProperties for these virtual parts also. This way your Bill of Materials information for the virtual parts can be set when the virtual part is created. So you were wanting to read data from an XLS file that contains all of the information that you typically add for virtual parts.




Solution:
Here is an example iLogic rule that will read a *.xls file and present the contents to the user in an input box list. The user is then asked to enter a quantity for the virtual part, and then the virtual part occurrences are added to the assembly. If one or more occurrences of the virtual part exist in the assembly, the iLogic rule deletes them and just adds back the total number needed.

As the virtual parts are added, the iProperty information found in the *.xls file is added also. 
In this example the parts are placed by using the A column, which is the description. Then the other columns are read in and used to populate the virtual part's iProperties.

An example XLS file list with iProperty information.




Dim MyArrayList As New ArrayList
MyArrayList = GoExcel.CellValues("U:\iLogic examples\Virtual Part List.xls", "Sheet1", "A2", "A1000")
Dim sVirtPart As String
'get user input from list
sVirtPart = InputListBox("Select a virtual part to add.", _
MyArrayList, MyArrayList.Item(0), "iLogic", "Standard Virtual Parts")
'check for empty input in the case where the user cancels out of the input box
If sVirtPart = "" Then
Return 'end rule
Else
End if

'get iProperties from the XLS file
For MyRow = 2 To 1000 'index row 2 through 1000
                'find the cell in column A that matches the user selection
                 If sVirtPart = (GoExcel.CellValue("A" & MyRow)) Then
            'get the iProperty from the XLS file for each column
                oProp1 = GoExcel.CellValue("A" & MyRow )
            oProp2 = GoExcel.CellValue("B" & MyRow )
            oProp3 = GoExcel.CellValue("C" & MyRow)
            oProp4 = GoExcel.CellValue("D" & MyRow)
            oProp5 = GoExcel.CellValue("E" & MyRow)
            Exit For
            End If
Next

'get quantity from user
iQTY = InputBox("Enter the TOTAL number of:" _
& vblf & "        ''" & sVirtPart & "''" _
& vblf & "to place in the assembly." _
& vblf &  vblf & "Note: Enter 0 to delete all existing instances.", "iLogic", "1")
'check for empty input in the case where the user cancels out of the input box
If iQTY = "" Then
Return 'end rule
Else
End if

'define assembly
Dim asmDoc As AssemblyDocument
asmDoc = ThisApplication.ActiveDocument
'define assembly Component Definition
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all of the occurrences in the assembly
Dim asmOcc As ComponentOccurrence
For Each asmOcc  In oAsmCompDef.Occurrences
                'get name of occurence only (sees only everything left of the colon)
                Dim oOcc As Object
            oOcc = asmOcc.name.Split(":")(0)
            'look at only virtual components
                If TypeOf asmOcc.Definition Is VirtualComponentDefinition Then
                        'compare name selected from list to the
                                'existing virtual parts
                                If oOcc = sVirtPart Then
                        'delete existing virtual parts if name matches
                                asmOcc.delete
                                Else
                        End if
            Else
            End If
Next
 
Dim occs As ComponentOccurrences
occs = asmDoc.ComponentDefinition.Occurrences
 
Dim identity As Matrix
identity = ThisApplication.TransientGeometry.CreateMatrix

'create first instance of the virtual part
Dim virtOcc As ComponentOccurrence
if  iQTY >= 1 Then
virtOcc = occs.AddVirtual(sVirtPart, identity)
            Try
            iProperties.Value(sVirtPart & ":1", "Project", "Description") = oProp1
                Catch 'catch error when oProp1 = nothing
                End Try
            Try
            iProperties.Value(sVirtPart & ":1", "Project", "Part Number") = oProp2
                Catch 'catch error when oProp2 = nothing
                End Try
            Try
            iProperties.Value(sVirtPart & ":1", "Project", "Revision Number") = oProp3
                Catch 'catch error when oProp3 = nothing
                End Try
            Try
            iProperties.Value(sVirtPart & ":1", "Project", "Vendor") = oProp4
                Catch 'catch error when oProp4 = nothing
                End Try
            Try
            iProperties.Value(sVirtPart & ":1", "Summary", "Comments") = oProp5
                Catch 'catch error when oProp5 = nothing
                End Try
Else
Return
End if

'add next instance starting at instance2 (if applicable)
Dim index As Integer
index = 2
Do While index <= iQTY
occs.AddByComponentDefinition(virtOcc.Definition, identity)
index += 1
Loop


Blog Archive

Labels

2D Drafting 3D design 3D Modeling 3D models 3D Printing 3D rendering 3D scanning 3D Sketch Inventor 3D visualization 3D Web App 3ds Max ACC Additive Manufacturing AEC Technology affordable Autodesk tools AI Design AI in CAD AI in Manufacturing AI Tools AR architectural design architectural modeling architectural visualization Architecture architecture design Architecture Firm Architecture Productivity architecture software Artificial Intelligence As-Built Model augmented reality AutoCAD AutoCAD advice AutoCAD Basics AutoCAD Beginners AutoCAD Civil 3D 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 tools AutoCAD training. AutoCAD tricks AutoCAD Tutorial AutoCAD workflow AutoCAD Xref Autodesk Autodesk 2025 Autodesk 2026 Autodesk 3ds Max Autodesk AI Autodesk AI Tools Autodesk Alias Autodesk AutoCAD Autodesk BIM Autodesk BIM 360 Autodesk Certification Autodesk Cloud Autodesk Construction Cloud Autodesk Docs Autodesk Dynamo Autodesk features Autodesk Forge Autodesk FormIt Autodesk Fusion 360 Autodesk InfraWorks Autodesk Inventor Autodesk Inventor Frame Generator Autodesk Inventor iLogic Autodesk License Autodesk Navisworks Autodesk news Autodesk plugins Autodesk Recap Autodesk Revit Autodesk Software Autodesk Takeoff Autodesk Tips Autodesk training Autodesk update Autodesk Upgrade Autodesk Vault Autodesk Video Autodesk Viewer Automation Automation Tutorial automotive design automotive visualization Backup Basic Commands Basics Beginner Beginner Tips Big Data BIM BIM 360 BIM collaboration BIM Coordination BIM Data BIM for Infrastructure BIM Implementation BIM software BIM technology BIM tools BIM Trends BIM workflow Block Editor Building Maintenance Building Systems ByLayer CAD CAD API CAD Automation CAD commands CAD comparison CAD Data Management CAD Design CAD Evolution CAD File Size Reduction CAD Integration CAD line thickness CAD management CAD modeling CAD Optimization CAD plugins CAD Productivity CAD Security CAD Skills CAD software CAD software 2026 CAD software training CAD technology CAD Tips CAD workflow car design software Case Study CGI design Civil 3D civil engineering Clash Detection Class-A surfacing clean CAD file cleaning command client engagement Cloud CAD Cloud Collaboration Cloud design platform Cloud Engineering Cloud Management Cloud Storage Cloud-First collaboration command abbreviations concept car conceptual workflow construction Construction Analytics Construction BIM Construction Cloud Construction Technology contractor tools Contractor Workflow Contraints cost estimation Create resizable blocks CTB STB Cybersecurity Data Backup data management Data Protection Data Reference Data Security Data Shortcut Design Automation Design Collaboration Design Comparison design review Design Rules design software design software tips Design Technology Design Tools Design Workflow design-to-construction Designer Tools Digital Construction Technology Digital Design Digital engineering digital fabrication digital marketing digital takeoff Digital Twin Digital Twins digital workflow Drafting Standards Drawing Automation Dref Dynamic Block Dynamic Block AutoCAD Dynamic Blocks Dynamic doors Dynamic windows Dynamo automation early stage design eco design editing commands energy efficiency Engineering Engineering Automation engineering data Engineering Design Engineering Innovation Engineering Productivity engineering software Engineering Technology engineering tools Engineering Tools 2025 Engineering Workflow Excel Express Tools External Reference Facility Management Fast Structural Design File Recovery Forge Development Forge Viewer FreeCAD Fusion 360 Fusion 360 tutorial Future Skills Generative Design Geospatial Data GIS Global design teams green building Grips Handoff heavy CAD file Heavy CAD Files HVAC Design Tools HVAC Engineering Hydraulic Modeling iLogic Industry 4.0 infrastructure design Infrastructure Monitoring Infrastructure Planning Infrastructure Technology InfraWorks Insight interactive presentation Interior Design Inventor Inventor API Inventor Drawing Template Inventor Frame Generator Inventor Graphics Issues Inventor IDW Inventor Tips Keyboard Shortcuts Large Projects Laser Scan Learn AutoCAD Licensing Linked Models Machine Learning in CAD maintenance command Management Manufacturing Innovation Mapping Technology marketing visuals Mechanical Design Mechanical Engineering MEP Modeling Mesh-to-BIM Metal Structure Model Optimization Multi-User Environment Navisworks Best Practices ObjectARX .NET API Open Source CAD Organization OVERKILL OVERKILL AutoCAD Palette parametric design parametric family PDF PDM system Plot Style AutoCAD point cloud Post Construction Practice Drawing preconstruction workflow Predictive Maintenance Printing Quality Product Design Product Development product lifecycle product rendering Productivity productivity tools professional printing Professional Tips project management PTC Creo PURGE PURGE AutoCAD realistic rendering ReCap reduce CAD file size rendering engine rendering software Renovation Project Resizable Block Revit Revit add-ins Revit automation Revit Best Practices Revit integration Revit MEP Revit Performance Revit Scripting Revit skills Revit Tips Revit tutorial Revit Workflow Ribbon Scale Autodesk screen Secure Collaboration shortcut keys Shortcuts Siemens NX Simulation Sketch Small Firms Smart Block Smart City Smart Factory Smart Infrastructur Software Compliance Software Management Software Update SolidWorks Steel Structure Design Structural Optimization sustainability sustainable design Sustainable Manufacturing team training guide Technical Drawing time saving tools toolbar Troubleshooting Tutorial urban planning User Interface (UI) Vault Best Practices Vault Lifecycle Vault Mistakes vehicle modeling virtual reality visualization workflow VR VRED Water Infrastructure Water Management What’s New in Autodesk Workbook workflow Workflow Automation Workflow Optimization Worksets Worksharing Workspace XLS Xref