Jump to content
matteoluigi

vs.GetSpaceNameForObj/vs.GetSpaceNumForObj

Recommended Posts

Hi,

we still are working again on Secondlevel Space Boundaries for Space Objects. (

However I think about solving the issue with a Python-script. In Worksheets there exists the function GetSpaceNameForObj and GetSpaceNumForObj.

I have been looking for it in the Vectorscript/Python function reference, without any success... 

Quote

SpaceName = vs.GetSpaceNameForObj(HNDL)

SpaceNum = vs.GetSpaceNumForObj(HNDL)

obviously don't exist.

 

Guess the commands only exist for Worksheets, right? Is there any possibility to coordinate an object to the adjacent space object?

 

 

Share this post


Link to post

@matteoluigi ,

   Have you tried querying the PIO record for the name and number?

 

SpaceName = vs.GetRField(vs.FSActLayer(), 'Space', 'Name')

SpaceNum = int(vs.GetRField(vs.FSActLayer(), 'Space', 'Number'))

 

And if you need it,

SpaceArea = vs.Str2Num(vs.GetRField(vs.FSActLayer(), 'Space', 'Area'))
 

HTH,

Raymond

Share this post


Link to post
8 hours ago, MullinRJ said:

SpaceName = vs.GetRField(vs.FSActLayer(), 'Space', 'Name')

SpaceNum = int(vs.GetRField(vs.FSActLayer(), 'Space', 'Number'))

nope, sorry but both worksheet functions don't check the name or number of a selected space but they get me the name or number of a space the selected object is situated in.

For example GetSpaceNameForObj can get me Name and Number of the space-object a selected furniture-symbol is planned in.

 

Pity, that the function obviously only works in worksheets, not in Vectorsript/Python

Share this post


Link to post

@matteoluigi ,

   Sorry, I misunderstood the question and the nature of the WS functions. Here is a short Pascal script, lightly tested,  that searches every Space object in the drawing and tests if the object passed to the function is inside any Space. Now the functions I posted earlier will return the correct results AFTER the new function is called which returns the appropriate Space handle.

 

   It shouldn't be too hard to Pythonize the script. As a simplification, I am using the center point of the referenced object to make the test, and not testing the object's bounding box. Feel free to modify this to your heart's content.

 

PROCEDURE xxx;
{ Script to test the ObjInSpace function. }
{ 14 Mar 2021 - Raymond Mullin }
VAR
	H0, SpaceH :Handle;
	SpaceNum :Integer;
	SpaceName :String;


	function ObjInSpace(H :Handle) :Handle;
	{ Return a handle to the Space object that contaons object H, or NIL if none is found. }
	{ 14 Mar 2021 - Raymond Mullin }
	Var
		SpaceH :Handle;
		X, Y :Real;
	
		procedure InSpace(SpcH :Handle);
		Var
			RecH, PolyH :Handle;
		Begin
			RecH := GetParametricRecord(SpcH);
			if (RecH <> nil) & (GetName(RecH) = 'Space') then begin
				PolyH := Space_GetGrossPoly(SpcH);
				if PtInPoly(X, Y, PolyH) then
					SpaceH := SpcH;
			end;		{ if }
		End;		{ InSpace }

	Begin		{ ObjInSpace }
		hCenter(H, X, Y);
		SpaceH := nil;
		ForEachObject(InSpace, T=86);
		ObjInSpace := SpaceH;
	End;		{ ObjInSpace }


BEGIN
	H0 := FSActLayer;
	
	SpaceH := ObjInSpace(H0);
	if (SpaceH <> nil) then begin
		SpaceName := GetRField(SpaceH, 'Space', 'Name');
		SpaceNum := Str2Num(GetRField(SpaceH, 'Space', 'Number'));
		message(SpaceName, '  ', SpaceNum);
	end		{ if }
	else message('Selected object is not contained in any Space objects in the drawing.');

	SysBeep;
END;
Run(xxx);

 

HTH,

Raymond

 

  • Like 2

Share this post


Link to post
Posted (edited)
Quote

def ObjInSpace(SpaceH):

 

             def InSpace(SpcH):

                          RecH = vs.GetParametricRecord(SpcH)

                          RecHN = vs.GetName(RecH)

 

                          if ((RecH !=  '') & (RechN == 'Space')):

                                       PolyH = vs.Space_GetGrossPoly(SpcH)

                          if vs.PtInPoly(X, Y, PolyH):

                                       SpaceH = SpcH

             

             X,Y=vs.HCenter(SpaceH)

             SpaceH = ''

             vs.ForEachObject(InSpace, 'T=86')

             ObjInSpace = SpaceH

 

H0 = vs.FSActLayer()

SpaceH = ObjInSpace(H0)

if (SpaceH !=  ''):

             SpaceName = vs.GetRField(SpaceH, 'Space', 'Name')

             SpaceNum = vs.Str2Num(vs.GetRField(SpaceH, 'Space', 'Number'))

             vs.AlrtDialog(vs.Concat(SpaceName, '  ', SpaceNum))

if (SpaceH ==  ''):

             vs.AlrtDialog('Selected object is not contained in any Space objects in the drawing.')

I tried to pythonize it, but it won't work to the end 😉 what's wrong?

 

The compiler says:

Traceback (most recent call last):

"File "<string>", line 11, in InSpace

NameError: name 'Rechn' is not defined

 

Edited by matteoluigi

Share this post


Link to post

The variable in Raymonds script it RecH (Record Handle).  If the error message actually says Rechn, then you have a typo or have changed the variable name.

 

And Python cares about capitalization (IMNSHO a really stupid thing to do in a programming language.) The last line of your quote shows RecHN. The error message says Rechn.  I believe those would be considered different variables.

 

That is part of why I am sticking to Pascal as long (or longer) than possible.

  • Like 2

Share this post


Link to post
Posted (edited)

Hello @matteoluigi

   Pat's right, there is a typo.

 

                          if ((RecH !=  '') & (RechN == 'Space')):
 

should read:

 

                          if ((RecH !=  '') & (RecHN == 'Space')):
 

HTH,

Raymond

 

Edited by MullinRJ
  • Like 1

Share this post


Link to post
On 3/20/2021 at 12:08 AM, MullinRJ said:

RecHN

thanks for helping an old myopic man by correcting his simple syntax-errors 😉 

 

However, I still don't understand various things and so I don't get to pythonize the code that easily :

1) I try to call the function "ObjInSpace" with the command "SpaceH = ObjInSpace(H0)". In my opinion I give over the Handle of the previously selected Object H0 = vs.FSActLayer() to the function that way. (that's what you intended to do)

 

2) however you start the function wit the command "function ObjInSpace(H :Handle) :Handle" is my variant right: def ObjInSpace(SpaceH):? Imo, SpaceH is the "key Handle" in the "ObjInSpace"-function, so, I chose "SpaceH" and not "H" as Handle

