BIM Coordinator Program (INT) April 22, 2024
Find the next step in your career as a Graphisoft Certified BIM Coordinator!
GDL
About building parametric objects with GDL.
SOLVED!

2D script to move nodes individually

mansarius
Participant

Hi, first time poster here!

 

I have been working with Archicad for about 2 years now, and now I feel it's time to start learning some scripting! I have started with the script under here to create a basic rectangle where I can stretch the width and height, but what I want it to do is to make each hotspot move in X and Y individually, so that when I click one hotspot, the other hotspots stay where they are while the clicked hotspot can be adjusted freely and not locked in either X or Y. Alternatively that point 0,0 and A,0 are stationary, and 0,B and A,B can be adjusted individually to make a trazoid shape for example.

 

I have tried to find the info in avaiable resources. I feel this is something that's very easy to do, but I just don't know what to search for to find the info.

 

Can someone help me with this code? I use AC 26.

 

pen gs_cont_pen

unID = 1


! Make Height stretchable

hotspot2 0,0,unID : unID=unID+1
line2 0, 0, a, 0
line2 a, 0, a, b
line2 a, b, 0, b
line2 0, b, 0, 0
line2 0,0,a,b

HOTSPOT2 0, 0, unID, A, 1+256
unID=unID+1
HOTSPOT2 -0.001, 0, unID, A, 3+128
unID=unID+1
HOTSPOT2 A, 0, unID, A, 2
unID=unID+1

HOTSPOT2 0, B, unID, A, 1+256
unID=unID+1
HOTSPOT2 -0.001, B, unID, A, 3+128
unID=unID+1
HOTSPOT2 A, B, unID, A, 2
unID=unID+1


! Make Width stretchable

HOTSPOT2 0, 0, unID, B, 1+256
unID=unID+1
HOTSPOT2 0, -0.001, unID, B, 3+128
unID=unID+1
HOTSPOT2 0, B, unID, B, 2
unID=unID+1

HOTSPOT2 A, 0, unID, B, 1+256
unID=unID+1
HOTSPOT2 A, -0.001, unID, B, 3+128
unID=unID+1
HOTSPOT2 A, B, unID, B, 2
unID=unID+1

fill gs_fill_type

poly2_b 5, 2,gs_fill_pen,gs_back_pen,
0,0,0,
0,b,0,
a,b,0,
a,0,0,
0,0,-1  

 

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
MF BIM
Booster

Hi @mansarius ,

 

Rest assured, why you're trying to do is not easy as hotspot editiong should probably further down your list of things to learn 😁

The answer that you're looking for is explained in the Reference Guide under the chapter "Graphical Editing Using Hotspots" but you've likely already read it as you've mixed two parameters in your type 2 hotspots2.

 

Before going into your issue, two things :

- if you use the poly2_b command, you do not need to use line2. poly2 commands manage both linework and fill and to do so you need to give them a frame_fill value of 3 or 1+2. The reason why you don't see your linework is because your frame_fill is 2 (only fill is displayed) and you gave all the nodes a 0 status (which won't display any linework even if the frame_fill is 3). Switch the 0s to 1 to display the lines and you will optimize your code already.

- you could fuse several lines that are related by using colons so this :

 

HOTSPOT2 0, B, unID, B, 2
unID=unID+1

 

will become that :

 

HOTSPOT2 0, B, unID, B, 2 : unID=unID+1

 

 

Considering you will likely have plenty of hotspots2 for what you want to do, it will clean up your code significantly.

 

Ok so now on to your issue. Your problem is two fold : you want each corner to behave independently from each other while your rectangle still use A and B as main dimensions. As hotspots are related to only one dimension and you need two to move in 2 dimensions, then the answer is to create two parameters per nodes that will add a delta to the rectangle's nodal coordinates.

 

Below, is an example for one node only (the first one on the bottom left that I named n1). I created two new parameters for this that I named n1_dx and n1_dy.

 

pen gs_cont_pen
fill gs_fill_type

unID = 1

! Make node 1 stretchable

hotspot2 0, n1_dy, unID, n1_dx, 1+128 : unID=unID+1
hotspot2 -1, n1_dy, unID, n1_dx, 3 : unID=unID+1
hotspot2 n1_dx, n1_dy, unID, n1_dx, 2 : unID=unID+1
hotspot2 n1_dx, 0, unID, n1_dy, 1+128 : unID=unID+1
hotspot2 n1_dx, -1, unID, n1_dy, 3 : unID=unID+1
hotspot2 n1_dx, n1_dy, unID, n1_dy, 2 : unID=unID+1

! Adds deltas for x and y for each of n1's coordinates

poly2_b	5, 1+2, gs_fill_pen, gs_back_pen,
		0+n1_dx, 0+n1_dy, 1,
		0, b, 1,
		a, b, 1,
		a, 0, 1,
		0+n1_dx, 0+n1_dy, -1 

 

 

Basically, the two delta parameters for n1 subtract or add to n1's coordinates according to their respective values. On the poly2_b coordinates, I willingly wrote "0+n1_dx" so you could understand that but you do not need the "0+" there, it's redundant. If you want all 4 nodes to move independently, you will then need to create 6 additional parameters and create 3 new sets of hotspots2 for n2, n3 and n4.

 

