NEVJOHNSON
 |
| 13 Nov 2006 03:13 PM |
|
Anyone know what is the correct way to code a VBScript to be used in a UDF.
For example I coded the following
Dim oDoc As Document
Set oDoc = CATIA.ActiveDocument
Dim oPart As Part
Set oPart = oDoc.Part
Dim oParams As Parameters
Set oParams = oPart.Parameters
Dim strParam1 As Parameter
Set oMyParam = oParams.Item("Style"
However failure occurs on the last line.
How do I access the parameters that are now within the UDF as opposed tothe parameters that were
external before the udf was built?
I hope that makes sense
There is further code that I guess will fail for the same reasons.
Thxs In Adv
Nev |
|
|
|
|
DS_DEVELOPER
 |
| 14 Nov 2006 03:05 AM |
|
Mmmmh, I think this instantiates a user feature and gets a published parameter. This is not what Nev tries to do...
Nev, there are several problems in your script : - it can not be exexcuted if the part is included in a product (because of Set oPart = ActiveDocument.Part) - You retrieve a parameter by its name, but 1. you don't know the name it will have in the udf 2. what happens if the udf is instantiated several times?
This is the reason why script with arguments exist. They allow to code generic macros So create a VB script with argument feature, and adds the parameter as an argument
Sub CATMain(parameter) ' do something with the parameter ' if you need the part, DO NOT USE Father.Father, ' use Context instead, it is dedicated to retrieve the root of parameter document End Sub
Then use this macro either in a rule or in a reaction, and pass directly the parameter you want to use in the macro... Note that you can add arguments in the macro if needed. Note that the objects passed as arguments to the macro wiil be udf inputs if not embedded in the udf (so avoid to use the part as an argument, it is strange to have the part as an input)
Regards |
|
|
|
|
NEVJOHNSON
 |
| 14 Nov 2006 08:42 AM |
|
Hi DS_developer
- it can not be exexcuted if the part is included in a product (because of Set oPart = ActiveDocument.Part) The UDF is instantiated via VB. The part is in a product but I just open the part in a new window to overcome any issue with ActiveDocument.
So create a VB script with argument feature
Mmmh. problem. The argument idea would work but how to I code this if the UDF is instantiated automatically.?
Thxs
Nev |
|
|
|
|
DS_DEVELOPER
 |
| 14 Nov 2006 08:51 AM |
|
Nev, I don't understand the problem.
The script with argument is embedded in the udf, and is executed when rule or reaction using it is evaluated. This rule or reaction should also be embedded in the udf.
The way the udf is instantiated should not affect this behaviour |
|
|
|
|
NEVJOHNSON
 |
| 14 Nov 2006 09:36 AM |
|
DS_developer,
OK my error
Did not realize you could simply pass the arguments as
`Relations\VB Scripts.1\SetHoleAngles` .Run(Feature .GetAttributeString("Style" ) )
Firstly as .Run is missing from the dictionary when in a rule although it does show in the reaction dictionary.
However the parameter I wish to pass is a top level parameter. It does not exist as a parameter in a feature.
Is it possible to pass top level parameters I.e those stored under the Root Parameter set?
Or do I need to put my parameters in a feature to be able to pass them using the GetAttributeString method?
Regards
Nev |
|
|
|
|
DS_DEVELOPER
 |
| 14 Nov 2006 09:56 AM |
|
Run does not appear in rule dictionary because it is not a best practice to use macros from rules (you know exactly when a reaction is executed, it is much less clear for a rule, that can be evaluated several times in an update transaction)
In your context, you should pass the parameter directly (not thru object.GetAttribute...) : `Relations\VB Scripts.1\SetHoleAngles` .Run()
If the parameter is not embedded in the udf, it will become an udf input. Otherwise, the argument will be the parameter inside the udf. |
|
|
|
|
NEVJOHNSON
 |
| 14 Nov 2006 10:36 AM |
|
In your context, you should pass the parameter directly
Did not understand what you meant by pass it directly.
I assume you meant `Relations\VB Scripts.1\SetHoleAngles` .Run(Parameter1,Parameter2) etc
But if this were the case that could not be correct as I need to extract the value of the parameter not the parameter itself.
How does one do this. It is not clear that a string method can do this or maybe it can if you know which one to use.
Regards
Nev |
|
|
|
|
NEVJOHNSON
 |
| 14 Nov 2006 11:23 AM |
|
OK. think I have cracked it
Pass parameter as I had written
`Relations\VB Scripts.1\SetHoleAngles` .Run(Parameter1,Parameter2)
And can u believe its as simple as
Parameter1.value once inside the script |
|
|
|
|
DS_DEVELOPER
 |
| 15 Nov 2006 06:42 AM |
|
Yes this is as simple as that! It opens perspectives, doesn't it?
(I had written .Run(parameter) with parameter surrounded by "<"and ">", but it made disappear the word...)
|
|
|
|
|
NEVJOHNSON
 |
| 15 Nov 2006 11:20 AM |
|
Thankxs DS,
I have now put that one to bed.
or so I though
It appears that I am now experiencing a new problem.
First lets explain the scenario.
The UDF (containing the VBScript) is run by a reaction.
I instantiate UDF within a Body within a part. (all good so far)
I then instantiate the same UDF after the first (using different inputs)
However for some strange reason when I investigate the parent child relations.
The second UDF says that it has the 1st as a parent.
Additionally the second UDF does not behave as expected.
I can only assume that when the VBscript is run it somehow grabs the 1st UDF.
How can this BE and how can I check for it and AVOID it.
Regards
Neville
|
|
|
|
|
DS_DEVELOPER
 |
| 20 Nov 2006 04:04 AM |
|
It is difficult to say...
Please describe your udf content and inputs.
If you are in R16 level, you can also use the udf debugging capability (in udf definition panel, choose White box, so that the udf is instantiated "opened". You probably will be able to analyze the problem) |
|
|
|
|
NEVJOHNSON
 |
| 21 Nov 2006 09:49 AM |
|
Unfortunately I am not using r16 yet.
Better than describing contents and inputs.
Here is a copy of the UDF.
Still puzzles me why when u instantiate multiple UDFs they all seem linked.
This must surely slow down regeneration times?
Thxs
Nev |
Attachment: 111215001583.zip
|
|
|
|
DS_DEVELOPER
 |
| 21 Nov 2006 11:05 AM |
|
I can not instantiate it without having errors (no resulting element)...
You did not say where to instantiate... and I used Use Identical name |
|
|
|
|
NEVJOHNSON
 |
| 21 Nov 2006 12:24 PM |
|
Good Point.
Here is a part in which the UDF is instantiated 3 times.
In addition the exists all inputs for these UDFs.
All UDFS appear to be located in the same position in space.
However if you delete the 1st the 2nd appears in the position it should be.
Equally if you delete 1st and 2nd then the 3rd appears in its correct position.
|
Attachment: 11121242184478.zip
|
|
|
|