Welcome to the newest blog entry in the "Planning for Automation Success" series, where we plunge into the realm of assembly design using Autodesk Inventor, specifically version 2024. In this blog, we'll explore the intricate world of WorkPlanes, the often unsung heroes responsible for assembly positioning and constraining. Yet, their significance extends beyond mere placement – we'll uncover how they drive extrusion positioning, laying the groundwork for efficient and precise design workflows.
As we embark on this journey, we'll highlight the importance of naming conventions and parameter alignment, showcasing how these seemingly small details can revolutionize automation and bolster design control. Follow along as we navigate assembly workflows, revealing hidden potentials and optimizing your design processes for peak efficiency.
Before we commence, feel free to revisit the first installment of this blog series, "Planning for Automation Success in Autodesk Inventor - Parts Edition". This initial post lays the groundwork for our exploration into assembly automation practices, through enhancing part automation, ensuring you're well-prepared for the exciting journey ahead.
Let's dive in!
WorkPlanes
In assembly work, WorkPlanes serve the crucial role of positioning and constraining components. However, in this particular assembly, we'll explore an additional function: using WorkPlanes for extrusion positioning, which we'll explore later in this blog post. Consistency in naming is key, especially between the assembly and part levels, for WorkPlanes that share the same purpose. Take note of the naming conventions employed in the assembly, such as "PLANE IN" and "PLANE OUT," which align with those discussed in the previous blog post on part automation. Maintaining this consistency streamlines the process of constraining components at a glance and lays the groundwork for implementing code-based constraints in the future.
Upgrade Part Template
A subtle enhancement to the part template is needed to unlock a powerful capability: the ability to generate a new part file from the template post-configuration. This upgrade involves the integration of a new internal rule within the part, complemented by refinements to the iLogic form. These adjustments pave the way for streamlined asset creation, setting the stage for upcoming sections.
Create Asset Files For Assembly
With the enhanced part template file, we're gearing up to create multiple assets for our assembly. Specifically, we'll be generating three assets: ATQ-36-60-B, ATQ-36-60-N, and ATQ-36-120-N. What's interesting is that the naming convention for these files is derived from the "MODEL" iProperty of the part itself. Given that this was the sole distinguishing factor within the part, the filename is dictated by the "MODEL" iProperty.
Parameters
In our assembly workflows, parameters are pivotal in steering WorkPlanes. They serve to guide component movement, dictate extrusion cuts, and establish the assembly's positioning relative to the floor. Ensuring clarity and consistency is paramount, thus aligning parameter names with corresponding iProperties is crucial. Take, for instance, the parameter "GATE_LOCATION," which mirrors the future iProperty "GATE LOCATION." By harmonizing these names, we establish a standardized naming convention, enhancing the assembly's overall presentation and simplifying its organization, leading to a cleaner and more efficient workspace.
The underscore in the parameter's name holds significance when exposing it as an iProperty in a different format using code. For instance, you might have an iProperty named "GATE LOCATION," but wish to expose a parameter named "GATE_LOCATION" as an iProperty. This capability to expose parameters as iProperties proves invaluable for descriptions and other metadata processes. Having this option available when necessary is pivotal for maximizing flexibility and efficiency in design processes.
WorkPlanes and Parameters
Implementing parameters to drive WorkPlanes introduces a straightforward automation method for locating components within our assembly. We'll leverage multiple parameters to seamlessly automate the positioning of WorkPlanes, enhancing efficiency and precision throughout the process. Once constrained these components will move when the iProperties drive the parameters.
Asset Placement
After utilizing the part template tool to configure our assets, the subsequent step is to position them within the assembly. At this stage, we'll simply place them randomly in the assembly without any constraints. It's worth noting that one asset will be placed in the assembly multiple times, serving a distinct purpose that we'll explore in the sections ahead.
Constraining
Each asset will be constrained fully, to ensuring precise alignment within the assembly. The majority of these constraints will involve linking a part WorkPlane to an assembly WorkPlane. Notably, certain WorkPlanes are dynamically driven by parameters, facilitating automated adjustments upon completion. In this segment, constraints will be applied to only three of the four components, with the final one slated for constraining in subsequent sections. It's evident that most constraints align planes with similar names, such as "PLANE CTR" from the assembly to "PLANE CTR" on the part, fostering consistency throughout the process. While manual constraining is our current approach, the standardized naming convention enables seamless automation, promising not only feasibility but also efficiency in future automation endeavors.
Additional WorkPlanes
As we advance through the constraining process, additional WorkPlanes become necessary. In this scenario, we're introducing two new WorkPlanes, although not at the assembly level, but rather at the part level. For example, we're creating a WorkPlane derived from the gate WorkPlane "PLANE OUT." Once this WorkPlane is established at the assembly level, it will automatically align with the "PLANE OUT" of the part and move accordingly with the gate part. This approach streamlines the process by eliminating the need for an additional parameter. Moreover, since all asset parts follow the same creation method, substituting the gate part with a different model won't disrupt the constraints. This consistency in WorkPlanes and naming conventions ensures continuity throughout the automation process.
Third Component Constraints
With all the WorkPlanes now properly positioned, it's time to apply constraints to the third component. Here, we'll be linking its "PLANE IN" to the freshly introduced "PLANE GATE OUT," which originates from the "PLANE OUT" of the gate component. This clever approach ensures that regardless of any changes made to the gate, this component will consistently remain constrained to its end. By adopting this method, we minimize the necessity for a parameter to regulate the position of this particular component.
Cleaning Up Model Tree
Choosing descriptive component names in the tree, rather than relying solely on part numbers, can greatly enhance the potential for automation. For instance, if a component is labeled with a specific part number, but there's a need to accommodate variations in width or model, searching for a fitting part number within the model tree can be cumbersome. Opting for generic yet descriptive component names facilitates flexibility and ensures ease of locating components, particularly when transitioning to programming tasks.
Create Patterns
In this assembly, we'll implement two distinct patterns, each serving its specific purpose. It's worth noting that these patterns may intersect with other components initially. However, as we progress through subsequent sections, we'll refine the model geometry to ensure there's no interference with other components. For now, though, we'll maintain the current configuration.
Create Assembly Sketches
In this assembly, we're about to create two sketches situated on distinct WorkPlanes. These sketches play a vital role in enabling the assembly extrusion cuts scheduled for upcoming sections. To ensure meticulous preparation, we'll design these sketches with generous dimensions, providing flexibility for substantial material removal, if necessary. In both sketches, we'll utilize the two-point center rectangle tool and constrain it to the origin for precise alignment.
Create Assembly Extrusion Cuts
Extrusion cuts within an assembly serve various purposes, but for this demonstration, we'll focus on using them to remove excess material. In our business model, we adhere to the logic of supplying full-length beds, specifically 120" beds for this instance, as it streamlines manufacturing processes and minimizes on-site cutting requirements. This approach is common when working with materials that only come in a 20ft stick , where we aim to utilize the entire length efficiently. Embracing the practice of strategic material removal is invaluable, offering flexibility for future needs.
Once the cuts are executed, they'll consume all material within their path. However, not all collected material is necessary for our assembly. Hence, a process to eliminate surplus components called "Remove Participant" becomes essential. We'll retain only the last pattern element in both patterns, ensuring that each cut contains only one element for now. This meticulous step guarantees optimal efficiency in our assembly process.
Add Default Participants to Assembly Cuts
Utilizing default participants is a prudent practice, particularly when employing patterns. My usual approach involves including the first element in the pattern as a participant. This ensures that the extrusions consistently have a participant in the cut, safeguarding against the risk of the cut being removed. In various versions of Inventor, if the participants decrease to zero, the cut is eliminated. Thus, the principle is to preemptively prevent such occurrences by always including a participant in the cut, even if it doesn't remove any material. In forthcoming sections, we'll explore code modifications to manage the dynamic nature of patterns, adjusting participants to accommodate pattern growth or reduction effectively.
Cleanup as you go
We're progressing with our model tree cleanup, focusing on refining both patterns and extrusions. Practicing this cleanup routine is invaluable throughout our workflow. Standardizing the naming conventions for patterns plays a crucial role in enhancing code clarity and cleanliness within the assembly environment. Using generic names for patterns or extrusions can muddy the waters when examining the code associated with your assembly, making it challenging to discern their purpose. In this demonstration, we'll adopt a prefix convention, employing "EXT" for extrusions and "PAT" for patterns followed by a descriptive purpose. While the choice of prefix may vary, consistency is key throughout your automation journey. Adhering to these standards and maintaining consistency not only streamlines individual tasks but also fosters cohesion within the entire team.
Parameters for Patterns
In the realm of design, it's common to encounter scenarios where creating parameters to control patterns becomes essential. This necessity arises particularly when you're dealing with variables like length, which directly influence the pattern's configuration. Take, for example, this situation we're altering the "OAL" (Overall Length) and "GATE LOCATION" affects multiple patterns simultaneously. To address this, we'll establish two parameters for each pattern: one to regulate offset and another to manage quantity.
iProperties
When it comes to iProperties, our objective is to establish several distinct ones that will ultimately govern parameters and additional features within the assembly. In this instance, our focus is solely on creating and defining initial values. These iProperties will serve as the foundation for driving an iLogic form and subsequent code in later sections.
External Rule
In this instance, we'll demonstrate how to employ an external rule for managing assembly control. Initially, we'll focus on its creation and integration into the existing directory structure. As we progress through subsequent sections, we'll be incorporating code to orchestrate assembly components and features. External rules offer distinct advantages over internal ones, particularly in collaborative development settings, as they can be modified externally to the Inventor model, streamlining workflow in multi-developer environments.
iLogic Form
The iLogic form serves as the central control mechanism for the assembly, chosen for its intuitive nature in driving the model. Leveraging a design setup where adjustments are streamlined through iProperties modification and execution of an external rule, automation can be achieved through various means. Options include employing VBA, developing a Visual Studio add-in to inject values into iProperties, and triggering external rule execution via buttons. This flexible process can be further expanded upon as requirements evolve.
iLogic Code:
Sub Main()
'*********************************************************************************
' DOCUMENT
'*********************************************************************************
Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim asmDef As AssemblyComponentDefinition = asmDoc.ComponentDefinition
'*********************************************************************************
' iProperties
'*********************************************************************************
Dim oal As String = ReturnPropertyValue(asmDoc, "OAL")
Dim gateLocation As String = ReturnPropertyValue(asmDoc, "GATE LOCATION")
Dim height As String = ReturnPropertyValue(asmDoc, "HEIGHT")
'*********************************************************************************
' PUSH iProperties INTO PARAMETERS
'*********************************************************************************
If oal <> "" Then Parameter.Param("OAL").Expression = LCase(oal)
If gateLocation <> "" Then Parameter.Param("GATE_LOCATION").Expression = LCase(gateLocation)
If height <> "" Then Parameter.Param("HEIGHT").Expression = LCase(height)
'*********************************************************************************
' CONVERT iProperties INTO FEET-INCH FORMAT
'*********************************************************************************
iProperties.Value("Custom", "OAL") = ConvertDecimaltoFeetInches(Parameter("OAL"))
iProperties.Value("Custom", "GATE LOCATION") = ConvertDecimaltoFeetInches(Parameter("GATE_LOCATION"))
iProperties.Value("Custom", "HEIGHT") = ConvertDecimaltoFeetInches(Parameter("HEIGHT"))
'*********************************************************************************
' UPDATE DOCUMENT TO MAKE PARTS IN ASSEMBLY IN CORRECT LOCATION PRIOR TO MEASURING
'*********************************************************************************
InventorVb.DocumentUpdate()
'*********************************************************************************
' TAKE MEASUREMENTS FOR DISTANCE BETWEEN PLANES TO ACCURATELY CALCULATE
' PATTERN QTY
'*********************************************************************************
Dim patternLength_IN As Double = Measure.MinimumDistance("PLANE IN", "PLANE GATE IN")
Dim patternLength_OUT As Double = Measure.MinimumDistance("PLANE GATE OUT", "PLANE OUT OFFSET")
'*********************************************************************************
' VALIDATE OAL OR RESET TO DEFAULT
'*********************************************************************************
Dim gateName As String = "GATE"
Dim gateOcc As ComponentOccurrence = Component.InventorComponent(gateName)
Dim gateDoc As PartDocument = gateOcc.Definition.Document
Dim gateLength As Double = Parameter(gateName, "LENGTH")
Dim compOutName As String = "COMP OUT"
Dim compOutOcc As ComponentOccurrence = Component.InventorComponent(compOutName)
Dim compOutDoc As PartDocument = compOutOcc.Definition.Document
Dim compOutLength As Double = Parameter(compOutName, "LENGTH")
Dim minOAL As Double = patternLength_IN + gateLength + compOutLength
If Parameter("OAL") < minOAL Then
MessageBox.Show("OAL is below the minimum length to accurately represent the design. Automatically changing to the default minimum length...", "Too Short!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Parameter.Param("OAL").Expression = CStr(minOAL)
iProperties.Value("Custom", "OAL") = ConvertDecimaltoFeetInches(minOAL)
'UPDATE DOCUMENT TO UP TO DATE OAL
InventorVb.DocumentUpdate()
'REMEASURE PLANES SINCE THEY HAVE CHANGED
patternLength_IN = Measure.MinimumDistance("PLANE IN", "PLANE GATE IN")
patternLength_OUT = Measure.MinimumDistance("PLANE GATE OUT", "PLANE OUT OFFSET")
End If
'*********************************************************************************
' PATTERN IN CALCULATIONS
'*********************************************************************************
Dim patternOffset_In As Double = Parameter("PAT_IN_OFFSET")
Dim patternQty_In As Double = Ceiling(patternLength_IN / patternOffset_In)
Dim patternVis_In As Boolean = False
Dim patternExp_In As String = "1"
If patternLength_IN > 0 Then
patternExp_In = CStr(patternQty_In)
patternVis_In = True
End If
Parameter.Param("PAT_IN_QTY").Expression = patternExp_In
MakePatternInvisible(asmDoc, "PAT IN", patternVis_In)
'*********************************************************************************
' PATTERN OUT CALCULATIONS
'*********************************************************************************
Dim patternOffset_Out As Double = Parameter("PAT_OUT_OFFSET")
Dim patternQty_Out As Double = Ceiling(patternLength_OUT / patternOffset_Out)
Dim patternVis_Out As Boolean = False
Dim patternExp_Out As String = "1"
If patternLength_OUT > 0 Then
patternExp_Out = CStr(patternQty_Out)
patternVis_Out = True
End If
Parameter.Param("PAT_OUT_QTY").Expression = patternExp_Out
MakePatternInvisible(asmDoc, "PAT OUT", patternVis_Out)
'*********************************************************************************
' UPDATE ASSEMBLY SO THAT THE PATTERNS REFLECT THEIR CURRENT STATE THIS WILL HELP
' WITH ADDING AND REMOVING PARTICIPANTS LATER IN THE CODE.
'*********************************************************************************
InventorVb.DocumentUpdate()
'*********************************************************************************
' ADJUSTING ASSEMBLY EXTRUSION CUTS - ADD OR REMOVE PARTICIPANTS AS NEEDED
' WHEN PARAMETERS SHRINK OR GROW PATTERNS
'*********************************************************************************
AdjustExtrusionParticipants(asmDoc, "EXT GATE", "PAT IN", "COMP IN")
AdjustExtrusionParticipants(asmDoc, "EXT OUT", "PAT OUT", "COMP GATE")
'*********************************************************************************
' SET INVISIBLE COMPONENTS TO REFERENCE
'*********************************************************************************
For Each invOcc As ComponentOccurrence In asmDoc.ComponentDefinition.Occurrences
If invOcc.Definition.Type <> kVirtualComponentDefinitionObject Then
If invOcc.Visible = False Or invOcc.Transparent = True Then
invOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
Else
invOcc.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
End If
End If
Next
iLogicVb.UpdateWhenDone = True
End Sub
Sub AdjustExtrusionParticipants(invDoc As AssemblyDocument, extName As String, patName As String, defaultName As String)
'*********************************************************************************
' THIS SUB ADDS THE LAST PARTICIPANT FROM A PATTERN TO AN ASSEMBLY EXTRUSION
' ALONG WITH REMOVING PARTICIPANTS THAT ARE NOT THE LAST PARTICIPANT AND ALSO
' NOT THE DEFAULT PARTICIPANT.
'*********************************************************************************
InventorVb.DocumentUpdate()
Dim asmDef As AssemblyComponentDefinition = invDoc.ComponentDefinition
Dim ext As ExtrudeFeature = Feature.InventorFeature(extName)
Dim pat As OccurrencePattern = asmDef.OccurrencePatterns.Item(patName)
Dim extOcc As ComponentOccurrence
Dim patElement As OccurrencePatternElement
Dim patOcc As ComponentOccurrence
Dim extOcc2 As ComponentOccurrence
Dim OccExists As Boolean
If ext IsNot Nothing And pat IsNot Nothing Then
For Each extOcc In ext.Participants
For Each patElement In pat.OccurrencePatternElements
For Each patOcc In patElement.Occurrences
If patOcc.Name <> defaultName Then
If patOcc.PatternElement.Index < pat.OccurrencePatternElements.Count Then
If patOcc Is extOcc Then
'MsgBox ("Removing- " & patOcc.Name & " To " & ext.Name , , "Managing Participants" )
ext.RemoveParticipant(patOcc)
End If
ElseIf patOcc.PatternElement.Index = pat.OccurrencePatternElements.Count Then
OccExists = False
'SKIP IF IT ALREADY EXISTS IN THE EXTRUSION
For Each extOcc2 In ext.Participants
If extOcc2.Name = patOcc.Name Then
OccExists = True
End If
Next
If OccExists = False Then
If patOcc IsNot extOcc Then
'MsgBox("Adding- " & patOcc.Name & " To " & ext.Name, , "Managing Participants")
ext.AddParticipant(patOcc)
End If
End If
End If
End If
Next
Next
Next
End If
End Sub
Public Sub MakePatternInvisible(invDoc As Document, patName As String, isVisible As Boolean)
'*********************************************************************************
' IN PREVIOUS VERSIONS OF INVENTOR WHEN YOU WOULD MAKE THE PATTERN INVISIBLE
' ALL THE OCCURRENCES WOULD STAY VISIBLE. THIS SUB SOLVES THAT PROBLEM.
'
' IT'S IMPORTANT TO MAKE THE PATTERN AND ALL OF IT'S OCCURRENCES INVISIBLE IF
' THEY ARE NOT BEING USED. IN THIS EXAMPLE WE WILL BE USING INVISIBLITY TO
' CONTROL BOM TYPE LATER ON IN THE MAIN SUB.
' WHEN A PATTERN'S COUNT IS LESS THAN ONE THEN THE PATTERN QTY WILL BE SET TO ONE
' AND THE PATTERN AND ALL OF IT'S OCCURRENCES WILL BE SET TO VISIBLE = FALSE.
'*********************************************************************************
Dim asmDef As AssemblyComponentDefinition = invDoc.ComponentDefinition
Dim pat As OccurrencePattern = asmDef.OccurrencePatterns.Item(patName)
Dim patElement As OccurrencePatternElement
Dim patOcc As ComponentOccurrence
If pat IsNot Nothing Then
pat.Visible = isVisible
For Each patElement In pat.OccurrencePatternElements
For Each patOcc In patElement.Occurrences
patOcc.Visible = isVisible
Next
Next
End If
End Sub
Function ReturnPropertyValue(invDoc As Document, invPropName As String) As String
'*********************************************************************************
' IN PREVIOUS VERSIONS OF INVENTOR THERE WERE ISSUES WHERE IF THE IPROPERTY DIDN'T
' EXIST AN ERROR WOULD RETURN. THIS FUNCTION SOLVES THAT PROBLEM.
' THIS FUNCTION WILL GO THROUGH ALL THE POSSIBLE IPROPERTY LOCATIONS AND TRY TO FIND
' THEM ALL. IF IT IS NOT FOUND AN EMPTY STRING WILL BE RETURNED.
'*********************************************************************************
If invDoc Is Nothing Then Exit Function
Dim invSumProperties As PropertySet = invDoc.PropertySets.Item("Inventor Summary Information")
Dim invDTProperties As PropertySet = invDoc.PropertySets.Item("Design Tracking Properties")
Dim invDSIProperties As PropertySet = invDoc.PropertySets.Item("Inventor Document Summary Information")
Dim invCustomPropertySet As PropertySet = invDoc.PropertySets.Item("Inventor User Defined Properties")
Dim invProp As Inventor.Property
For Each invProp In invSumProperties
If invProp.Name = invPropName Then
Return invProp.Value
End If
Next
For Each invProp In invDTProperties
If invProp.Name = invPropName Then
Return invProp.Value
End If
Next
For Each invProp In invDSIProperties
If invProp.Name = invPropName Then
Return invProp.Value
End If
Next
For Each invProp In invCustomPropertySet
If invProp.Name = invPropName Then
Return invProp.Value
End If
Next
Return ""
End Function
Function ConvertDecimaltoFeetInches(value As Double) As String
'*********************************************************************************
' THIS FUNCTION FORMATS THE INPUT VALUE INTO FEED AND INCHES. EVALUATING IT IF
' THE VALUE IS GREATER THAN 0.
'*********************************************************************************
Dim feet As Integer
Dim inches As Double
Dim roundedInches As Double
Dim result As String
If value > 0 Then
feet = value \ 12
inches = value Mod 12
roundedInches = Math.Round(inches * / 8
If roundedInches >= 12 Then
feet += 1
roundedInches -= 12
End If
result = feet & "'-" & roundedInches & """"
Return result
End If
End Function
Code Clarity
Within the code, there are specific sections that warrant further elaboration beyond the comments provided.
1. Validation and Error Handling
These are crucial aspects addressed in this code example. One potential scenario is where the Overall Length (OAL) falls short of the Gate Location requirement. In response, it becomes imperative to implement thorough checks, default fallback mechanisms, and user alerts during the design phase. Alerting users about configuration issues is a standard practice, ensuring that any deviations from specifications are promptly addressed. It is paramount to revert to default values, whether they represent minimum thresholds or adhere to company standards, to prevent configuration failures. Maintaining configurations in a state of failure is unacceptable, emphasizing the importance of robust error handling procedures.
Example:
'*********************************************************************************
' VALIDATE OAL OR RESET TO DEFAULT
'*********************************************************************************
Dim gateName As String = "GATE"
Dim gateOcc As ComponentOccurrence = Component.InventorComponent(gateName)
Dim gateDoc As PartDocument = gateOcc.Definition.Document
Dim gateLength As Double = Parameter(gateName, "LENGTH")
Dim compOutName As String = "COMP OUT"
Dim compOutOcc As ComponentOccurrence = Component.InventorComponent(compOutName)
Dim compOutDoc As PartDocument = compOutOcc.Definition.Document
Dim compOutLength As Double = Parameter(compOutName, "LENGTH")
Dim minOAL As Double = patternLength_IN + gateLength + compOutLength
If Parameter("OAL") < minOAL Then
MessageBox.Show("OAL is below the minimum length to accurately represent the design. Automatically changing to the default minimum length...", "Too Short!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Parameter.Param("OAL").Expression = CStr(minOAL)
iProperties.Value("Custom", "OAL") = ConvertDecimaltoFeetInches(minOAL)
'UPDATE DOCUMENT TO UP TO DATE OAL
asmDoc.Update2
'REMEASURE PLANES SINCE THEY HAVE CHANGED
patternLength_IN = Measure.MinimumDistance("PLANE IN", "PLANE GATE IN")
patternLength_OUT = Measure.MinimumDistance("PLANE GATE OUT", "PLANE OUT OFFSET")
End If
2. Converting Inputs
In the scenario presented, there exist multiple ways for users to input values, ranging from variations like 45ft to 45' to 540". However, it's crucial to convert these diverse inputs into a uniform format, such as 45'-0" for consistency.
Often, dropdown menus for length inputs adhere to specific standardizations, whether in one-foot or one-inch increments. However, our approach in this instance is to accommodate any input format, converting it into a foot-inch scheme. This not only standardizes the data but also familiarizes users with the preferred input format for future interactions.
Moreover, the system allows users to input formulas directly, seamlessly integrating them into the Overall Length (OAL) parameter expression. For instance, entering "45' + 16'" would calculate and display a resulting OAL of "61'-0"", streamlining the process of inputting complex expressions.
iProperties.Value("Custom", "OAL") = ConvertDecimaltoFeetInches(minOAL)
Function ConvertDecimaltoFeetInches(value As Double) As String
'*********************************************************************************
' THIS FUNCTION FORMATS THE INPUT VALUE INTO FEED AND INCHES. EVALUATING IT IF
' THE VALUE IS GREATER THAN 0.
'*********************************************************************************
Dim feet As Integer
Dim inches As Double
Dim roundedInches As Double
Dim result As String
If value > 0 Then
feet = value \ 12
inches = value Mod 12
roundedInches = Math.Round(inches * / 8
If roundedInches >= 12 Then
feet += 1
roundedInches -= 12
End If
result = feet & "'-" & roundedInches & """"
Return result
End If
End Function
3. Managing Participants in Extrusion Cuts: Ensuring Accuracy
The precision of extrusion cuts hinges on several factors, with one crucial aspect being the timing of document updates. Before taking measurements to ascertain pattern accuracy, it's imperative to ensure that document lengths are up-to-date. Failure to update these lengths can lead to inaccuracies in the measurements between WorkPlanes, consequently affecting the addition and removal of extrusion participants.
Determining the appropriate moments for document updates holds significant importance in the realm of designs. To illustrate this process, I've included a video example below. In the demonstration, I've incorporated message boxes within the loop, allowing viewers to observe the addition and removal of participants in the extrusion cut step by step. These message boxes serve as visual cues, highlighting each step of the extrusion cut process. Feel free to explore the example further by trying it out yourself!
AdjustExtrusionParticipants(asmDoc, "EXT GATE", "PAT IN", "COMP IN")
AdjustExtrusionParticipants(asmDoc, "EXT OUT", "PAT OUT", "COMP GATE")
Sub AdjustExtrusionParticipants(invDoc As AssemblyDocument, extName As String, patName As String, defaultName As String)
'*********************************************************************************
' THIS SUB ADDS THE LAST PARTICIPANT FROM A PATTERN TO AN ASSEMBLY EXTRUSION
' ALONG WITH REMOVING PARTICIPANTS THAT ARE NOT THE LAST PARTICIPANT AND ALSO
' NOT THE DEFAULT PARTICIPANT.
'*********************************************************************************
InventorVb.DocumentUpdate()
Dim asmDef As AssemblyComponentDefinition = invDoc.ComponentDefinition
Dim ext As ExtrudeFeature = Feature.InventorFeature(extName)
Dim pat As OccurrencePattern = asmDef.OccurrencePatterns.Item(patName)
Dim extOcc As ComponentOccurrence
Dim patElement As OccurrencePatternElement
Dim patOcc As ComponentOccurrence
Dim extOcc2 As ComponentOccurrence
Dim OccExists As Boolean
If ext IsNot Nothing And pat IsNot Nothing Then
For Each extOcc In ext.Participants
For Each patElement In pat.OccurrencePatternElements
For Each patOcc In patElement.Occurrences
If patOcc.Name <> defaultName Then
If patOcc.PatternElement.Index < pat.OccurrencePatternElements.Count Then
If patOcc Is extOcc Then
MsgBox ("Removing- " & patOcc.Name & " To " & ext.Name , , "Managing Participants" )
ext.RemoveParticipant(patOcc)
End If
ElseIf patOcc.PatternElement.Index = pat.OccurrencePatternElements.Count Then
OccExists = False
'SKIP IF IT ALREADY EXISTS IN THE EXTRUSION
For Each extOcc2 In ext.Participants
If extOcc2.Name = patOcc.Name Then
OccExists = True
End If
Next
If OccExists = False Then
If patOcc IsNot extOcc Then
MsgBox("Adding- " & patOcc.Name & " To " & ext.Name, , "Managing Participants")
ext.AddParticipant(patOcc)
End If
End If
End If
End If
Next
Next
Next
End If
End Sub
Code Summary:
-
Initialization: The subroutine begins by initializing necessary variables and obtaining relevant document properties.
-
Parameter Push: It sets assembly parameters based on retrieved iProperties, converting them into a consistent format.
-
Unit Conversion: Converts decimal values into a feet-inch format for consistency.
-
Document Update: Ensures the assembly document is up-to-date before taking measurements.
-
Measurement: Measures the distances between specific planes to accurately calculate pattern quantities.
-
Validation: Validates the Overall Length (OAL) parameter against minimum requirements and adjusts if necessary.
-
Pattern Calculations: Calculates pattern quantities based on given offsets and visibility conditions.
-
Extrusion Participant Adjustment: Manages the addition and removal of participants in extrusion cuts based on pattern changes.
-
Component Visibility Control: Controls the visibility of assembly components based on pattern visibility.
-
Utility Functions: Includes utility functions for property retrieval, unit conversion, and participant adjustment.
Conclusion
In conclusion, the integration of WorkPlanes, parameters, and naming conventions within the assembly environment lays a solid foundation for efficient automation and precise control of components. By leveraging consistent naming conventions and strategic parameterization, we've streamlined the process of constraining components and driving WorkPlanes. The enhancement of the part template file and the implementation of descriptive component names further contribute to the clarity and organization of the assembly workspace.
As we progress through the assembly process, the utilization of patterns, extrusions, and parameters becomes increasingly important, offering flexibility and scalability. By standardizing naming conventions for patterns and extrusions, we ensure clarity and cleanliness within the assembly environment, facilitating easier code examination and modification. Additionally, the establishment of parameters to control patterns and the creation of iProperties to govern assembly features set the stage for further automation and customization.
Through the demonstration of external rule integration and the utilization of the iLogic form as a central control mechanism, we showcase the versatility of automation methods within the assembly environment. By adopting these practices, we not only enhance efficiency and precision but also pave the way for future developments in collaborative design and workflow optimization. Overall, the careful integration of WorkPlanes, parameters, naming conventions, and automation methods underscores the importance of thoughtful design practices in achieving seamless assembly workflows and fostering innovation.
GitHub Repo: All finished files and reference information can be found on GitHub here.
Webinar
On September 5th, I had the pleasure of hosting a webinar where I explored the same material covered in this blog. This session was part of the KETIV Virtual Academy (KVA), a platform dedicated to providing valuable resources and insights to professionals in the field. If you're looking to deepen your understanding or revisit the concepts discussed, I highly recommend watching the recording available on YouTube.
Webinar: https://youtu.be/Nh4Bh81hE3I?si=EmmyKw7vI74XqP86
Thank you for watching, and I hope both this blog and the webinar provide you with the tools and knowledge needed to succeed in your automation endeavors.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.