Inventor Ilogic : Paper size Norm OR Custom

Inventor Ilogic : Paper size Norm OR Custom

tristan-haller
Collaborator Collaborator
1,289 Views
7 Replies
Message 1 of 8

Inventor Ilogic : Paper size Norm OR Custom

tristan-haller
Collaborator
Collaborator

FR:

 

Bonjour,

 

J'essaye de crée une Règle Ilogic permettant d'inscrire dans mes cartouches les formats de papier normé (ex : norme ISO A0, B2, C3 ...) lorsque la feuille les utilise, ou le format en mm Hauteur Largeur quand j'utilise un format Custom.
Résultat Voulut :
tristanhaller_1-1649776671721.pngtristanhaller_1-1649776671721.png  ou tristanhaller_0-1649776657800.pngtristanhaller_0-1649776657800.png

 

J'ai écrit la règle ci-dessous pour lister les format "normé" mais certaines valeurs ne fonctionnent pas.
Pouvez-vous m'aider à diagnostiquer le problème?

Pouvez-vous m'aider a améliorer ce code?


Merci d'avance.

 

 

Hello,

 

I am trying to create an Ilogic Rule to write in my title block the standard paper sizes (ex: ISO standard A0, B2, C3 ...) when the sheet uses them, or the size in mm Height Width when I use a Custom size.
Result Wanted :

tristanhaller_1-1649776671721.pngtristanhaller_1-1649776671721.png  OR  tristanhaller_0-1649776657800.pngtristanhaller_0-1649776657800.png

 

I wrote the rule below to list the "standard" formats but some values don't work.
Can you help me to diagnose the problem?

Can you help me to improve this code?

 

Thanks in advance.

 

Comportement correct / Proper behavior : 

tristanhaller_3-1649777144667.pngtristanhaller_3-1649777144667.png

 

Comportement incohérent / Inconsistent behaviour :

tristanhaller_2-1649777055322.pngtristanhaller_2-1649777055322.png

 

 

' création des 3 Propriétés Custom : 
iProperties.Value("Custom", "HtFeuille") = ""	' n'affiche rien si un format"Normé" est reconnu
iProperties.Value("Custom", "LargFeuille") = ""	' n'affiche rien si un format"Normé" est reconnu
iProperties.Value("Custom", "Format") = "\"		' Affiche \ si un format "Normé" N'EST PAS  reconnu

' Listes des Format "Normé" a recherché:

' Ax Portrait :
If ActiveSheet.Height = 37 And ActiveSheet.Width = 26 Then iProperties.Value("Custom","Format") = "A10"
If ActiveSheet.Height = 52 And ActiveSheet.Width = 37 Then iProperties.Value("Custom","Format") = "A9"
If ActiveSheet.Height = 74 And ActiveSheet.Width = 52 Then iProperties.Value("Custom","Format") = "A8"
If ActiveSheet.Height = 105 And ActiveSheet.Width = 74 Then iProperties.Value("Custom","Format") = "A7"
If ActiveSheet.Height = 148 And ActiveSheet.Width = 105 Then iProperties.Value("Custom","Format") = "A6"
If ActiveSheet.Height = 210 And ActiveSheet.Width = 148 Then iProperties.Value("Custom","Format") = "A5"
If ActiveSheet.Height = 297 And ActiveSheet.Width = 210 Then iProperties.Value("Custom","Format") = "A4"
If ActiveSheet.Height = 420 And ActiveSheet.Width = 297 Then iProperties.Value("Custom","Format") = "A3"
If ActiveSheet.Height = 594 And ActiveSheet.Width = 420 Then iProperties.Value("Custom","Format") = "A2"
If ActiveSheet.Height = 841 And ActiveSheet.Width = 594 Then iProperties.Value("Custom","Format") = "A1"
If ActiveSheet.Height = 1189 And ActiveSheet.Width = 841 Then iProperties.Value("Custom","Format") = "A0"

' Ax Paysage :
If ActiveSheet.Height = 26 And ActiveSheet.Width = 37 Then iProperties.Value("Custom","Format") = "A10"
If ActiveSheet.Height = 37 And ActiveSheet.Width = 52 Then iProperties.Value("Custom","Format") = "A9"
If ActiveSheet.Height = 52 And ActiveSheet.Width = 74 Then iProperties.Value("Custom","Format") = "A8"
If ActiveSheet.Height = 74 And ActiveSheet.Width = 105 Then iProperties.Value("Custom","Format") = "A7"
If ActiveSheet.Height = 105 And ActiveSheet.Width = 148 Then iProperties.Value("Custom","Format") = "A6"
If ActiveSheet.Height = 148 And ActiveSheet.Width = 210 Then iProperties.Value("Custom","Format") = "A5"
If ActiveSheet.Height = 210 And ActiveSheet.Width = 297 Then iProperties.Value("Custom","Format") = "A4"
If ActiveSheet.Height = 297 And ActiveSheet.Width = 420 Then iProperties.Value("Custom","Format") = "A3"
If ActiveSheet.Height = 420 And ActiveSheet.Width = 594 Then iProperties.Value("Custom","Format") = "A2"
If ActiveSheet.Height = 594 And ActiveSheet.Width = 841 Then iProperties.Value("Custom","Format") = "A1"
If ActiveSheet.Height = 841 And ActiveSheet.Width = 1189 Then iProperties.Value("Custom","Format") = "A0"

' Bx Portrait :
If ActiveSheet.Height = 44 And ActiveSheet.Width = 31 Then iProperties.Value("Custom","Format") = "B10"
If ActiveSheet.Height = 62 And ActiveSheet.Width = 44 Then iProperties.Value("Custom","Format") = "B9"
If ActiveSheet.Height = 88 And ActiveSheet.Width = 62 Then iProperties.Value("Custom","Format") = "B8"
If ActiveSheet.Height = 125 And ActiveSheet.Width = 88 Then iProperties.Value("Custom","Format") = "B7"
If ActiveSheet.Height = 176 And ActiveSheet.Width = 125 Then iProperties.Value("Custom","Format") = "B6"
If ActiveSheet.Height = 250 And ActiveSheet.Width = 176 Then iProperties.Value("Custom","Format") = "B5"
If ActiveSheet.Height = 353 And ActiveSheet.Width = 250 Then iProperties.Value("Custom","Format") = "B4"
If ActiveSheet.Height = 500 And ActiveSheet.Width = 353 Then iProperties.Value("Custom","Format") = "B3"
If ActiveSheet.Height = 707 And ActiveSheet.Width = 500 Then iProperties.Value("Custom","Format") = "B2"
If ActiveSheet.Height = 1000 And ActiveSheet.Width = 707 Then iProperties.Value("Custom","Format") = "B1"
If ActiveSheet.Height = 1414 And ActiveSheet.Width = 1000 Then iProperties.Value("Custom","Format") = "B0"

' Bx Paysage :
If ActiveSheet.Height = 31 And ActiveSheet.Width = 44 Then iProperties.Value("Custom","Format") = "B10"
If ActiveSheet.Height = 44 And ActiveSheet.Width = 62 Then iProperties.Value("Custom","Format") = "B9"
If ActiveSheet.Height = 62 And ActiveSheet.Width = 88 Then iProperties.Value("Custom","Format") = "B8"
If ActiveSheet.Height = 88 And ActiveSheet.Width = 125 Then iProperties.Value("Custom","Format") = "B7"
If ActiveSheet.Height = 125 And ActiveSheet.Width = 176 Then iProperties.Value("Custom","Format") = "B6"
If ActiveSheet.Height = 176 And ActiveSheet.Width = 250 Then iProperties.Value("Custom","Format") = "B5"
If ActiveSheet.Height = 250 And ActiveSheet.Width = 353 Then iProperties.Value("Custom","Format") = "B4"
If ActiveSheet.Height = 353 And ActiveSheet.Width = 500 Then iProperties.Value("Custom","Format") = "B3"
If ActiveSheet.Height = 500 And ActiveSheet.Width = 707 Then iProperties.Value("Custom","Format") = "B2"
If ActiveSheet.Height = 707 And ActiveSheet.Width = 1000 Then iProperties.Value("Custom","Format") = "B1"
If ActiveSheet.Height = 1000 And ActiveSheet.Width = 1414 Then iProperties.Value("Custom","Format") = "B0"

' Cx Portrait :
If ActiveSheet.Height = 40 And ActiveSheet.Width = 28 Then iProperties.Value("Custom","Format") = "C10"
If ActiveSheet.Height = 57 And ActiveSheet.Width = 40 Then iProperties.Value("Custom","Format") = "C9"
If ActiveSheet.Height = 81 And ActiveSheet.Width = 57 Then iProperties.Value("Custom","Format") = "C8"
If ActiveSheet.Height = 114 And ActiveSheet.Width = 81 Then iProperties.Value("Custom","Format") = "C7"
If ActiveSheet.Height = 162 And ActiveSheet.Width = 114 Then iProperties.Value("Custom","Format") = "C6"
If ActiveSheet.Height = 229 And ActiveSheet.Width = 162 Then iProperties.Value("Custom","Format") = "C5"
If ActiveSheet.Height = 324 And ActiveSheet.Width = 229 Then iProperties.Value("Custom","Format") = "C4"
If ActiveSheet.Height = 458 And ActiveSheet.Width = 324 Then iProperties.Value("Custom","Format") = "C3"
If ActiveSheet.Height = 648 And ActiveSheet.Width = 458 Then iProperties.Value("Custom","Format") = "C2"
If ActiveSheet.Height = 917 And ActiveSheet.Width = 648 Then iProperties.Value("Custom","Format") = "C1"
If ActiveSheet.Height = 1297 And ActiveSheet.Width = 917 Then iProperties.Value("Custom","Format") = "C0"

' Cx Paysage :
If ActiveSheet.Height = 28 And ActiveSheet.Width = 40 Then iProperties.Value("Custom","Format") = "C10"
If ActiveSheet.Height = 40 And ActiveSheet.Width = 57 Then iProperties.Value("Custom","Format") = "C9"
If ActiveSheet.Height = 57 And ActiveSheet.Width = 81 Then iProperties.Value("Custom","Format") = "C8"
If ActiveSheet.Height = 81 And ActiveSheet.Width = 114 Then iProperties.Value("Custom","Format") = "C7"
If ActiveSheet.Height = 114 And ActiveSheet.Width = 162 Then iProperties.Value("Custom","Format") = "C6"
If ActiveSheet.Height = 162 And ActiveSheet.Width = 229 Then iProperties.Value("Custom","Format") = "C5"
If ActiveSheet.Height = 229 And ActiveSheet.Width = 324 Then iProperties.Value("Custom","Format") = "C4"
If ActiveSheet.Height = 324 And ActiveSheet.Width = 458 Then iProperties.Value("Custom","Format") = "C3"
If ActiveSheet.Height = 458 And ActiveSheet.Width = 648 Then iProperties.Value("Custom","Format") = "C2"
If ActiveSheet.Height = 648 And ActiveSheet.Width = 917 Then iProperties.Value("Custom","Format") = "C1"
If ActiveSheet.Height = 917 And ActiveSheet.Width = 1297 Then iProperties.Value("Custom","Format") = "C0"

' Si aucun des formats "Normé" n'est reconnu :
If iProperties.Value("Custom", "Format") = "\" Then 			' Affiche \ au lieu du Format
iProperties.Value("Custom", "HtFeuille") = ActiveSheet.Height	' Affiche la valeur en mm 
iProperties.Value("Custom", "LargFeuille") = ActiveSheet.Width	' Affiche la valeur en mm 
End If

 

 

0 Likes
Accepted solutions (1)
1,290 Views
7 Replies
Replies (7)
Message 2 of 8

dalton98
Collaborator
Collaborator

This might help. Change all your "If_" to "Else If_". That way they are all in the same if statement

daltonparrish_0-1649778776958.pngdaltonparrish_0-1649778776958.png

 

 

0 Likes
Message 3 of 8

dalton98
Collaborator
Collaborator
' création des 3 Propriétés Custom : 
iProperties.Value("Custom", "HtFeuille") = ""	' n'affiche rien si un format"Normé" est reconnu
iProperties.Value("Custom", "LargFeuille") = ""	' n'affiche rien si un format"Normé" est reconnu
iProperties.Value("Custom", "Format") = "\"		' Affiche \ si un format "Normé" N'EST PAS  reconnu

' Listes des Format "Normé" a recherché:

' Ax Portrait :
If ActiveSheet.Height = 37 And ActiveSheet.Width = 26 Then 
	iProperties.Value("Custom", "Format") = "A10"
Else If ActiveSheet.Height = 52 And ActiveSheet.Width = 37 Then 
	iProperties.Value("Custom", "Format") = "A9"
Else If ActiveSheet.Height = 74 And ActiveSheet.Width = 52 Then 
	iProperties.Value("Custom", "Format") = "A8"
Else If ActiveSheet.Height = 105 And ActiveSheet.Width = 74 Then 
	iProperties.Value("Custom", "Format") = "A7"
Else If ActiveSheet.Height = 148 And ActiveSheet.Width = 105 Then 
	iProperties.Value("Custom", "Format") = "A6"
Else If ActiveSheet.Height = 210 And ActiveSheet.Width = 148 Then 
	iProperties.Value("Custom", "Format") = "A5"
Else If ActiveSheet.Height = 297 And ActiveSheet.Width = 210 Then 
	iProperties.Value("Custom", "Format") = "A4"
Else If ActiveSheet.Height = 420 And ActiveSheet.Width = 297 Then 
	iProperties.Value("Custom", "Format") = "A3"
Else If ActiveSheet.Height = 594 And ActiveSheet.Width = 420 Then 
	iProperties.Value("Custom", "Format") = "A2"
Else If ActiveSheet.Height = 841 And ActiveSheet.Width = 594 Then 
	iProperties.Value("Custom", "Format") = "A1"
Else If ActiveSheet.Height = 1189 And ActiveSheet.Width = 841 Then 
	iProperties.Value("Custom", "Format") = "A0"

' Ax Paysage :
Else If ActiveSheet.Height = 26 And ActiveSheet.Width = 37 Then 
	iProperties.Value("Custom", "Format") = "A10"
Else If ActiveSheet.Height = 37 And ActiveSheet.Width = 52 Then 
	iProperties.Value("Custom", "Format") = "A9"
Else If ActiveSheet.Height = 52 And ActiveSheet.Width = 74 Then 
	iProperties.Value("Custom", "Format") = "A8"
Else If ActiveSheet.Height = 74 And ActiveSheet.Width = 105 Then 
	iProperties.Value("Custom", "Format") = "A7"
Else If ActiveSheet.Height = 105 And ActiveSheet.Width = 148 Then 
	iProperties.Value("Custom", "Format") = "A6"
Else If ActiveSheet.Height = 148 And ActiveSheet.Width = 210 Then 
	iProperties.Value("Custom", "Format") = "A5"
Else If ActiveSheet.Height = 210 And ActiveSheet.Width = 297 Then 
	iProperties.Value("Custom", "Format") = "A4"
Else If ActiveSheet.Height = 297 And ActiveSheet.Width = 420 Then 
	iProperties.Value("Custom", "Format") = "A3"
Else If ActiveSheet.Height = 420 And ActiveSheet.Width = 594 Then 
	iProperties.Value("Custom", "Format") = "A2"
Else If ActiveSheet.Height = 594 And ActiveSheet.Width = 841 Then 
	iProperties.Value("Custom", "Format") = "A1"
Else If ActiveSheet.Height = 841 And ActiveSheet.Width = 1189 Then 
	iProperties.Value("Custom", "Format") = "A0"

' Bx Portrait :
Else If ActiveSheet.Height = 44 And ActiveSheet.Width = 31 Then 
	iProperties.Value("Custom", "Format") = "B10"
Else If ActiveSheet.Height = 62 And ActiveSheet.Width = 44 Then 
	iProperties.Value("Custom", "Format") = "B9"
Else If ActiveSheet.Height = 88 And ActiveSheet.Width = 62 Then 
	iProperties.Value("Custom", "Format") = "B8"
Else If ActiveSheet.Height = 125 And ActiveSheet.Width = 88 Then 
	iProperties.Value("Custom", "Format") = "B7"
Else If ActiveSheet.Height = 176 And ActiveSheet.Width = 125 Then 
	iProperties.Value("Custom", "Format") = "B6"
Else If ActiveSheet.Height = 250 And ActiveSheet.Width = 176 Then 
	iProperties.Value("Custom", "Format") = "B5"
Else If ActiveSheet.Height = 353 And ActiveSheet.Width = 250 Then 
	iProperties.Value("Custom", "Format") = "B4"
Else If ActiveSheet.Height = 500 And ActiveSheet.Width = 353 Then 
	iProperties.Value("Custom", "Format") = "B3"
Else If ActiveSheet.Height = 707 And ActiveSheet.Width = 500 Then 
	iProperties.Value("Custom", "Format") = "B2"
Else If ActiveSheet.Height = 1000 And ActiveSheet.Width = 707 Then 
	iProperties.Value("Custom", "Format") = "B1"
Else If ActiveSheet.Height = 1414 And ActiveSheet.Width = 1000 Then 
	iProperties.Value("Custom", "Format") = "B0"

' Bx Paysage :
Else If ActiveSheet.Height = 31 And ActiveSheet.Width = 44 Then 
	iProperties.Value("Custom", "Format") = "B10"
Else If ActiveSheet.Height = 44 And ActiveSheet.Width = 62 Then 
	iProperties.Value("Custom", "Format") = "B9"
Else If ActiveSheet.Height = 62 And ActiveSheet.Width = 88 Then 
	iProperties.Value("Custom", "Format") = "B8"
Else If ActiveSheet.Height = 88 And ActiveSheet.Width = 125 Then 
	iProperties.Value("Custom", "Format") = "B7"
Else If ActiveSheet.Height = 125 And ActiveSheet.Width = 176 Then 
	iProperties.Value("Custom", "Format") = "B6"
Else If ActiveSheet.Height = 176 And ActiveSheet.Width = 250 Then 
	iProperties.Value("Custom", "Format") = "B5"
Else If ActiveSheet.Height = 250 And ActiveSheet.Width = 353 Then 
	iProperties.Value("Custom", "Format") = "B4"
Else If ActiveSheet.Height = 353 And ActiveSheet.Width = 500 Then 
	iProperties.Value("Custom", "Format") = "B3"
Else If ActiveSheet.Height = 500 And ActiveSheet.Width = 707 Then 
	iProperties.Value("Custom", "Format") = "B2"
Else If ActiveSheet.Height = 707 And ActiveSheet.Width = 1000 Then 
	iProperties.Value("Custom", "Format") = "B1"
Else If ActiveSheet.Height = 1000 And ActiveSheet.Width = 1414 Then 
	iProperties.Value("Custom", "Format") = "B0"

' Cx Portrait :
Else If ActiveSheet.Height = 40 And ActiveSheet.Width = 28 Then 
	iProperties.Value("Custom", "Format") = "C10"
Else If ActiveSheet.Height = 57 And ActiveSheet.Width = 40 Then 
	iProperties.Value("Custom", "Format") = "C9"
Else If ActiveSheet.Height = 81 And ActiveSheet.Width = 57 Then 
	iProperties.Value("Custom", "Format") = "C8"
Else If ActiveSheet.Height = 114 And ActiveSheet.Width = 81 Then 
	iProperties.Value("Custom", "Format") = "C7"
Else If ActiveSheet.Height = 162 And ActiveSheet.Width = 114 Then 
	iProperties.Value("Custom", "Format") = "C6"
Else If ActiveSheet.Height = 229 And ActiveSheet.Width = 162 Then
	iProperties.Value("Custom", "Format") = "C5"
Else If ActiveSheet.Height = 324 And ActiveSheet.Width = 229 Then 
	iProperties.Value("Custom", "Format") = "C4"
Else If ActiveSheet.Height = 458 And ActiveSheet.Width = 324 Then 
	iProperties.Value("Custom", "Format") = "C3"
Else If ActiveSheet.Height = 648 And ActiveSheet.Width = 458 Then 
	iProperties.Value("Custom", "Format") = "C2"
Else If ActiveSheet.Height = 917 And ActiveSheet.Width = 648 Then 
	iProperties.Value("Custom", "Format") = "C1"
Else If ActiveSheet.Height = 1297 And ActiveSheet.Width = 917 Then 
	iProperties.Value("Custom", "Format") = "C0"

' Cx Paysage :
Else If ActiveSheet.Height = 28 And ActiveSheet.Width = 40 Then 
	iProperties.Value("Custom", "Format") = "C10"
Else If ActiveSheet.Height = 40 And ActiveSheet.Width = 57 Then 
	iProperties.Value("Custom", "Format") = "C9"
Else If ActiveSheet.Height = 57 And ActiveSheet.Width = 81 Then 
	iProperties.Value("Custom", "Format") = "C8"
Else If ActiveSheet.Height = 81 And ActiveSheet.Width = 114 Then 
	iProperties.Value("Custom", "Format") = "C7"
Else If ActiveSheet.Height = 114 And ActiveSheet.Width = 162 Then 
	iProperties.Value("Custom", "Format") = "C6"
Else If ActiveSheet.Height = 162 And ActiveSheet.Width = 229 Then 
	iProperties.Value("Custom", "Format") = "C5"
Else If ActiveSheet.Height = 229 And ActiveSheet.Width = 324 Then 
	iProperties.Value("Custom", "Format") = "C4"
Else If ActiveSheet.Height = 324 And ActiveSheet.Width = 458 Then 
	iProperties.Value("Custom", "Format") = "C3"
Else If ActiveSheet.Height = 458 And ActiveSheet.Width = 648 Then 
	iProperties.Value("Custom", "Format") = "C2"
Else If ActiveSheet.Height = 648 And ActiveSheet.Width = 917 Then 
	iProperties.Value("Custom", "Format") = "C1"
Else If ActiveSheet.Height = 917 And ActiveSheet.Width = 1297 Then 
	iProperties.Value("Custom", "Format") = "C0"
End If

' Si aucun des formats "Normé" n'est reconnu :
If iProperties.Value("Custom", "Format") = "\" Then 			' Affiche \ au lieu du Format
iProperties.Value("Custom", "HtFeuille") = ActiveSheet.Height	' Affiche la valeur en mm 
iProperties.Value("Custom", "LargFeuille") = ActiveSheet.Width	' Affiche la valeur en mm 
End If
0 Likes
Message 4 of 8

tristan-haller
Collaborator
Collaborator

Merci pour votre réponse,

 

Pas de différence chez moi. la règle proposée se comporte de la même manière.

 

Thank you for your answer,

 

No difference in my case. The proposed rule behaves in the same way.

0 Likes
Message 5 of 8

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @tristan-haller,

 

I think there were 2 issues.

 

1) There was a type mismatch or precision issue. So making sure the value you're testing against is an Integer type fixes this issue.

 

2) It's possible the document could be out of date after changing the size, so adding a document Update line at the beginning of the rule prevents the rule from looking at out of date information.

 

Note too that you can use the Min and Max functions to shorten your code so that you don't need a separate section for Portrait and Landscape drawings. See the simplified example below.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

InventorVb.DocumentUpdate() 'make sure the drawing is up to date

' création des 3 Propriétés Custom : 
iProperties.Value("Custom", "HtFeuille") = ""	' n'affiche rien si un format"Normé" est reconnu
iProperties.Value("Custom", "LargFeuille") = ""	' n'affiche rien si un format"Normé" est reconnu
iProperties.Value("Custom", "Format") = "\"		' Affiche \ si un format "Normé" N'EST PAS  reconnu

Dim oMin As Integer
Dim oMax As Integer
oMin = Min(ActiveSheet.Width, ActiveSheet.Height)
oMax = Max(ActiveSheet.Width, ActiveSheet.Height)

Dim oValue As String
If oMin = 210 And oMax = 297 Then oValue = "A4"
If oMin = 297 And oMax = 420 Then oValue = "A3"
If oMin = 420 And oMax = 594 Then oValue = "A2"
If oMin = 594 And oMax = 841 Then oValue = "A1"
If oMin = 841 And oMax = 1189 Then oValue = "A0"
	
If ActiveSheet.Size = "Custom" Then 
	oValue = "\"
	iProperties.Value("Custom", "HtFeuille") = ActiveSheet.Height	' Affiche la valeur en mm 
	iProperties.Value("Custom", "LargFeuille") = ActiveSheet.Width	' Affiche la valeur en mm 
End If

iProperties.Value("Custom", "Format") = oValue

InventorVb.DocumentUpdate()



 

 

Message 6 of 8

JelteDeJong
Mentor
Mentor

I think that @Curtis_Waguespack has a point with the precision problem of double values. But I would use the iLogic function "DoubleUtil.DoublesAreEqual(value1, value2)". Implicit casting doubles to integers is not always possible and may lead in some cases to unexpected results. (You can find more info on that topic in my blog post "Unexpected Results".)

The second problem that I did have is that the Inventor API uses Cm. The width and height you entered need to be converted. After writing a solution I found that you and @Curtis_Waguespack used the iLogic API that uses document units probably those are mm. (Therefore you don't have this problem, but I left it like this anyway so you know that there are also other solutions) 

For shorter and more readable code I would do the checks in a new function. Your rule could then look something like this.

Sub Main()
    Dim doc As DrawingDocument = ThisDoc.Document
    Dim sheet As Sheet = doc.ActiveSheet

    Dim size As String = ""
    If IsSizes(sheet, 26, 37) Then size = "A10"
    If IsSizes(sheet, 37, 52) Then size = "A9"
    If IsSizes(sheet, 52, 74) Then size = "A8"
    If IsSizes(sheet, 74, 105) Then size = "A7"
    If IsSizes(sheet, 105, 148) Then size = "A6"
    If IsSizes(sheet, 148, 210) Then size = "A5"
    If IsSizes(sheet, 210, 297) Then size = "A4"
    If IsSizes(sheet, 297, 420) Then size = "A3"
    If IsSizes(sheet, 420, 594) Then size = "A2"
    If IsSizes(sheet, 594, 841) Then size = "A1"
    If IsSizes(sheet, 841, 1189) Then size = "A0"

    If IsSizes(sheet, 31, 44) Then size = "B10"
    If IsSizes(sheet, 44, 62) Then size = "B9"
    If IsSizes(sheet, 62, 88) Then size = "B8"
    If IsSizes(sheet, 88, 125) Then size = "B7"
    If IsSizes(sheet, 125, 176) Then size = "B6"
    If IsSizes(sheet, 176, 250) Then size = "B5"
    If IsSizes(sheet, 250, 353) Then size = "B4"
    If IsSizes(sheet, 353, 500) Then size = "B3"
    If IsSizes(sheet, 500, 707) Then size = "B2"
    If IsSizes(sheet, 707, 1000) Then size = "B1"
    If IsSizes(sheet, 1000, 1414) Then size = "B0"

    If IsSizes(sheet, 28, 40) Then size = "C10"
    If IsSizes(sheet, 40, 57) Then size = "C9"
    If IsSizes(sheet, 57, 81) Then size = "C8"
    If IsSizes(sheet, 81, 114) Then size = "C7"
    If IsSizes(sheet, 114, 162) Then size = "C6"
    If IsSizes(sheet, 162, 229) Then size = "C5"
    If IsSizes(sheet, 229, 324) Then size = "C4"
    If IsSizes(sheet, 324, 458) Then size = "C3"
    If IsSizes(sheet, 458, 648) Then size = "C2"
    If IsSizes(sheet, 648, 917) Then size = "C1"
    If IsSizes(sheet, 917, 1297) Then size = "C0"

    If sheet.Size = DrawingSheetSizeEnum.kCustomDrawingSheetSize Then
        size = "\"
        iProperties.Value("Custom", "HtFeuille") = ActiveSheet.Height * 10
        iProperties.Value("Custom", "LargFeuille") = ActiveSheet.Width * 10
    End If

    iProperties.Value("Custom", "Format") = size
End Sub

Public Function IsSizes(sheet As Sheet, width As Double, height As Double) As Boolean

    Dim min As Double = Math.Min(sheet.Width, sheet.Height)
    Dim max As Double = Math.Max(sheet.Width, sheet.Height)

    Return (DoubleUtil.DoublesAreEqual(min, width) And
            DoubleUtil.DoublesAreEqual(max, height))
End Function

 

 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 7 of 8

tristan-haller
Collaborator
Collaborator

Bonjour @Curtis_Waguespack ,

 

Merci de votre réponse, j'ai pu revoir mon code et ajouter les Types nécessaire à mes variables.

 

Il marche parfaitement désormais.

 

Je ne comprend pas l'intérêt de la mise a jour du document... je ne l'ai donc pas ajouter 😅

 

 

Hello @Curtis_Waguespack ,

 

Thank you for your answer, I was able to review my code and add the necessary Types to my variables.

 

It works perfectly now.

 

I don't understand the point of updating the document... so I didn't add it 😅

 

 

Dim LargPapier, LongPapier As Integer
LargPapier = Min(ActiveSheet.Height , ActiveSheet.Width)
LongPapier = Max(ActiveSheet.Height , ActiveSheet.Width)
Dim Norme As String
Norme = "\"

' Listes des Format "Normé" a recherché:

' Ax :
If LargPapier = 26 And LongPapier = 37 Then Norme = "A10"
If LargPapier = 37 And LongPapier = 52 Then Norme = "A9"
If LargPapier = 52 And LongPapier = 74 Then Norme = "A8"
If LargPapier = 74 And LongPapier = 105 Then Norme = "A7"
If LargPapier = 105 And LongPapier = 148 Then Norme = "A6"
If LargPapier = 148 And LongPapier = 210 Then Norme = "A5"
If LargPapier = 210 And LongPapier = 297 Then Norme = "A4"
If LargPapier = 297 And LongPapier = 420 Then Norme = "A3"
If LargPapier = 420 And LongPapier = 594 Then Norme = "A2"
If LargPapier = 594 And LongPapier = 841 Then Norme = "A1"
If LargPapier = 841 And LongPapier = 1189 Then Norme = "A0"

' Bx :
If LargPapier = 31 And LongPapier = 44 Then Norme = "B10"
If LargPapier = 44 And LongPapier = 62 Then Norme = "B9"
If LargPapier = 62 And LongPapier = 88 Then Norme = "B8"
If LargPapier = 88 And LongPapier = 125 Then Norme = "B7"
If LargPapier = 125 And LongPapier = 176 Then Norme = "B6"
If LargPapier = 176 And LongPapier = 250 Then Norme = "B5"
If LargPapier = 250 And LongPapier = 353 Then Norme = "B4"
If LargPapier = 353 And LongPapier = 500 Then Norme = "B3"
If LargPapier = 500 And LongPapier = 707 Then Norme = "B2"
If LargPapier = 707 And LongPapier = 1000 Then Norme = "B1"
If LargPapier = 1000 And LongPapier = 1414 Then Norme = "B0"

' Cx :
If LargPapier = 28 And LongPapier = 40 Then Norme = "C10"
If LargPapier = 40 And LongPapier = 57 Then Norme = "C9"
If LargPapier = 57 And LongPapier = 81 Then Norme = "C8"
If LargPapier = 81 And LongPapier = 114 Then Norme = "C7"
If LargPapier = 114 And LongPapier = 162 Then Norme = "C6"
If LargPapier = 162 And LongPapier = 229 Then Norme = "C5"
If LargPapier = 229 And LongPapier = 324 Then Norme = "C4"
If LargPapier = 324 And LongPapier = 458 Then Norme = "C3"
If LargPapier = 458 And LongPapier = 648 Then Norme = "C2"
If LargPapier = 648 And LongPapier = 917 Then Norme = "C1"
If LargPapier = 917 And LongPapier = 1297 Then Norme = "C0"

If Norme = "\" Then 
	iProperties.Value("Custom", "HtFeuille") = ActiveSheet.Height	' Affiche la valeur en mm si un format"Normé" N'est PAS reconnu
	iProperties.Value("Custom", "LargFeuille") = ActiveSheet.Width	' Affiche la valeur en mm si un format"Normé" N'est PAS reconnu
Else
	iProperties.Value("Custom", "HtFeuille") = ""	' n'affiche rien si un format"Normé" est reconnu
	iProperties.Value("Custom", "LargFeuille") = ""	' n'affiche rien si un format"Normé" est reconnu
End If

iProperties.Value("Custom", "Format") = Norme ' Affiche \ ou la "Norme" reconu

 

 

Message 8 of 8

tristan-haller
Collaborator
Collaborator

Bonjour @JelteDeJong,

 

Votre code semble très complet, mais pour le moment je ne parviens pas à en comprendre tout le fonctionnement, je n'ai pas encore appris à crée des fonctions de "bas de page" et le fait de les appeler « avant » de les définir me perturbe.
Je vais devoir étudier encore un peu avant de pouvoir réutiliser ce que vous avez partagé.

Votre écriture s'approche beaucoup plus d'un tableau que la mienne, ce que je trouve plus esthétique.
Pourrait-on parcourir un "vrais" tableau de valeur pour lier les Hauteur Largeur recherchées avec la "string" de la norme de papier ?

 

 

Hello @JelteDeJong 

 

Your code seems very complete, but at the moment I can't figure out how it all works, I haven't learned how to create "footer" functions yet and calling them "before" defining them confuses me.
I'll have to study a bit more before I can reuse what you've shared.

Your writing is much closer to a table than mine, which I find more aesthetically pleasing.
Could we go through a "real" array of values to link the Widths searched with the paper Format "string"?

0 Likes