Modify some properties of an ipt or iam / Modificar algunas propiedades de un ip

Modify some properties of an ipt or iam / Modificar algunas propiedades de un ip

Mecanico14
Advisor Advisor
1,237 Views
8 Replies
Message 1 of 9

Modify some properties of an ipt or iam / Modificar algunas propiedades de un ip

Mecanico14
Advisor
Advisor

Good.
With my little knowledge of iLogic and my bad English, I spent a few days unsuccessfully looking to build an iLogic rule to solve a simple process I want to do.
I have an ipt whose name is, for example, 345679-023-P-1258 (it will always be numeric and with the same length). I want to modify / add some of the properties, I want to extract the last 4 characters starting from the right (1258) and add them to the Stock Number property. In the Revision Number property, I will initially have the digits 00 and I want to add to the Part Number property, at the end a "-" and the value of the Revision Number property, so that I have the Part Number property (in this case ) as well: 345679-023-P-1258-00.
Can you help me with this little problem, or I ask too much ?, with the little (rather nothing) of iLogic, I am not even able to start creating the rule.


Many thanks in advance.

 

-----------------------------------------

Buenas.
Con mis pocos conocimientos de iLogic y mi mal inglés, llevo unos días buscando sin éxito cómo construir una regla de iLogic para solucionar un sencillo proceso que quiero hacer.
Tengo un ipt cuyo nombre es, por ejemplo, 345679-023-P-1258 (siempre será numérico y con la misma longitud). Quiero modificar/añadir algunas de las propiedades, quiero extraer los 4 últimos caracteres empezando por la derecha (1258) y añadirlos a la propiedad Stock Number. En la propiedad Revision Number, tendré en principio los dígitos 00 y quiero añadirle a la propiedad Part Number, al final un "-" y el valor de la propiedad Revision Number, de tal manera que me quede la propiedad Part Number (en este caso) así: 345679-023-P-1258-00.
¿Me podeis ayudar con este problemilla, o pido demasiado?, con lo poco (mas bien nada) que se de iLogic, no soy capaz ni de empezar a crear la regla.


Muchas gracias anticipadas.


-------------------------
Un saludo.

Mecanico14

Siempre parece imposible hasta que se hace.

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

dgreatice
Collaborator
Collaborator
Accepted solution

Hi,

 

 

try this:

 

 

GetString = Split(iProperties.Value("Project", "Part Number"), "-")
iProperties.Value("Project", "Stock Number") = Getstring(3)

iProperties.Value("Project", "Part Number") = iProperties.Value("Project", "Part Number") & "-" & iProperties.Value("Project", "Revision Number")

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
Message 3 of 9

Mecanico14
Advisor
Advisor

Good Morning.
Perfect, it works just the way I needed it, thank you very much, I already knew that it did not have to be so complex, but I do not know why, I was unable to find the right solution.
What has intrigued me is the code, I like to learn and therefore I do not limit myself to just asking, I try to know why or how the rule works. The first two lines confuse me, I do not know very well if what you do in the first is to look for the "-" (but there are several) and in the second you keep what goes behind, but I do not understand that Getstring(3). Yes, I understand that in this second line you set the value for the Stock Number property.
When I was trying to do something, I had insisted on using the Right() instruction, but I think I did everything wrong. Now it has occurred to me to try on your code and replace the Split, by Right, staying with the last 4 characters. The first two lines have stayed like this:

GetString = Right (iProperties.Value ("Project", "Part Number"), 4)
iProperties.Value ("Project", "Stock Number") = GetString

Is this code valid? work, it works perfect.
Or have I done some huge barbarity ?.
As I say, I still do not understand your first two lines (come on, I do not know what they do), that's why my doubts.
Anyway, thanks for your help and problem solved. That yes, I will be happy that you give me your opinion to what I comment. You or whoever wants to help.

 

------------------------------

 

Buenos días.
Perfecto, funciona tal y como necesitaba, muchas gracias, ya sabía yo que no tenía que ser tan complejo, pero no se por que, yo era incapaz de buscar la correcta solución.
Lo que si me ha intrigado es el código, me gusta aprender y por lo tanto no me limito solo a preguntar, intento saber por que o como funciona la regla. Las dos primeras líneas me confunden, no se muy bien si lo que haces en la primera es buscar el "-" (pero hay varios) y en la segunda te quedas con lo que va detrás, pero no entiendo ese Getstring(3). SI que entiendo que en esta segunda línea estableces el valor para la propiedad Stock Number.
Cuando estuve intentando hacer algo, yo me había empeñado en usar la instrucción Right(), pero creo que lo hacía todo mal. Ahora se me ha ocurrido probar sobre tu código y sustituir el Split, por el Right, quedandome con los 4 últimos caracteres. Las dos primeras líneas se han quedado así:

