iLogic sheet parametrs without units

iLogic sheet parametrs without units

firelinsgs
Enthusiast Enthusiast
1,382 Views
8 Replies
Message 1 of 9

iLogic sheet parametrs without units

firelinsgs
Enthusiast
Enthusiast

Hello,

 

I just discovered Ilogic in Inventor. So im really begginer in this. Can someone help me with my problems? 

I have this code bellow. What i need is Dimensions without units "mm". Just number.  (See picture in att.)

 

Also looking for Ilogic solution how to fill numbers to "stock number" for Diffrents thickness.

For example : Thickness 2mm - Stock number 1044

                      Thickness 3mm - Stock number 8445

                      ...

 

Thanks,

Lukas.

 

SyntaxEditor Code Snippet

Dim oDoc As PartDocument
oDoc = ThisDoc.Document

Dim oSMDef As SheetMetalComponentDefinition
oSMDef = oDoc.ComponentDefinition

Dim oPart As partdocument
oPart = ThisApplication.activedocument
Dim oShtCompDef as SheetMetalComponentDefinition
oShtCompDef = oPart.ComponentDefinition

If oShtCompDef.HasFlatPattern = False Then
oShtCompDef.Unfold()
End If


iProperties.Value("Custom", "Length") = "=<Sheet Metal Length>"


iProperties.Value("Custom", "Width") = "=<Sheet Metal Width>"


iProperties.Value("Custom", "Description") = "=Sheet t.<Thickness> <Sheet Metal Length>x<Sheet Metal Width> "

Parameter.Param(docFName, "Thickness") .ExposedAsProperty = True
Dim smFormat As CustomPropertyFormat = Parameter.Param(docFName,"Thickness").CustomPropertyFormat
smFormat.ShowTrailingZeros = False
smFormat.ShowUnitsString = False

 

0 Likes
Accepted solutions (1)
1,383 Views
8 Replies
Replies (8)
Message 2 of 9

Owner2229
Advisor
Advisor

Here you go:

 

'Get the thickness parameter as a value
Dim oThick As Double = Parameter("Thickness").Value
'Check the value and set the iProperty's value If oThick = 2 Then iProperties.Value("Project", "Stock Number") = "1044" ElseIf oThick = 3 Then iProperties.Value("Project", "Stock Number") = "8445" End If
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 3 of 9

firelinsgs
Enthusiast
Enthusiast

Thanks a lot for this. Smiley Happy

 

Can you also help me with my first issue?  (dimension without units.)

 

 

0 Likes
Message 4 of 9

Owner2229
Advisor
Advisor

Well, you can read the parameters the same way as in the first part of my code:

 

Dim oLength As Double = Parameter("Length").Value
Dim oWidth As Double = Parameter("Width").Value

It only depends what do you want to do with them, eg. if you want to write the description:

 

Dim oThick As Double = Parameter("Thickness").Value
Dim oLength As Double = Parameter("Length").Value
Dim oWidth As Double = Parameter("Width").Value
iProperties.Value("Custom", "Description") = "=Sheet t." & oThick & " " & oLength & "x" & pWidth & " "

 

If you want the Description to be "linked" instead of a flat (static) value you can expose the parameters (as shown below) and use this instead:

iProperties.Value("Custom", "Description") = "=Sheet t.<Thickness> <Length>x<Width> "

 

If you want to expose the parameter as an iProperty without units (dunno why you would need that at this point), you actually have the code in the bottom of your code. Just replace the "Thickness" with "Length" and "Width":

 

Parameter.Param("Length").ExposedAsProperty = True
Dim smFormat As CustomPropertyFormat = Parameter.Param("Length").CustomPropertyFormat
smFormat.ShowTrailingZeros = False
smFormat.ShowUnitsString = False

Parameter.Param("Width").ExposedAsProperty = True
Dim smFormat As CustomPropertyFormat = Parameter.Param("Width").CustomPropertyFormat
smFormat.ShowTrailingZeros = False
smFormat.ShowUnitsString = False

 

PS. Why do you have iProperties' names in English when you're using Inventor in Czech? It might cause some issues if you'll use this code along with some other colleagues (or even different models on your PC) as they might have "Tloušťka" instead of "Thickness".

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 5 of 9

firelinsgs
Enthusiast
Enthusiast

Thanks for your reply.

 

I used "thickness" just for this forum...commonly use "Tloušťka".

 

Also i use filling the stuck number. Its work great, but! Can we add to this code also material? 

For example : Thickness 2mm /Material S235 - Stock number 1000

                      Thickness 2mm /Material DC01 - Stock number 9999

                      Thickness 3mm /Material S235 - Stock number 8445

                      Thickness 3mm /Material S355 - Stock number 8445

 

 

Just edited my rule. There is result. Smiley Wink

 

Výstřižek.PNG

 

Code:

Dim oDoc As PartDocument
oDoc = ThisDoc.Document