however, the Handle "H" never gets mentioned in your whole code. Why? (and, however, your Code WORKS. I already tested it.) 

 

3) if (SpaceH !=  ''):  is the right correspondent code to if (SpaceH <> nil) then begin in Pascal, right? ('' of course are 2 single quotation marks 😉)

 

then still I'm not 100% sure if the sequence of my code is ok that way, although it definitely is the same as in other Python scripts, where I called a "foreach"-function...

It just feels a little strange first writing the function and then the main program. So you did with the foreach-"subfunction" in your code as well.

It's like:

 

def ObjInSpace(SpaceH):

             def InSpace(SpcH):

                    def InSpace-Code

 

             def ObjInSpace-Code

 

Main Code

SpaceH = ObjInSpace(H0)

 

right?

Sorry for my complex questions, I don't have the time for controlling my code more accurately at work and at home, too.

 

Share this post


Link to post

... I replaced "T='86' " with "PON='SPACE' "... so, only spaces are related, no more walls, slabs,... however, it wasn't enough...

Share this post


Link to post

@matteoluigi ,

   Try this Python conversion. I used your PON='Space' suggestion for the criteria, since it simplifies the runtime. Also note that you have to declare SpaceH as a global variable, since it cannot be passed in the function's calling parameter list. This may be why it wasn't working for you.

 

import vs

# Script to test the ObjInSpace function.
# 14 Mar 2021 - Raymond Mullin

# GOLBALS
NIL = vs.Handle()		# constant for readability
SpaceH = NIL			# initialize variable


def ObjInSpace(H1):
# Return a handle to the Space object that contaons object H, or NIL if none is found. 
# 14 Mar 2021 - Raymond Mullin 

	def InSpace(SpcH):
		global SpaceH
		RecH = vs.GetParametricRecord(SpcH)
		if (RecH != NIL):
			PolyH = vs.Space_GetGrossPoly(SpcH)
			if vs.PtInPoly(X, Y, PolyH):
				SpaceH = SpcH

	X, Y = vs.HCenter(H1)
	vs.ForEachObject(InSpace, "PON='Space'")
	return SpaceH


H0 = vs.FSActLayer()
SpaceH = ObjInSpace(H0)

if (SpaceH != NIL):
	SpaceName = vs.GetRField(SpaceH, 'Space', 'Name')
	SpaceNum = int(vs.Str2Num(vs.GetRField(SpaceH, 'Space', 'Number')))
	vs.Message(SpaceName, '  ', SpaceNum)
else:
	vs.Message('Selected object is not contained in any Space objects in the drawing.')

vs.SysBeep()

 

HTH,

Raymond

 

  • Like 2

Share this post


Link to post

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.


 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...