GetString = Right(iProperties.Value("Project", "Part Number"), 4)
iProperties.Value("Project", "Stock Number") = GetString 

¿Es válido este código? funcionar, funciona perfecto.
¿O he hecho alguna barbaridad enorme?.
Como ya te digo, no entiendo todavia tus dos primera líneas (vamos, no se lo que hacen), por eso mis dudas.
De todas formas, gracias por tu ayuda y problema resuelto. Eso si, estare encantado de que me des tu opinión a lo que comento. Tu o el que quiera ayudar.


-------------------------
Un saludo.

Mecanico14

Siempre parece imposible hasta que se hace.

0 Likes
Message 4 of 9

dgreatice
Collaborator
Collaborator

yes, you can use Right(String, 4).

 

if you have another issue to get string from 345679-023-P-1258, you can use Split():

the result is:

Getstring(0) = 345679

GetString(1) = 023

GetString(2) = P

GetString(3) = 1258

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
Message 5 of 9

Mecanico14
Advisor
Advisor

Good.
I think I'm already understanding, correct me if I'm wrong:

Split (iProperties.Value ("Project", "Part Number"), "-")

Here you are "cutting" the string given in "Part Number" in each "-" that exists in the chain, making as many "pieces" as "-" +1 exist in the chain. In my chain 345679-023-P-1258, a total of 4 "pieces". These "pieces" are numbered from left to right beginning with 0 and continuing with 1, 2 and 3
Then when using the instruction

iProperties.Value ("Project", "Stock Number") = Getstring (3)

I selected part No. 3
If I change the Getstring (X) number, then it gives me the values ​​that you indicate in your last answer:
Getstring (0) = 345679
GetString (1) = 023
GetString (2) = P
GetString (3) = 1258
Now I had a problem, because if the value I add at the end by joining "Part Number" + "-" + "00", already exists and I execute the rule, I would add another "-00" at the end of the "Part Number" and the chain that would extract for the "Stock Number", would not be what it should. That is why I modified the rule in this way:

 

LL = Len (iProperties.Value ("Project", "Part Number"))
If LL> 17 Then
iProperties.Value ("Project", "Part Number") = Left (iProperties.Value ("Project", "Part Number"), 17)
GetString = Split (iProperties.Value ("Project", "Part Number"), "-")
End If

iProperties.Value ("Project", "Stock Number") = GetString (3)

iProperties.Value ("Project", "Part Number") = iProperties.Value ("Project", "Part Number") & "-" & iProperties.Value ("Project", "Revision Number")

Now I have to think of a way to solve a problem that has been presented to me with other files, since they have one less character, so 345679-23-P-1258. I will have to make two rules and it bothers me, I would like it to be one, but I have to think how.

 

Thanks again, I'm already understanding more things about iLogic.

 

-------------------------------------------

 

Buenas.
Creo que ya lo estoy entendiendo, corrígeme si me equivoco:

Split(iProperties.Value("Project", "Part Number"), "-")

Aquí estás "cortando" la cadena dada en "Part Number" en cada "-" que existe en la cadena, haciendo tantos "trozos" como "-" +1 existan en la cadena. En mi cadena 345679-023-P-1258, un total de 4 "trozos". Dichos "trozos" se numeran de izquierda a derecha empezando con el 0 y continuando con el 1, 2 y 3
Entonces al usar la instrucción

iProperties.Value("Project", "Stock Number") = Getstring(3)

selecciono la parte Nº 3
Si cambio el número de Getstring(X), entonces me da los valores que me indicas en tu última respuesta:
Getstring(0) = 345679
GetString(1) = 023
GetString(2) = P
GetString(3) = 1258
Ahora tenía un problema, ya que si el valor que añado al final uniendo "Part Number" + "-" + "00", ya existe y ejecuto la regla, me añadiría otro "-00" al final del "Part Number" y la cadena que extraería para el "Stock Number", no sería lo que debería. Por ello he modificado la regla de esta manera:

 

LL = Len(iProperties.Value("Project", "Part Number"))
If LL > 17 Then 
iProperties.Value("Project", "Part Number") = Left(iProperties.Value("Project", "Part Number"), 17)
GetString = Split(iProperties.Value("Project", "Part Number"), "-")
End If

iProperties.Value("Project", "Stock Number") = GetString(3)

iProperties.Value("Project", "Part Number") = iProperties.Value("Project", "Part Number") & "-" & iProperties.Value("Project", "Revision Number")

Ahora tengo que pensar una manera de solucionar un problema que se me ha presentado con otros ficheros, ya que tienen un carácter menos, así 345679-23-P-1258. Tendré que hacer dos reglas y me incomoda, me gustaría que fuese una sola, pero he de pensar como.

 

Gracias de nuevo, ya voy entendiendo más cosas de iLogic.


-------------------------
Un saludo.

Mecanico14

Siempre parece imposible hasta que se hace.

0 Likes
Message 6 of 9

Mecanico14
Advisor
Advisor

Good afternoon.
When you insist on doing something, until you do not get it, it does not stop and that has happened to me. We call it "cabezón" here, jajajaja. I have already achieved what I wanted, apart from the fact that if I already had the "-00", I removed it and started again (this is so that if I change the "Revision Number", I update it, for example if I put " 01 ", add the" -01 ") and I have managed to make it not for a fixed number of characters, but for more. I had the problem of files with 16 characters and others with 17 and did not want to create two rules, if not with one, make it work in either case. Well after giving it a few laps, I got it. This is the result:

 

LL = Len (iProperties.Value ("Project", "Part Number"))
If LL> 16 Then iProperties.Value ("Project", "Part Number") = Left (iProperties.Value ("Project", "Part Number"), (LL-3))
GetString = Split (iProperties.Value ("Project", "Part Number"), "-")
End If iProperties.Value ("Project", "Stock Number") = GetString (3) iProperties.Value ("Project", "Part Number") = iProperties.Value ("Project", "Part Number") & "-" & iProperties.Value ("Project", "Revision Number")

And it works, which is what I liked the most.

In case someone is interested in my little "nonsense", it's still good for something.

 

------------------

Buenas tardes.
Cuando uno se empeña en hacer algo, hasta que no lo consigue, no para y eso me ha pasado. Por aquí lo llamamos "cabezón", jajajaja. Ya he conseguido lo que quería, aparte de que si ya tenía el "-00", lo quitaba y empezaba de nuevo (esto es con la finalidad de que si cambio la "Revision Number", me lo actualice, por ejemplo si pongo "01", que me añada el "-01") y he conseguido que no sea para un número de caracteres fijo, si no que sea para más. Tenia el problema de ficheros con 16 caracteres y otros con 17 y no quería crear dos reglas, si no que con una, hacer que funcionase en cualquiera de los dos casos. Pues después de darle unas vueltas, lo he conseguido. Este es el resultado:

 

LL = Len(iProperties.Value("Project", "Part Number"))
If LL > 16 Then
iProperties.Value("Project", "Part Number") = Left(iProperties.Value("Project", "Part Number"), (LL-3))
GetString = Split(iProperties.Value("Project", "Part Number"), "-")
End If iProperties.Value("Project", "Stock Number") = GetString(3) iProperties.Value("Project", "Part Number") = iProperties.Value("Project", "Part Number") & "-" & iProperties.Value("Project", "Revision Number")

Y funciona, que es lo que más me ha gustado.

Por si le interesa a alguien mi pequeña "tontería", igual le sirve para algo.

 


-------------------------
Un saludo.

Mecanico14

Siempre parece imposible hasta que se hace.

0 Likes
Message 7 of 9

Mecanico14
Advisor
Advisor
Accepted solution

Goodnight.
Sorry, sorry and a thousand times sorry. I do not know how the previous rules could work, but I had a serious syntax error. I had done tests on a piece that was made and worked, but when making a new piece, it did not work even backwards. I've gone crazy looking for the fault, I took about 3 hours analyzing the rule and I had not realized my big mistake, an error that I think I have corrected. Sorry to have confused those who have read it, the correct code to work with 16 or 17 characters is as follows:

LL = Len (iProperties.Value ("Project", "Part Number"))

If LL = 20 Then
iProperties.Value ("Project", "Part Number") = Left (iProperties.Value ("Project", "Part Number"), 17)

ElseIf LL = 19 Then
iProperties.Value ("Project", "Part Number") = Left (iProperties.Value ("Project", "Part Number"), 16)

End If

GetString = Split (iProperties.Value ("Project", "Part Number"), "-")

iProperties.Value ("Project", "Stock Number") = GetString (3)

iProperties.Value ("Project", "Part Number") = iProperties.Value ("Project", "Part Number") & "-" & iProperties.Value ("Project", "Revision Number")

I hope not to make another mistake, it's already too late in Spain and I'll see if I rest a little, tomorrow I'll try it again and check to see if it's still working.

Sorry for the inconvenience that may have caused.

 

------------------------

 

Buenas noches.
Perdón, perdón y mil veces perdón. No se como me podía funcionar las reglas anteriores, pero tenía un grave error de sintaxis. Había hecho pruebas en una pieza hecha y funcionaba, pero al realizar una pieza nueva, no funcionaba ni para atrás. Me he vuelto loco buscando el fallo, llevo como 3 horas analizando la regla y no me había dado cuenta de mi gran error, error que creo he subsanado. Siento haber confundido a los que lo hayan leído, el código correcto para que funcione con 16 o 17 caracteres es el siguiente:

LL = Len(iProperties.Value("Project", "Part Number"))

If LL = 20 Then
iProperties.Value("Project", "Part Number") = Left(iProperties.Value("Project", "Part Number"), 17)

ElseIf LL = 19 Then
iProperties.Value("Project", "Part Number") = Left(iProperties.Value("Project", "Part Number"), 16)

End If

GetString = Split(iProperties.Value("Project", "Part Number"), "-")

iProperties.Value("Project", "Stock Number") = GetString(3)

iProperties.Value("Project", "Part Number") = iProperties.Value("Project", "Part Number") & "-" & iProperties.Value("Project", "Revision Number")

Espero no volver a equivocarme otra vez, ya es muy tarde en España y voy a ver si descanso un poco, mañana lo vuelvo a probar y revisar a ver si sigue funcionando.

Perdón por las molestias que haya podido causar.


-------------------------
Un saludo.

Mecanico14

Siempre parece imposible hasta que se hace.

0 Likes
Message 8 of 9

dgreatice
Collaborator
Collaborator
Accepted solution

Hi,

 

 

because you use len(), is better to avoid wrong user input in Revision. value of revision can be (00) or (0)?

 

nice, there are many way to do this:

 

GetString = Split(iProperties.Value("Project", "Part Number"), "-")
iProperties.Value("Project", "Stock Number") = GetString(3)

Try
	GetString(4) = iProperties.Value("Project", "Revision Number")
	iProperties.Value("Project", "Part Number") = GetString(0) & "-" & GetString(1)& "-" & GetString(2) & "-" & GetString(3) & "-" & GetString(4)
Catch
	iProperties.Value("Project", "Part Number") = iProperties.Value("Project", "Part Number") & "-" & iProperties.Value("Project", "Revision Number")
End Try

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
Message 9 of 9

Mecanico14
Advisor
Advisor

Good afternoon.
I have to acknowledge my complete ignorance regarding the programming with iLogic and I have to admit that the four things that I have prepared for my personal use, could be wrong in its approach or its programming. My dear friend, I discover myself before you, has simplified my problem in a few lines.
And yes, "Revision Number" can be "00" or "0" or any other value, like "1234". In principle they are two figures, starting with "00" and with each revision increasing the value by 1, that is "01", "02", "03" ....
But from what I'm trying, it works with any number of characters.

 

Thank you very much for your help, for me it has been a great and quick iLogic lesson that I will always remember.

 

----------------------------

 

Buenas tardes.
He de reconocer mi completa ignorancia en lo que respecta a la programación con iLogic y he de reconocer que las cuatro cosas que haya preparado para mi uso personal, puedan ser erróneas en su planteamiento o su programación. Mi estimado amigo, me descubro ante usted, ha simplificado mi problema en unas pocas líneas.
Y si, "Revision Number" puede ser "00" o "0" o cualquier otro valor, como "1234". En principio son dos cifras, empezando por "00" y con cada revisión aumentando el valor en 1, es decir "01", "02", "03" ....
Pero por lo que estoy probando, funciona con cualquier cantidad de caracteres.

 

Muchas gracias por tu ayuda, para mi ha sido una estupenda y rápida lección de iLogic que la recordaré siempre.


-------------------------
Un saludo.

Mecanico14

Siempre parece imposible hasta que se hace.

0 Likes