Dim oSMDef As SheetMetalComponentDefinition
oSMDef = oDoc.ComponentDefinition

Dim oPart As partdocument
oPart = ThisApplication.activedocument
Dim oShtCompDef as SheetMetalComponentDefinition
oShtCompDef = oPart.ComponentDefinition

If oShtCompDef.HasFlatPattern = False Then
oShtCompDef.Unfold()
End If

iProperties.Value("Custom", "Length")=Round(SheetMetal.FlatExtentsLength,1)
iProperties.Value("Custom", "Width")=Round(SheetMetal.FlatExtentsWidth,1)
iProperties.Value("Custom", "Description") = "=Sheet t.<Tloušťka> <Length>x<Width> "
iProperties.Value("Project", "Description") = "=Sheet t.<Tloušťka> <Length>x<Width> "
Parameter.Param(docFName, "Tloušťka") .ExposedAsProperty = True
Dim smFormat As CustomPropertyFormat = Parameter.Param(docFName,"Tloušťka").CustomPropertyFormat
smFormat.ShowTrailingZeros = False
smFormat.ShowUnitsString = False


'Get the thickness parameter as a value
Dim oThick As Double = Parameter("Tloušťka").Value
'Check the value and set the iProperty's value
If oThick = 2 Then
    iProperties.Value("Project", "Stock Number") = "131000006"
ElseIf oThick = 2.5 Then
    iProperties.Value("Project", "Stock Number") = "131000008"	
ElseIf oThick = 3  Then
	iProperties.Value("Project", "Stock Number") = "131000009"
ElseIf oThick = 4  Then
    iProperties.Value("Project", "Stock Number") = "131000011"
ElseIf oThick = 5  Then
    iProperties.Value("Project", "Stock Number") = "131000013"
ElseIf oThick = 6  Then
    iProperties.Value("Project", "Stock Number") = "131000016"	
ElseIf oThick = 7 Then
	iProperties.Value("Project", "Stock Number") = "131000018"
ElseIf oThick = 8  Then
    iProperties.Value("Project", "Stock Number") = "131000019"
ElseIf oThick = 9  Then
    iProperties.Value("Project", "Stock Number") = "131000020"
ElseIf oThick = 10 Then
	iProperties.Value("Project", "Stock Number") = "131000021"
ElseIf oThick = 12  Then
    iProperties.Value("Project", "Stock Number") = "131000022"
ElseIf oThick = 14 Then
	iProperties.Value("Project", "Stock Number") = "131000023"
ElseIf oThick = 15  Then
    iProperties.Value("Project", "Stock Number") = "131000024"
ElseIf oThick = 20  Then
    iProperties.Value("Project", "Stock Number") = "131000025"
End If
 

 

0 Likes
Message 6 of 9

Owner2229
Advisor
Advisor
Accepted solution

I've updated your code. It does exactly the same as your last one (unless you have some "unposted" code-lines), but on less code-lines.

 

Dim oPart As PartDocument = ThisApplication.ActiveDocument
Dim oSMDef As SheetMetalComponentDefinition = oPart.ComponentDefinition

If Not oSMDef.HasFlatPattern Then oShtCompDef.Unfold()

iProperties.Value("Custom", "Length")=Round(SheetMetal.FlatExtentsLength, 1)
iProperties.Value("Custom", "Width")=Round(SheetMetal.FlatExtentsWidth, 1)
iProperties.Value("Custom", "Description") = "=Sheet t.<Tloušťka> <Length>x<Width> "
iProperties.Value("Project", "Description") = "=Sheet t.<Tloušťka> <Length>x<Width> "
Parameter.Param("Tloušťka").ExposedAsProperty = True
Dim smFormat As CustomPropertyFormat = Parameter.Param("Tloušťka").CustomPropertyFormat
smFormat.ShowTrailingZeros = False
smFormat.ShowUnitsString = False

'Get the thickness parameter as a value
Dim oThick As Double = Parameter("Tloušťka").Value
'Check the value and set the iProperty's value
Select Case oThick
Case 2:   iProperties.Value("Project", "Stock Number") = "131000006"
Case 2.5: iProperties.Value("Project", "Stock Number") = "131000008"	
Case 3:   iProperties.Value("Project", "Stock Number") = "131000009"
Case 4:   iProperties.Value("Project", "Stock Number") = "131000011"
Case 5:   iProperties.Value("Project", "Stock Number") = "131000013"
Case 6:   iProperties.Value("Project", "Stock Number") = "131000016"	
Case 7:   iProperties.Value("Project", "Stock Number") = "131000018"
Case 8:   iProperties.Value("Project", "Stock Number") = "131000019"
Case 9:   iProperties.Value("Project", "Stock Number") = "131000020"
Case 10:  iProperties.Value("Project", "Stock Number") = "131000021"
Case 12:  iProperties.Value("Project", "Stock Number") = "131000022"
Case 14:  iProperties.Value("Project", "Stock Number") = "131000023"
Case 15:  iProperties.Value("Project", "Stock Number") = "131000024"
Case 20:  iProperties.Value("Project", "Stock Number") = "131000025"
End Select

 

Now, I'm not sure what you want to do with the material...

You want to set the "Stock Number" to a value based on both Thickness and Material?

E.g. something like this?

 

Dim oMat As String = iProperties.Value("Custom", "Material")
If Parameter("Thickness").Value = 2 Then
If oMat = "S235" Then iProperties.Value("Custom", "Stock Number") = "1000" End If End If
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 7 of 9

firelinsgs
Enthusiast
Enthusiast

I meant something like this.

 

 

Dim oMat As String = iProperties.Material
If Parameter("Tloušťka").Value = 10 Then
    If oMat = "S 235 JR" Then
        iProperties.Value("Project", "Stock Number") = "5555"
    ElseIf oMat = "DC01" Then 
        iProperties.Value("Project", "Stock Number") = "9999"
    End If
End If

 Can we use both conditions in "case" rule..?

0 Likes
Message 8 of 9

firelinsgs
Enthusiast
Enthusiast

The rule for filling "stock number" doesn't work for thickness 3. For other thicknesses rule works correctly.

Any ideas?

 

file included.

0 Likes
Message 9 of 9

Owner2229
Advisor
Advisor

Ok, so I've fixed the issue with 3 mm thickness, the forgotten "oSMDef.Unfold()" and I've added an example for the material (for thickness 10 mm):

Here's what was the issue: modthemachine/floating-point-numbers

 

Dim oPart As PartDocument = ThisApplication.ActiveDocument
Dim oSMDef As SheetMetalComponentDefinition = oPart.ComponentDefinition

If Not oSMDef.HasFlatPattern Then oSMDef.Unfold()

iProperties.Value("Custom", "Length")=Round(SheetMetal.FlatExtentsLength, 1)
iProperties.Value("Custom", "Width")=Round(SheetMetal.FlatExtentsWidth, 1)
iProperties.Value("Custom", "Description") = "=Sheet t.<Tloušťka> <Length>x<Width> "
iProperties.Value("Project", "Description") = "=Sheet t.<Tloušťka> <Length>x<Width> "
Parameter.Param("Tloušťka").ExposedAsProperty = True
Dim smFormat As CustomPropertyFormat = Parameter.Param("Tloušťka").CustomPropertyFormat
smFormat.ShowTrailingZeros = False
smFormat.ShowUnitsString = False

'Read the Material
Dim oMat As String = iProperties.Material
'Get the thickness parameter as a value
Dim oThick As Single = Round(Parameter("Tloušťka").Value, 3) 'Round to 3 decimal numbers
'Check the value and set the iProperty's value
Select Case oThick
Case 2:   iProperties.Value("Project", "Stock Number") = "131000006"
Case 2.5: iProperties.Value("Project", "Stock Number") = "131000008"	
Case 3:   iProperties.Value("Project", "Stock Number") = "131000009"
Case 4:   iProperties.Value("Project", "Stock Number") = "131000011"
Case 5:   iProperties.Value("Project", "Stock Number") = "131000013"
Case 6:   iProperties.Value("Project", "Stock Number") = "131000016"	
Case 7:   iProperties.Value("Project", "Stock Number") = "131000018"
Case 8:   iProperties.Value("Project", "Stock Number") = "131000019"
Case 9:   iProperties.Value("Project", "Stock Number") = "131000020"
Case 10:
    If oMat = "S 235 JR" Then
        iProperties.Value("Project", "Stock Number") = "5555"
    ElseIf oMat = "DC01" Then
        iProperties.Value("Project", "Stock Number") = "9999"
    End If
Case 12:  iProperties.Value("Project", "Stock Number") = "131000022"
Case 14:  iProperties.Value("Project", "Stock Number") = "131000023"
Case 15:  iProperties.Value("Project", "Stock Number") = "131000024"
Case 20:  iProperties.Value("Project", "Stock Number") = "131000025"
End Select

If you have more than 2 material options (or you simply want to use it instead), you can use "Select Case" again:

 

Select Case oThick
'...
Case 10:
    Select Case oMat
Case "S 235 JR": iProperties.Value("Project", "Stock Number") = "5555" Case "DC01": iProperties.Value("Project", "Stock Number") = "9999" End Select Case 12: iProperties.Value("Project", "Stock Number") = "131000022" '... End Select

 

Note: "Select Case" is a faster option for numeric selections, but it doesn't matter for text comparing (the speed is the same).

 

You cloud also shorten it to single line selects (to make the code look tidy and easy to read):

 

Dim oStock As String = vbNullString
Select Case oThick '... Case 10: If oMat = "S 235 JR" Then oStock = "5555" Else oStock = "9999" Case 12: oStock = "131000022" '... End Select
If oStock <> vbNullString Then iProperties.Value("Project", "Stock Number") = oStock 

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods