Help with try and catch, ilogic to update parts length when part is changed.

Help with try and catch, ilogic to update parts length when part is changed.

Anonymous
Not applicable
892 Views
2 Replies
Message 1 of 3

Help with try and catch, ilogic to update parts length when part is changed.

Anonymous
Not applicable

Hi,

 

I need help with this code..it works really well I just kinda combine what I found here on forum and with the great help of a lot of people esp. Curtis of course we all know who he is. 

 

The issue is when running it for the first time, its great but when I change the part shape or dimensions.  because of the try and catch function, it doesn't update my length ei ("B_L") parameters.  it keeps the existing.  my workaround it is to erase parameter but there must be something here for a fix.

 

and if I remove the try and catch well it creates a new "B_L1" parameter...but with the right length.

 

Thanks a bunch!

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 76787 StartFragment: 314 EndFragment: 76755 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

'MEASURES OVERALL X, Y, AND Z DIMENSIONS
X_MEASURE = Measure.ExtentsLength
Y_MEASURE = Measure.ExtentsWidth
Z_MEASURE = Measure.ExtentsHeight

'SORTS MEASURED DIMENSIONS TO FIND THE LENGTH, WIDTH AND HEIGHT OF PART
xdim = MaxOfMany(X_MEASURE,Y_MEASURE,Z_MEASURE)
ydim = MinOfMany(X_MEASURE,Y_MEASURE,Z_MEASURE)
zdim = (X_MEASURE + Y_MEASURE + Z_MEASURE) - xdim - ydim

'ROUNDS DIMENSIONS TO NEAREST 1/16"
dimx = Round(xdim*16 ul)*.0625
dimy = Round(ydim*16 ul)*.0625 
dimz = Round(zdim*16 ul)*.0625

InventorVb.DocumentUpdate()
iLogicVb.UpdateWhenDone = True


'ADDS A ZERO If DIMENSION DISPLAYS X.5'ADDS TWO ZEROS IF DIMENSION DISPLAYS X

If (Round(dimx,0)+1)-dimx = .5 Then
dmx = dimx & ""
ElseIf (Round(dimx,0)+1)-dimx = 1 Then
dmx = dimx & ""
Else dmx = dimx
End If
If (Round(dimy,0)+1)-dimy = .5 Then
dmy = dimy & "0"
ElseIf (Round(dimy,0)+1)-dimy = 1 Then
dmy = dimy & ""
Else dmy = dimy
End If
If (Round(dimz,0)+1)-dimz = .5 Then
dmz = dimz & ""
ElseIf (Round(dimz,0)+1)-dimz = 1 Then
dmz = dimz & ""
Else dmz = dimz
End If

'CREATES CUSTOM iPROPERTY FOR THE BOM
iProperties.Value("Custom", "B_L") = dmx
iProperties.Value("Custom", "B_W") = dmz
iProperties.Value("Custom", "B_T") = dmy
' Set up parameters


' Get the active document.  Assumes a part document is active.
Dim partDoc As PartDocument
partDoc = ThisDoc.Document
'partDoc = ThisApplication.ActiveDocument

'get filename
Filename = ThisDoc.FileName(False)

'get the drawing number
drawingnumber = Left(filename,8)
'get description name
description = Mid(filename,10, 40)

' Get the UserParameters collection
Dim userParams As UserParameters
userParams = partDoc.ComponentDefinition.Parameters.UserParameters

Try
    oTest = Parameter("B_L")
    Catch
    param = userParams.AddByExpression("B_L", dmx, UnitsTypeEnum.kInchLengthUnits)
    param = partDoc.ComponentDefinition.Parameters.Item("B_L") 
    param.ExposedAsProperty = True
    param.CustomPropertyFormat.Units = "in"
    param.CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kThreeDecimalPlacesPrecision
    param.CustomPropertyFormat.ShowTrailingZeros = False 
    param.CustomPropertyFormat.ShowUnitsString = False 
    param.CustomPropertyFormat.ShowUnitsString = False
End Try

Try
    oTest = Parameter("B_W")
    Catch
    param = userParams.AddByExpression("B_W", dmz, UnitsTypeEnum.kInchLengthUnits)
    param = partDoc.ComponentDefinition.Parameters.Item("B_W") 
    param.ExposedAsProperty = True
    param.CustomPropertyFormat.Units = "in"
    param.CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kThreeDecimalPlacesPrecision
    param.CustomPropertyFormat.ShowTrailingZeros = False 
    param.CustomPropertyFormat.ShowUnitsString = False 
    param.CustomPropertyFormat.ShowUnitsString = False
End Try
    
Try
    oTest = Parameter("B_T")
    Catch
    param = userParams.AddByExpression("B_T", dmy, UnitsTypeEnum.kInchLengthUnits)
    param = partDoc.ComponentDefinition.Parameters.Item("B_T") 
    param.ExposedAsProperty = True
    param.CustomPropertyFormat.Units = "in"
    param.CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
End Try
iLogicVb.UpdateWhenDone = True

'oB_TConverted = Parameter("B_T")

oBT = RoundToFraction(dmy, 1/32, RoundingMethod.Round)
fBT = oBT & """"

'select the case for B_T
Select Case dmy 
    Case 0.1196 
        oVNR = "445-0011"
    Case 0.1345 '10GA
        oVNR = "445-0010"
    Case 0.1875 
        oVNR = "445-0203"
    Case 0.25
        oVNR = "445-0204"
    Case 0.3125
        oVNR = "445-0205"
    Case 0.375 
        oVNR = "445-0206"
    Case .5
        oVNR = "445-0208"
    Case 0.625
        oVNR = "445-0210"
    Case 0.75 
        oVNR = "445-0212"
    Case 0.875
        oVNR = "445-0214"
    Case 1
        oVNR = "445-0216"        
    Case 1.125 
        oVNR = "445-0218"
    Case 1.25 
        oVNR = "445-0220"
    Case 1.375 
        oVNR = "445-0222"
    Case 1.5
        oVNR = "445-0224"
    Case 1.75 
        oVNR = "445-0228"
    Case 2
        oVNR = "445-0232"
    Case 2.125
        oVNR = "445-0234"
    Case 2.25
        oVNR = "445-0236"
    Case 2.375
        oVNR = "445-0238"
    Case 2.5
        oVNR = "445-0240"
    Case 2.75
        oVNR = "445-0244"    
    Case 3
        oVNR = "445-0248"
    Case 3.25
        oVNR = "445-0252"
    Case Else
    
        oVNR = "445-????"
End Select
']

'[ set iproperties
iProperties.Value("Custom", "Thickness") = fBT
'iProperties.Value("Project", "Stock Number") = drawingnumber
iProperties.Value("Project", "Vendor") = oVNR
'iProperties.Value("Project", "Description") = description
iProperties.Value("Project", "WEB Link") = "=PL, MS, HR, <Thickness>"
iProperties.Value("Project", "Cost Center") = "=<B_W> x <B_L>"

DNL = Mid(filename,9,4)

If DNL < 10 Then 
iProperties.Value("Summary", "Category") = Mid (filename, 12,1)

Else  
iProperties.Value("Summary", "Category") = Mid (filename, 11,2)
End If


'check part if its single part
Dim spart As String
spart = Mid(filename,9,2)

'If filename .contains("-") Then
If spart = "00" Then

iProperties.Value("Project", "Stock Number") = iProperties.Value("Project", "Vendor")
'iProperties.Value("Project", "Cost Center") = oPRJ
iProperties.Value("Project", "Description") = iProperties.Value("Project", "WEB Link")
'iProperties.Value("Summary", "Category") = DNL

Else

iProperties.Value("Project", "Stock Number") = drawingnumber
iProperties.Value("Project", "Description") = description

End If

If oVNR = "445-0011" Then 
iProperties.Value("Project", "WEB Link") = "=PL, MS, HR, #11 GA"
End If

If oVNR = "445-0010" Then 
iProperties.Value("Project", "WEB Link") = "=PL, MS, HR, #10 GA"
End If

odrawingname = ThisDoc.FileName(False)
opartname = Mid(odrawingname, 5,8) 
'iProperties.Value("Summary", "Category") = 
']

iLogicVb.UpdateWhenDone = True
']

 

 

0 Likes
Accepted solutions (1)
893 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

I added this before the try and catch for B_L and it seems to work..not sure if this is the best way to go about it but it works for now

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 1227 StartFragment: 314 EndFragment: 1195 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

param = partDoc.ComponentDefinition.Parameters.Item("B_L") 
param.Delete

 

0 Likes
Message 3 of 3

richard.joseph.pollak
Advocate
Advocate
Accepted solution

It looks like the problem is that you're only setting the value if it fails the 'Try'

Try it this way:

 

Try
    Parameter("B_L") = dmx
Catch
    param = userParams.AddByExpression("B_L", dmx, UnitsTypeEnum.kInchLengthUnits)
param.ExposedAsProperty = True
param.CustomPropertyFormat.Units = "in"
param.CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kThreeDecimalPlacesPrecision
param.CustomPropertyFormat.ShowTrailingZeros = False
param.CustomPropertyFormat.ShowUnitsString = False
param.CustomPropertyFormat.ShowUnitsString = False
   End Try

   I made a mistake when I first replied that I have edited.