Jump to content
rebu1985

Script to get a Space function when you point the area defined by objects "help"?

Recommended Posts

Hi guys,

 

I would like to create a script similar than the SPACE function but instead of creating the polygon manually I would like to point an area and get the space called room defined by objects called walls. My main point is to save time to calculate square meters of different rooms of a flat.

Thanks guys!!

 

Laura

Share this post


Link to post

Scripting wise it's easy, but a math challenge is always fun.

 

Start with listing all walls and their absolute start/mid/end coordinates in a struct array.

Find the wall that is closest to this point by comparing coordinates. Also make sure you also check the midpoints when comparing as you could otherwise start with the wrong T junction wall segment, if that T junction is the closest point, owned by multiple walls.

 

Next compare the wall with other walls to find adjacent walls and recursively keep doing this until you find the first wall piece again. Check handles to verify.

- If you are at a junction, you need the choose the closest wall from the available options, again compare by midpoint.

- If you don't find the original object again, you are trying to create a point in a none closed shape.

- If you do find a closed wall shape, verify the point lies within the polygon formed by these walls, otherwise the point lies outside the building contours and the shape should be invalid.

 

Edited by Hippocode

Share this post


Link to post

Thanks for your help but i think what i need its easier because i have used simple 2d rectangles as walls.

What i was thinking it was to create a script to define a polyline as the contours when you point the area predefined by the rectangles and then use another script to convert to space or using the function convert objects to shapes.

Share this post


Link to post

If you have Architect or Designer and are using VW Walls, there is already a command (AEC:Space Planning:Spaces from Walls) that does close to what you want.

 

Also, if you are not using VW walls, be very careful with your names. Vectorworks will only allow one object to have a name. If you draw a polygon and name it "Wall", then you will not be able to use VW wall objects in the drawing. Similar with Door, Window, etc.

Share this post


Link to post

What about using the Polygon tool (second mode button - Bucket)? 

 

Try this short script and tell us if it works, or if you need something else.

PROCEDURE xxx;
VAR
	H :Handle;
BEGIN
	H := LActLayer;
	CallToolwithMode(-207, 1, 2);		{ Polygon tool, Bucket mode }
	
	{ if bucket mode succeeds, continue }
	if (H <> LActLayer) then begin		
		Message('Area = ', HAreaN(LActLayer));
		DelObject(LActLayer);
	end
	else begin
		Message('The area you clicked in was not closed. Try again.');
		SysBeep;
	end;
END;
Run(xxx);

Of course if you want to do something with the numbers beside write them down, you could finesse this approach a little more.

 

Raymond

Edited by MullinRJ
Added error checking to script.

Share this post


Link to post

Thank you guys for your help!!

 

I have created this script but I would like to ask you 2 questions if you can help me :)

- I would like to show another extra class class called 0Door plus the active one 0Wall.

- I would like to show a label as the space function indicating the Room and the area. I was thinking to convert this script to Space but i am not sure what is easier and better. 

 

PROCEDURE xxx;
VAR
    H, H1 :Handle;
    Active_class : String;
BEGIN
    H := FActLayer;
    Active_class:= GetClass(H1);
    NameClass('0Wall');
    SetClassOptions(1);
    CallTool(-207);        { Polygon tool, Bucket mode }
    Message ('Area = ', HAreaN(FActLayer));
    DelObject(FActLayer);
END;
Run(xxx);

Share this post


Link to post

Convert the poly to the space, easiest way.

You can just create a new space, just assign the poly as path. Don't delete the poly afterwards as it becomes part of the space.

Share this post


Link to post

Thanks Hippocode,

 

I was thinking to do that or convert to property line as well.

I have created the script below but something is wrong because the second part of the script is not working.

- I would like to show the visibility on of class called 0Muros at the same time than the active class 0Sup and hide the others but when the script just works showing the visibility of the 0sup and all the others are hidden.

- I tried to add more classes as ShowClass((('0Muros') & ('0Muros2'))); but script indicates that i need a string. Could you help me, please?

 

PROCEDURE xxx;
VAR
    H :Handle;
    Active_class : String;
BEGIN
    H := FActLayer;
    Active_class:= GetClass(H);
    NameClass('0Sup');
    SetClassOptions(1);
IF ((GetCVis('Active_class')) = 0) THEN
    Begin
    ShowClass('0Muros');    
    CallTool(-207);        { Polygon tool, Bucket mode }
    DelObject(FActLayer);
end;
END;
Run(xxx);

Share this post


Link to post

Laura,
This is how your script reads:

1) Get a handle to the 1st object on the active layer.

2) Get the class of that object.

3) Change the Active Class to '0Sup'.

4) Change class options to ONLY show the Active Class, which is now '0Sup'.

5) Test if the class named 'Active_Class' is visible. This will always return TRUE when a class name does not exist, and I assume 'Active_Class' is not in your drawing.

 

Inside the IF:

6) Make class ''0Muros' visible. (This has no noticeable effect since the Class View Options are set to ActiveClass, and '0Sup' is the active class.)

7) Call the Polygon tool for one use. (The Polygon drawing mode is not specified and will draw in whatever the last Polygon mode was selected.) 

8) Delete the 1st object on the layer, whatever it is. (This may be desirable, or not, depending how you plan to use this tool.)

 

 

Comments:

A likely mistake:

IF ((GetCVis('Active_class')) = 0) THEN
should probably be written:

IF (GetCVis(Active_class) = 0) THEN

if you want to reference the string variable Active_class and not a class named 'Active_class'.
 

Next:

assigning the active class to string variable Active_Class is usually written as:

Active_class := ActiveClass;

 

The first object on the active layer may, or may not, be in the active class. It is not guaranteed.

However, since I am not sure what you are really intending, your code may do what you want.

 

Next:

To show multiple classes at the same time you cannot set the Class View Options to "Active Class Only". You will have to hide the classes you don't want to see.

This will require more extensive programming, since you will probably what to save the current visibility state, and restore it when you are done.

 

Next:

If you want the Bucket Mode of the Polygon tool you will have to explicitly ask for it.

CallToolwithMode(-207, 1, 2); { Polygon tool, Bucket mode }

If you want the last mode used, then your script does that.

 

Next:

The code as written will delete the 1st object on the layer. Each time you run it, something will disappear. 

I'm guessing this is not what you want. Your last line will need some work.

 

Suggestions:

1) Write your intended actions down on paper, in English (or your favorite language). Use this as your guide for the script.

 

2) When you get a line working,  add a comment to the right describing exactly what it does.

It comes in very handy later when you revisit your code, especially when numeric options are used in a line. This way you don't have to look up the meaning of the numbers each time. 

 

3) Use the Message() statement inline, or in a test script, to see how expressions evaluate.

Example: "Message(GetCVis('AnyUnusedClassName'));"

Note this will return 0, even when a class name doesn't exist.

<<Side effects happen!>>

 

4) Last tip – Visit here often. Help is free, and that's a good deal even at thrice that price.

 

HTH,

Raymond

Edited by MullinRJ

Share this post


Link to post

Thank you so much Mullin for you help, 

 

Using your script i have created two kind of scripts in case i need to use them individually. One does on/classes and the other uses the bucket mode. Its easier for me right now designing the scripts one per one to learn.

 

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...