2023-11-28 05:24 PM - last edited on 2024-09-26 01:32 PM by Doreena Deng
I'd like to create an object with A=B and 2 values for A and B: 1 or 2.
If A(or B) = 1 then it draws a square.
If A(or B) = 2 then it draws a circle.
In addition to this (simple) object, I'd like to be able to set offset hotspots on the circle and square (to force the user to take some safety margins in the drawing without cheating on the circle or square actually drawn).
These hotspots are offset by a "dim_secu" value.
I'd like to be able to modify this "dim_secu" value via Model View Options.
This is where I get stuck.
The dim_secu value is correctly updated in the object: the displayed A value takes this new value into account, but the drawing itself doesn't update on its own: I have to force this update manually.
If I don't use Model View Options and change dim_secu from the object itself, I don't have this problem.
Any ideas on how to debug the object?
Thanks in advance!
Principal:
succes = LIBRARYGLOBAL ("MVO_EXAMPLE", "dim_secu_glob" , dim_secu)
2D:
! ---------------------------------------------------------------------- !
! --------HOTSPOT------------------------------------------------------- !
! ---------------------------------------------------------------------- !
_unID = 1
HOTSPOT2 0, 0, _unID : _unID = _unID + 1
!!! ------------ Coins : Dimension A
hotspot2 0, 0, _unID, A, 1+256,A ! base ancrage
_unID = _unID + 1
hotspot2 -1, 0, _unID, A, 3,A ! ref
_unID = _unID + 1
hotspot2 A, 0, _unID, A, 2,A ! move
_unID = _unID + 1
hotspot2 0, B, _unID, A, 1+256 ,A
_unID = _unID + 1
hotspot2 -1, B, _unID, A, 3 ,A
_unID = _unID + 1
hotspot2 A, B, _unID, A, 2 ,A
_unID = _unID + 1
!!! ------------ Coins : Dimension B
hotspot2 0, 0, _unID, B, 1+256 ,A
_unID = _unID + 1
hotspot2 0, -1, _unID, B, 3 ,A
_unID = _unID + 1
hotspot2 0, B, _unID, B, 2 ,A
_unID = _unID + 1
hotspot2 A, 0, _unID, B, 1+256 ,A
_unID = _unID + 1
hotspot2 A, -1, _unID, B, 3 ,A
_unID = _unID + 1
hotspot2 A, B, _unID, B, 2 ,A
_unID = _unID + 1
! ---------------------------------------------------------------------- !
! --------DESSIN 2D----------------------------------------------------- !
! ---------------------------------------------------------------------- !
IF A=1+2*dim_secu THEN
RECT2 dim_secu,dim_secu,A-dim_secu,B-dim_secu
ELSE
CIRCLE2 A/2,A/2,(A-2*dim_secu)/2
ENDIF
Parameter:
LOCK "dim_secu"
!VALUES "A" 1+2*dim_secu,2+2*dim_secu
!VALUES "B" 1+2*dim_secu,2+2*dim_secu
IF GLOB_MODPAR_NAME = "A" AND A = 1+2*dim_secu THEN
PARAMETERS B = 1+2*dim_secu
ENDIF
IF GLOB_MODPAR_NAME = "A" AND A =2+2*dim_secu THEN
PARAMETERS B = 2+2*dim_secu
ENDIF
IF GLOB_MODPAR_NAME = "B" AND B =1+2*dim_secu THEN
PARAMETERS A = 1+2*dim_secu
ENDIF
IF GLOB_MODPAR_NAME = "B" AND B = 2+2*dim_secu THEN
PARAMETERS A = 2+2*dim_secu
ENDIF
Solved! Go to Solution.
2023-12-04 10:37 AM
Yves, a french user sent me a solution to the problem, using only the master script:
succes = LIBRARYGLOBAL ("MVO_EXAMPLE", "dim_secu_glob" , dim_secu)
a1 = 1+2*dim_secu
a2 = 2+2*dim_secu
IF A < 1.5-EPS THEN
A = a1
B = a1
ELSE
A = a2
B = a2
ENDIF
IF GLOB_MODPAR_NAME = "A" THEN
PARAMETERS B = A
ELSE
PARAMETERS A = B
ENDIF
2023-11-29 12:57 PM - edited 2023-11-29 01:00 PM
I’m not able to download the objects at the moment to interrogate in detail, but I think your issue is stemming from the fact you are attempting to change a parameter inside the object from the MVO, which can’t be done. An objects parameter can only be changed via script when the parameter script of that object is run. And that only runs when you change a setting parameter of that object.
I think you need to restructure your script to just read whether the setting you are applying in the MVO is on or off. And then your 2D script should just draw the safety margin there based on the value being on or off. Not try and modify the parameters.
Hope that makes sense.
2023-11-29 02:13 PM
Thank you for your reply.
The parameters can be modified via the model view options: size A & B take the new size into account in real time when modified by MVO.
But indeed, the problem seems to lie with the parameter script:
My conditions (If...then...) to make my script work are based on values that are set using the VALUES function, and the VALUES function only works when the parameter script is executed.
I wonder if there's an alternative/strategy in terms of code to avoid using the VALUES function.
I confess I didn't quite understand your recommendation.
2023-11-30 11:29 PM
You need to decide where you want to change the dim_secu parameter, from the object, or from the MVO. You can't have it modifiable from both spots.
If you did want that, you would need to have an option in the object to decide if you want to read from an object specific dim_secu or the MVO dim_secu.
If i deleted dim_secu from the object, i was able to modify dim_secu from the MVO and it seems to be working. Kind of.
I think your use of trying to use A & B to dictate whether you are drawing a square of a circle is complicating things. And then ending that into your if/else statements is causing your issues.
Would it not be easier to just use a drop down where you can choose either Circle or Square, then capture what you want your safety margin you need is. Then in your 2D script your if else statement based on the Circle or Square option, and then simply add the safety margin to the x,y cords of the rect2 or circle2.
Also just to clarify, the VALUES function will only change what the available value of the param is, it won't actually change the param to that value. For that you need to use the PARAMETERS function.
2023-12-04 10:37 AM
Yves, a french user sent me a solution to the problem, using only the master script:
succes = LIBRARYGLOBAL ("MVO_EXAMPLE", "dim_secu_glob" , dim_secu)
a1 = 1+2*dim_secu
a2 = 2+2*dim_secu
IF A < 1.5-EPS THEN
A = a1
B = a1
ELSE
A = a2
B = a2
ENDIF
IF GLOB_MODPAR_NAME = "A" THEN
PARAMETERS B = A
ELSE
PARAMETERS A = B
ENDIF
2023-12-08 04:50 PM
Hi, that might work technically, but only as long as the users don't forget that each MVO set should contain the same margin value.
Consider you have two objects.
The master script ensures they are both drawn by the current MVO, but the parameters only change when the script is run in parameter script context (settings dialog or hotspot edit), so contain the effect of the MVO at that time. One object might have been changed using one MVO, the other object by another.
Scheduling or labeling their A/B parameters will show different values.
2023-12-13 11:31 AM
Thanks, you made my day 🙂