Support Forum

Smartpart: repetition of one object by several handles [Gelöst]


Hi!

I'm creating a SmartPart that draws a rectangle several times, and this was created from two ways:
- From a handle "A" to copy the rectangle along a length
- From a handle "B" which controls the number of rectangles

In this script, the handle "A" works well, but the handle "B" does not work. How do you write the script correctly? This is the script:

rect_x = 0.5
rect_y = 0.5
n_objects = lenght / rect_x

!---- Handle of distribution of rectangles by total lengh
id = id + 1
HANDLE2 0 , 0 , id , "lenght" , 1
HANDLE2 lenght , 0 , id , "lenght" , 2
HANDLE2 -1 , 0 , id , "lenght" , 3

!---- Handle of distribution of rectangles by number
id = id + 1
HANDLE2 lenght , rect_y , id , "n_objects" , 9

!---- Call Layout
FOR kk = 1 TO n_objects
GOSUB "rectangle"
TRANS2 rect_x , 0
NEXT
RESTORE n_objects
RESTORE 1
END

!---- Subscript
"rectangle":
RECT2 0 , 0 , rect_x , rect_y
RETURN

Thanks a lot!
Xavi

Xavier Coll • Architect, Project Manager I+D, BIM Manager, BIM Auditor
EiPM • http://www.eipm.es/en/

Anhänge (1)

Typ: image/jpeg
516-mal heruntergeladen
Größe: 196,80 KiB

Hi Xavi,

if you look at your Code, then the answer is given:

In the 3rd line you calculate n_objects from the length!
After that calcualtion you probably change the length by the handle definition!
And the handle definition afterwards probably changes n_objects...
Very confusing...
You have to know:
HANDLE2 isn't executed at this position! It is only a definition for the handle!
(It changes the parameter value before executing Parameter-Part)

You should do the following:

1. Move the general initialization to Master-Part:

rect_x = 0.5
rect_y = 0.5

2. In the Parameter-Part you have to built in an switch, if
-you want to use the length, and calculate the number
-you want to use the number (and calcualte the length)

!!calculate count
IF GLOB_MODPAR_NAME = "lenght" THEN
n_objects = lenght / rect_x
PARAMETERS n_objects = n_objects
ENDIF
!!calculate length
IF GLOB_MODPAR_NAME = "n_objects" THEN
lenght = n_objects * rect_x
PARAMETERS lenght = lenght
ENDIF

(GLOB_MODPAR_NAME holds the name of the last modified parameter)

Another thing to know is, that if you change a parameter, then you have to
do it inside Parameter-Part, and do it with

PARAMETERS [parameter_name] = [parameter_name]

If you don't use this way, only the variable is changed (valid only for current script part)
At the beginning of each part-execution the parameter values are copied in the variables values...

HANDLE-Modification (dragging it) or input the value (in the dialog) change the parameters value directly(not the variable) before execution of parameter part!

Regards.

Jörg

Anhänge (1)

Typ: application/octet-stream
1899-mal heruntergeladen
Größe: 6,05 KiB

Jörg, thanks for all your advice! :-)
now works really well, and step by step it's understanding the smarpart's ecosystem.

I have some other question about one other smartpart, that is totally diferent of the last smartpart. In this other smartpart, the goal is to create a secuential of diferent geometries, using handles of "input type" at every kind of geometry.

The different geomerty are rectangles and triangles. The script create firt the rectangles (the number of rectangles is controlled by a handle of input type for the rectangles). After, the script create the triangles the number of rectangles is controlled by a handle of input type for the triangles).

While the script is editing, works well. But after the editing, the smartpart only show the rectangles. , but when it's editing the smartpart, this create it correctly, but when it finalices, not appear all the geometry, only the first geometry. How do you write the script correctly? This is the 2D Script:

!------------- Call layout rectangles
TRANS2 0 , 0

id = id + 1
HANDLE2 lenght_rect , rect_y , id , "n_rect" , 9

FOR kk = 1 TO n_rect
GOSUB "rectangle"
TRANS2 rect_x , 0
NEXT kk
RESTORE n_rect
RESTORE 1

!------------- Call layout triangles
TRANS2 lenght_rect , 0

id = id + 1
HANDLE2 lenght_tri , tri_y , id , "n_tri" , 9

FOR jj = 1 TO n_tri
GOSUB "triangle"
TRANS2 tri_x , 0
NEXT jj
RESTORE n_tri
RESTORE 1

END

!------------- Subscripts
"rectangle":
RECT2 0 , 0 , rect_x , rect_y
RECT2 0 , 0.07 , rect_x , 0.07
RETURN

"triangle":
POLY 3 ,
0 , 0 ,
tri_x , 0 ,
tri_x / 2 , tri_y
RETURN

Thanks a lot!!
Xavi

Xavier Coll • Architect, Project Manager I+D, BIM Manager, BIM Auditor
EiPM • http://www.eipm.es/en/

Anhänge (3)

Typ: image/jpeg
481-mal heruntergeladen
Größe: 160,68 KiB
Typ: image/jpeg
411-mal heruntergeladen
Größe: 127,08 KiB
Typ: image/jpeg
451-mal heruntergeladen
Größe: 102,09 KiB

This is the smarpart file :-)

Xavier Coll • Architect, Project Manager I+D, BIM Manager, BIM Auditor
EiPM • http://www.eipm.es/en/

Anhänge (1)

Typ: application/octet-stream
1810-mal heruntergeladen
Größe: 30,38 KiB

Hi Xavi,

as I mentioned before, you have to change parameters inside Parameter-Part with:

length_rect = n_rect * rect_x
length_tri = n_tri * tri_x

PARAMETERS length_rect = length_rect , length_tri = length_tri

(at "length" if have corrected the "th" -> you have written "lenght")

But the main mistake is, that you try to create an 3D-element inside the 2D-Script:

POLY 3 ,
0 , 0 ,
tri_x , 0 ,
tri_x / 2 , tri_y

If you really want to create 3D-Polygons, then do it inside 3D-Part!
Otherwise write:

POLY2 4 , 1 ,
0 , 0 ,
tri_x , 0 ,
tri_x / 2 , tri_y,
0,0

Regards

Jörg

Anhänge (1)

Typ: application/octet-stream
1852-mal heruntergeladen
Größe: 6,32 KiB

Ouuuuuups! you are absolutely right, Jörg.
Are beginner mistakes.. :-)

Thanks a lot!
Xavi

Xavier Coll • Architect, Project Manager I+D, BIM Manager, BIM Auditor
EiPM • http://www.eipm.es/en/

There is another solution to this problem, which I discovered by chance. When defining the handles just add handlefactor 1/(the value of distance between the objects) and then you can directly create handles based on the number parameter (n). Don't forget to return to the initial state by adding at the end handlefactor 1.

x = 0.4
y = 1.2

id=id+1
handlefactor 1/x

handle2 0,0,id,n,1
handle2 n*x,0,id,n,2
handle2 -1,0,id,n,3

handlefactor 1
GOSUB "box"

FOR i = 1 TO n - 1
TRANS2 x , 0
GOSUB "box"
NEXT i

RESTORE n - 1

END

"box":

PUT 0 , 0 , 15 ,
x , 0 , 15 ,
x , y , 15 ,
0 , y , 15

POLY2_ NUM_SP / 3 , 1 + 2 + 4 , GET ( NUM_SP )

RETURN

Very interesting, Haidu. I programmed a SmartPart that made a similar result as the one you have written, but without using Handlefactor. But thank you very much for the advice: with handlefactor, the script can be more accurate and allows more control.

Thanks a lot, Haidu! :-)
Regards,
Xavi

Xavier Coll • Architect, Project Manager I+D, BIM Manager, BIM Auditor
EiPM • http://www.eipm.es/en/