Jump to content

WS Script Memory Problem


Recommended Posts

Hello,

 

i have a file with thousands of 3d ifc objects that are rotated in all kind of ways in 3d space. Now i want to sort them by their width, depth and height, so that i can sum them up. I tried to use the =WIDTH, = HEIGHT and =DEPTH functions in a worksheet, however the =DEPTH function gives wrong results when the objects are rotated in a specific way.

But because i know that in this case the objects dimensions follow this rule x >= y >= z, i wrote a simple WS scipt that uses

vs.Get3DInfo(obj)

, which gives me the right results for the dimensions and simply sort them by their value.

 

The problem is (apart from the ws beeing very slow, what was expected), that the script uses a lot of ram and even if the script is finished the used ram number of vw wont drop by much until i restart vw and if i run the script again it just adds to the previously used ram.

 

See below the WS Script that im using.

def get_xyz():
	# infos
	obj = vs.WSScript_GetObject()

	choice = vs.WSScript_GetPrmStr(0)
	if isinstance(choice, str):
		choice = choice.lower()

	# script
	nHeight, nWidth, nDepth = vs.Get3DInfo(obj)

	# choice
	if choice == "h":
		vs.WSScript_SetResReal(nHeight)
	elif choice == "w":
		vs.WSScript_SetResReal(nWidth)
	elif choice == "d":
		vs.WSScript_SetResReal(nDepth)

	else:
		vs.WSScript_SetResStr("Choice error!")

# run
get_xyz()

 

I think that the best solution would be to try to export the ifc objects (if possible) in a different way, so that the needed values are already attached to some record, but i am wondering if i am doing something wrong regarding the WS script?

 

Regards,

Letti

Link to comment

HI Letti R

 

you can try to use:

 

=MIN(WIDTH, HEIGHT,DEPTH)

=MEDIAN(WIDTH, HEIGHT,DEPTH)

=MAX(WIDTH, HEIGHT,DEPTH)

 

… maybe this can help you for sorting your rotated stuff in your Worksheet.

… but only if the objects are not diagonal in 3D space.

 

Greetings

Tobi

Link to comment

Hello,

 

thank you for your reply @Tobias Kern. Unfortunately this does not work, because DEPTH gives wrong values.

For example, lets say the object has x, y, z of 1, 2, 3. If WIDTH, HEIGHT, DEPTH would give scrambled values like, 2, 3, 1, this would be no problem because i can sort the values for example the way you pointed out. However i get results like 2, 3, 3 or 1, 2, 2 where one value (the value i get from DEPTH) is just wrong.

 

Interestingly the VS function

vs.Get3DInfo(obj)

seems to always give the correct values.

 

Regards,

Letti

Link to comment

Hello,

 

unfortunately i cant share the file.

This is my workarround, however i think it is not a good one:

 

I wrote a script that copies a duplicate of the object to another layer and rotates it, so that its edges are parallel to x, y, z. Then i read the bbox values and put them into a data record and attached it to the original object.

I think that this is a bad idea (in general) because the values in the records dont change automatically if the object changes, but in this case the objects dont get changed.

 

Interestingly  this script only takes some seconds to run and does not have memory issues at all, even if run multiple times. I wonder why the worksheet script takes so much longer, even if it does the same thing (or even less).

 

Regards,

Letti

  • Like 1
Link to comment

The worksheet version of the script has to run for every object that meets the criteria, so making it as compact as possible is important.

 

What happens if you remove the if...elif nesting and the GetParamStr sections and make three different versions of the script, one for each of the nVariables?

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...