Also for your type 1 parameters, it's not necessary to make them editable. They are usually hidden (+128) except for specific cases.

 

Hope that my explanations were clear 🙂

https://mfbim.fr | https://youtube.com/@mfbim
AC21 FRA 3005 - AC24 FRA 7600 - AC26 FRA 4027 | MacBook M1 Pro

View solution in original post

5 REPLIES 5
Dave Seabury
Advocate

Mansarlus

 

Google GDL Cookbook, there is a hot spot example that will help you out.

If you can't find it let me know and i will copy the script.  Lots of other good stuff

in too it you are just starting out scripting.

 

David

 

AC 19-24 Windows 10 64 bit, Dell Prercision 7820, Xeon Silver 2414R ( 12 Cores), 64 GB Ram, Quadro RTX 4000 8GB
Solution
MF BIM
Booster

Hi @mansarius ,

 

Rest assured, why you're trying to do is not easy as hotspot editiong should probably further down your list of things to learn 😁

The answer that you're looking for is explained in the Reference Guide under the chapter "Graphical Editing Using Hotspots" but you've likely already read it as you've mixed two parameters in your type 2 hotspots2.

 

Before going into your issue, two things :

- if you use the poly2_b command, you do not need to use line2. poly2 commands manage both linework and fill and to do so you need to give them a frame_fill value of 3 or 1+2. The reason why you don't see your linework is because your frame_fill is 2 (only fill is displayed) and you gave all the nodes a 0 status (which won't display any linework even if the frame_fill is 3). Switch the 0s to 1 to display the lines and you will optimize your code already.

- you could fuse several lines that are related by using colons so this :

 

HOTSPOT2 0, B, unID, B, 2
unID=unID+1

 

will become that :

 

HOTSPOT2 0, B, unID, B, 2 : unID=unID+1

 

 

Considering you will likely have plenty of hotspots2 for what you want to do, it will clean up your code significantly.

 

Ok so now on to your issue. Your problem is two fold : you want each corner to behave independently from each other while your rectangle still use A and B as main dimensions. As hotspots are related to only one dimension and you need two to move in 2 dimensions, then the answer is to create two parameters per nodes that will add a delta to the rectangle's nodal coordinates.

 

Below, is an example for one node only (the first one on the bottom left that I named n1). I created two new parameters for this that I named n1_dx and n1_dy.

 

pen gs_cont_pen
fill gs_fill_type

unID = 1

! Make node 1 stretchable

hotspot2 0, n1_dy, unID, n1_dx, 1+128 : unID=unID+1
hotspot2 -1, n1_dy, unID, n1_dx, 3 : unID=unID+1
hotspot2 n1_dx, n1_dy, unID, n1_dx, 2 : unID=unID+1
hotspot2 n1_dx, 0, unID, n1_dy, 1+128 : unID=unID+1
hotspot2 n1_dx, -1, unID, n1_dy, 3 : unID=unID+1
hotspot2 n1_dx, n1_dy, unID, n1_dy, 2 : unID=unID+1

! Adds deltas for x and y for each of n1's coordinates

poly2_b	5, 1+2, gs_fill_pen, gs_back_pen,
		0+n1_dx, 0+n1_dy, 1,
		0, b, 1,
		a, b, 1,
		a, 0, 1,
		0+n1_dx, 0+n1_dy, -1 

 

 

Basically, the two delta parameters for n1 subtract or add to n1's coordinates according to their respective values. On the poly2_b coordinates, I willingly wrote "0+n1_dx" so you could understand that but you do not need the "0+" there, it's redundant. If you want all 4 nodes to move independently, you will then need to create 6 additional parameters and create 3 new sets of hotspots2 for n2, n3 and n4.

 

Also for your type 1 parameters, it's not necessary to make them editable. They are usually hidden (+128) except for specific cases.

 

Hope that my explanations were clear 🙂

https://mfbim.fr | https://youtube.com/@mfbim
AC21 FRA 3005 - AC24 FRA 7600 - AC26 FRA 4027 | MacBook M1 Pro
mansarius
Participant

Wow! Thank you @MF BIM, this was exactly the answer I was looking for. Now I understand that A and B reference will always make width and height adjust because it is Dimension 1 and 2, so by creating an individual parameter for each hotspot it will work like I wanted. By this logic I understand that I also can use only x or y for each hotspot if I want to. This is perfect!

 

I will check out the cookbook. Looking forward to learn more scripting!

Just wait till you discover you can use stretchy hotspots in 3D as well!

 

The Cookbook, although old now, is still an excellent source of knowledge.

That is what I learnt with and I still refer to it from time to time.

 

https://community.graphisoft.com/t5/Developer-forum/Re-GDL-version-4-Cookbook-what-happened/m-p/3299...

 

Barry.

One of the forum moderators.
Versions 6.5 to 27
Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
Lingwisyer
Guru

The fun times of working with editable hotspots on a sphere!

AC22-23 AUS 7000Help Those Help You - Add a Signature
Self-taught, bend it till it breaksCreating a Thread
Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660
Learn and get certified!