Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide/Show UDF output 3

Status
Not open for further replies.

Carl77

Automotive
May 29, 2020
5
IT
Hi dear all
I'm new in this forum, I have a question.
I have done a UDF with several output (look at the attached image).
Can I hide or show output feature by a reaction when i change plug parameter?
UDF_b3aeum.jpg
 
Replies continue below

Recommended for you

you can include the reaction inside the UDF. That should do the job...

Eric N.
indocti discant et ament meminisse periti
 
Itsmyjob Thank you for the answer.
I try to write a reaction like this (I write from my smartphone, I have not the UDF at hand):
If plug= "Yes"
{
Z942.show= true
}
Else
{
Z942.show= false
}
When I initialize the UDF, it doesn't work.
Have you any idea?
 
Well... we wish it would work that way but no.

is Z942 is the geometry you use to define as output in the UDF, then it's not gonna work, you have to get the output element, not the geometry that define the output.

So what I did:

create a GeometricalSet or a Body (I used an Assemble Body)
in you GeoSet or Body make sure you have a parameterSet and a relationSet
create your boolean parameter in your parameterset
create the reaction in the relationset

UDF1_bhutz0.png


in the reaction find the UDF with something like this:

Code:
let myUDF (UserFeature)
set myUDF =PartBody\Assemble.1.Owner

now that you have the UDF, go get the output but the trick is that when you create the code the first time you don't have the output yet, you did not defined the UDF yet... so Query the name you will give the output


Code:
let myList (List)
myList =myUDF.Query ("Line", "x.Name == \"HoleAxis\" ")

even if my line in the definition of the geometry is name Axis.7 I search the the output name...

Next is to Hide the Line

Code:
let myUDFOutput (Line)
set myUDFOutput  = myList[1]

myUDFOutput.Show = PartBody\Assemble.1\Body.1\Parameters.1\ShowAxis

UDFReaction_cfr3f7.png


Here I have my Parameter as boolean and not yes / no but you can use ternary to quickly get what you want:

Code:
myUDFOutput.Show = (plug== "Yes")? True ; False

Now if you change your parameter it will fail and you will have error message because no line is named HoleAxis... not best solution but we're not done yet.

Create the UDF and define the output Line and name it properly and publish the parameter

udf2_q2glmn.png


in the UDF you can change the parameter and again it will fail... don't panic!

instantiate your UDF

change parameter and voila! it works. Etonnant non ?

udf3_i5cbfj.png


So why does it fail in the definition? just because we are looking for a line that does not exists yet (the output element)
Why does it fail in the UDF? Because in the UDF the output is not truly a Line, so even if the name is correct, the Type is not.

and it works in the Instantiation of the UDF, because the output is a line with the proper name...

Can we make it work at all level (Definition/ UDF / Instantiation) ?
We almost could... if we make sure the Reaction is looking for the proper element:
in the definition, add some code to check if UDF is Null then change Axis.7.Show Parameter
in the UDF, well the output is a Feature and it seams it does not have Show Attribute, so no

To sum up: the output element is a duplication of the element that defines it, so if you want to change show or color attribute you have to get this output element, if you want to get length of output curve, well it should be the same as the length of the curve that defines it, so you can use the curve.

Enjoy...





Eric N.
indocti discant et ament meminisse periti
 
Thank you so much itsmyjob for your explanation. It's the first time that someone has explained that so clearly. When i return to work on wednesday i will try to modify the UDF as you have explained to me. I will let you know if everything is OK.
Best regards
Carl77
 
Hi itsmyjob
I don't Know but I can't write the code.
I have to do this with CATIA V5 R19, because some of our suppliers work with this version.
I attach the native file to the message.
Thank you very much.
Best regards
Carl77
UDF3_mshyek.png
 
the following code works for me.

Code:
let myUDF (UserFeature)
set myUDF =PartBody\Foro_HF_Punto_Angolo .Owner

let myList (List)
myList =myUDF.Query ("VolumeGeo", "x.Name == \"Z942\" ")

let myUDFOutput (VolumeGeo)
set myUDFOutput  = myList[1]

myUDFOutput.Show = `Foro_HF_Punto_Angolo\Geometrical Set.2\Parameteri_Foro\Plug2`


After changing the code I had to pass it to the definition of the UDF by updating the UDF

2020-06-02_21-15-25_nqzhhy.png


Also I published the boolean parameter Foro_HF_Punto_Angolo\Geometrical Set.1\Parameteri_Foro\Plug2

Result is fine:

2020-06-02_21-12-08_arpcdh.png



Not sure why line 2 would fail. Remove all lines in your code, and add one line at a time to see when the problem is. I had some problem with some code before and the solution was to delete the Action or the Reaction and make a new one.

Have fun... Stay safe.

Eric N.
indocti discant et ament meminisse periti
 
Itsmyjob thanks for your quick reply.
I'm not sure but I think the problem colud be vindows 8.1, maybe some .Net framework aren't updated.
Tomorrow I'll try on windows 10.
Thank you very much.
Have a nice day.
 
i am using 3dx21X on win10

Eric N.
indocti discant et ament meminisse periti
 
Eric, since this was fun, I tried to incorporate color into the reaction...
with mixed success...
It works IF I only have one color, but when I add "else" the whole thing stops responding to the color request... any reason why? I want to change the color of the entire UDF; hence
let myUDF (UserFeature)
set myUDF =UDF_prep\Assemble.1 .Owner

let myList (List)
myList =myUDF.Query ("VolumeGeo", "x.Name == \"Z942\" ")

let myUDFOutput (VolumeGeo)
set myUDFOutput = myList[1]

myUDFOutput.Show =UDF_Body\Parameters.2\BoxAttached

if UDF_Body\Parameters.2\BoxAttached
myUDF.Color="Green"
else
myUDF.Color="Yellow"
this does not work... but removing else and its contents will change the color to green (once)


regards,
LWolf
 
Edit: Yesterday it did NOT work, I tried rewriting the if-syntax in 10+ different ways, without success.
Today though, it WORKS. Anybody has any clue to WHY I get this random behaviour?!

regards,
LWolf
 
Yesterday it did NOT work, I tried rewriting the if-syntax in 10+ different ways, without success.
Today though, it WORKS. Anybody has any clue to WHY I get this random behaviour?!

Did you try restarting CATIA yesterday?
 
Little Cthulhu, no... that is one thing I did not.

regards,
LWolf
 
Little Cthulhu, no... that is one thing I did not.

Then I suppose it's just a bug possibly caused by a state CATIA was in.

As always, if you manage to reproduce it, send a report to DS.
 
I like to start CATIA in the morning..... It's a good day.

Eric N.
indocti discant et ament meminisse periti
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top