Created
January 20, 2016 15:23
-
-
Save rbtr/3a0a316850a01958a664 to your computer and use it in GitHub Desktop.
Parametric resizing of assembly components (Inventor)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' This Sub must be in Module1 of the Assembly DocumentProject for the PartsRunner to find it | |
Sub SubPartsRunner(part As PartDocument, parent As AssemblyDocument) | |
Dim parentWidth As String | |
Dim parentHeight As String | |
parentWidth = "WIDTH" | |
parentHeight = "HEIGHT" | |
Dim userParams As UserParameters | |
Set userParams = part.ComponentDefinition.Parameters.UserParameters | |
Dim asmParams As UserParameters | |
Set asmParams = parent.ComponentDefinition.Parameters.UserParameters | |
Dim widthParam As Parameter | |
Set widthParam = asmParams.Item(parentWidth) | |
Dim heightParam As Parameter | |
Set heightParam = asmParams.Item(parentHeight) | |
Call copyParentParam(userParams, widthParam) | |
Call copyParentParam(userParams, heightParam) | |
End Sub | |
Sub copyParentParam(destSet As UserParameters, srcParam As Parameter) | |
Dim parentPrefix As String | |
parentPrefix = "PARENT_" | |
Dim paramName As String | |
paramName = parentPrefix + srcParam.Name | |
Dim destParam As Parameter | |
If doesParamExist(destSet, srcParam.Name) Then | |
Set destParam = destSet.Item(paramName) | |
destParam.Value = srcParam.Value | |
destParam.Units = srcParam.Units | |
Else | |
Set destParam = destSet.AddByValue(paramName, srcParam.Value, srcParam.Units) | |
End If | |
End Sub | |
Function doesParamExist(destSet As UserParameters, srcParam As String) As Boolean | |
doesParamExist = False | |
On Error Resume Next | |
Dim param As Parameter | |
Set Parameter = destSet.Item(srcParam) | |
doesParamExist = True | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment