Need to get correct length of the part

Need to get correct length of the part

Anonymous
Not applicable
1,156 Views
8 Replies
Message 1 of 9

Need to get correct length of the part

Anonymous
Not applicable

I am looking for a way to change my cut length code. 

Sometimes the Max length is already in the material description 

example: a 2.00" x 3.00" Rectangular tube is cut at 1.25": The Max Length comes out as 3.00" when it should be 1.25"

 

I need to check if the Measure.ExtentsLength, Measure.ExtentsWidth, Measure.ExtentsHeight..... is already in the material description then use the one that is not in the description. 

 

The material description is stored in iProperties.Value("Project", "Stock Number")

 

Here is the code I am using, any help is greatly appreciated.

 

 

oDoc = ThisDoc.Document

Dim MyArrayList As New ArrayList

'get measurements
My_x = Measure.ExtentsLength
My_y = Measure.ExtentsWidth
My_z = Measure.ExtentsHeight

'Make longest value the Length, rounded to 4 places
MaxLength = Round(MaxOfMany(My_x, My_y, My_z), 4)

Dim propertyName1 As String = "CALCLength"

 'define custom prpoerty collection
oCustomPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")

 Try
'set property value
oProp = oCustomPropertySet.Item(propertyName1)
Catch
' Assume error means not found so create it
oCustomPropertySet.Add("", propertyName1)
End Try

 'set custom property value
iProperties.Value("Custom", "CALCLength") = MaxLength
0 Likes
Accepted solutions (1)
1,157 Views
8 Replies
Replies (8)
Message 2 of 9

bradeneuropeArthur
Mentor
Mentor
How is the materialdescription defined?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 9

Anonymous
Not applicable

Manually typed in. Working on changing that in the future

0 Likes
Message 4 of 9

bradeneuropeArthur
Mentor
Mentor
I don't understand this then:

"I need to check if the Measure.ExtentsLength, Measure.ExtentsWidth, Measure.ExtentsHeight..... is already in the material description then use the one that is not in the description. "

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 9

Anonymous
Not applicable

 a 2.00" x 3.00" Rectangular tube is cut at 1.25":

 

The Max Length comes out as 3.00" when it should be 1.25"

 

because the code uses the max of all extents 

0 Likes
Message 6 of 9

Anonymous
Not applicable

Here is an actual example

 

11 GA x 3.00 x 3.00 HRS TUBING

 

if I cut it at 2.00" 

 

run the ilogic code. the CALCLENGTH will be 3.00" when it needs to be 2.00"

0 Likes
Message 7 of 9

philip1009
Advisor
Advisor

I think this can be done with some string operations.

 

Get the Material name as a string with:

SyntaxEditor Code Snippet

Dim My_Material As String = ThisDoc.Document.ComponentDefinition.Material.Name

 

Or If the Material name is in the Stock Number then:

SyntaxEditor Code Snippet

Dim My_Material As String = iProperties.Value("Project", "Stock Number")

 

If your Material names are the same format, then you can use the Mid(My_Material,x,x) to check parts of the Material name for measurements, where the first x is the starting point of your string check, and the second x is the length to check.

 

For example, if your material is "Extrusion 1.500" X 2.000" then

 

If My_x <> Mid(My_Material, 10, 5) And My_x <> Mid(My_Material, 19, 5) Then

      Max_Length = My_x

'Do the same for other measurements with ElseIf statements.

 

For the first number in the Mid, the value is 10 since there are 10 characters, including spaces, before the cursor is in front of the "1.500", then the second value is 5 since there are 5 characters to check including periods.

 

Let me know if you need more info on string operations, they are in the snippets portion of the iLogic rule editing window.

 

Philip Martick
Inventor 2018 Pro, AutoCAD 2018, Autodesk Vault Basic 2018
Windows 10 Pro
2X Intel Xeon E5-2630 v4 @ 2.20GHz
16.00 GB of RAM
NVIDIA Quadro M2000

0 Likes
Message 8 of 9

omartin
Advocate
Advocate

I am assuming you have other code that will update the description after getting the max length.

Aafter you make the cut is the sketch showing from the original extrusion? maybe that is why the extent is still coming out as the original length.

Was my reply Helpful ? send a Kudos or accept as solution
0 Likes
Message 9 of 9

bradeneuropeArthur
Mentor
Mentor
Accepted solution
If dX > dY And dX > dZ Then
'MsgBox "x"
strLENGTH = dX
If dY > dZ Then
strWIDTH = dY
strTHICKNESS = dZ
Else
strWIDTH = dZ
strTHICKNESS = dY
End If
End If
Catch ex As Exception

End Try

If dY > dZ And dY > dX Then
'MsgBox "y"
strLENGTH = dY

If dZ > dX Then
strWIDTH = dZ
strTHICKNESS = dX
Else
strWIDTH = dX
strTHICKNESS = dZ
End If
End If

If dZ > dX And dZ > dY Then
'MsgBox "z"
strLENGTH = dZ
If dX > dY Then
strWIDTH = dX
strTHICKNESS = dY
Else
strWIDTH = dY
strTHICKNESS = dX
End If
End If

put these into properties and you have what you need

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes