Jump to content

giving object a unique name/number


Recommended Posts

how can I create a script that develops an object of a certain type and class and automatically gives it a name and number. The name I want via info palette as a prefix type, followed by a sequential number. Of course there should also be an option to reset the number so that I can add again to number.

 

Thanks for the help

Pascal

Link to comment

Hello Pat

 

Thanks for the help you want to give me.

I try to describe what I want.

 

It's actually about making a measurement statement for 2d drawings. In the facade I now draw surfaces for the different facade elements with rectangles. I now manually enter a name for these rectangles via the PIO and then I can retrieve the name of that rectangle and the dimensions to retrieve the m2 via spreadsheet. So now I have to draw the rectangle every time and then manually enter a name. So I wondered if I could create that name by, for example, a kind of stamp. But then a stamp that is immediately linked to that rectangle. Then I don't have to do that manually for every rectangle. The order of the numbering is actually determined according to the click on the rectangle or object that I click. I hope this is clear?

 

Pascal

Link to comment

You could have a script traverse all the rectangles in that layer, and number them in sequence for you. On default that would be stacking order, but you could also use coordinates to define the order instead, like relative position.

Link to comment

Here is a script with the basics but It works and should give you some ideas on how to improve it.

 

The biggest thing it needs is a way to check that a name is not already in use as VW will only allow a single object to have a name. Also, as is it only does the number not the prefix.

 

If you hold down the Command key when you click on an object it will ask you for the number to give that object and then start incrementing from there for the next clicked object.

 

Ask again if you need more help.

 

Procedure PickAndName;

Var	H1:	Handle;
	X1,Y1,Z1, X2,Y2: Real;
	N1: Integer;
	B1, B2: Boolean;
	
Function CallBack(Hd1:Handle):Boolean;
	Begin
		If GetType(Hd1)=3 then CallBack:=True;
	End;
	
Begin
	N1:=1;
	B2:=False;
	While B2 = False do
		Begin
			TrackObjectN(0, CallBack, H1, X1,Y1,Z1);
			If H1 <> Nil then
				Begin
					If Command then N1:=IntDialog('Enter Number for this Object.', Num2Str(0,N1));
					SetName(H1,Num2Str(0,N1));
					N1:=N1+1;
				End
			Else	B2:=True;
		End;
End;

Run(PickAndName);

 

Link to comment

hello pat

Thank you very much for the script you made for me. It looks very good and is already moving in the direction I want. But I still had a few questions.

1. I now see that it only works on rectangles, can this also be extended to other 2d shapes?
2. Could there be a field somewhere where I could enter a prefix, followed by the automatic number?

3. Suppose I have 2 shapes whom I want to call "wall" 1 and "wall" 2.
Then I want to number further with "window" 1 and "window" 2. How can I reset the numbers?

If these things were possible, I would have a very strong script for making my measurement statements for the drawings that are still drawn in 2d.

Thanks again for the help.
Pascal

Link to comment

Yes it can be extended to other shapes.

 

GetType(Hd1)=3. is the part that defines the object type. You can OR these together to get what you want.  ((GetType(HD1)=3) or (GetType(HD1)=4)) will highlight over Rectangles and Ovals (circles).  See the Vectorscript Appendix (click the link at the top of the page or look in your Applications Folder:Vectorworks 2020:VW Help: Script Reference) for other object types.

 

You can certainly add a prefix. Just have to define it.  Something like SetName(H1, Concat('TisMacFan-',Num2Str(0,N1)));  You could store it in a variable and CONCAT the variable instead of hard coding it. Or you could create a custom dialog box (or use two dialog boxes) to allow you to enter the prefix the same way you enter the number holding down the command key.

 

Hold down the Command Key when you click on an object and it will ask for the Number for the next object.

 

HTH

Link to comment

Hello Pat

 

The first thing to select different shapes has I managed with your tip, but the second

"You can certainly add a prefix. Just have to define it.  Something like SetName(H1, Concat('TisMacFan-',Num2Str(0,N1)));  You could store it in a variable and CONCAT the variable instead of hard coding it. Or you could create a custom dialog box (or use two dialog boxes) to allow you to enter the prefix the same way you enter the number holding down the command key."  I don't understand how to start with it.  

I like to work with a variable, or with to dialogboxes

So I hope you can help me a little bit further with this part of the script

Pascal

Link to comment

This version includes the ability to add a prefix.

 

If you hold down the Command Key when you click on a highlighted object, you will not get two dialog boxes, the first will ask for the number to use for that object, the second will ask for the Prefix to use. The prefix will then be used for all future objects until you change it.

 

The number is reset to 1 each time you run the script. The prefix is reset to nothing (empty string) each time the script is run.

 

Procedure PickAndName2;

Var	H1:	Handle;
	X1,Y1,Z1, X2,Y2: Real;
	N1: Integer;
	B1, B2: Boolean;
	S1: String;
	
Function CallBack(Hd1:Handle):Boolean;
	Begin
		If GetType(Hd1)=3 then CallBack:=True;
	End;
	
Begin
	N1:=1;
	B2:=False;
	While B2 = False do
		Begin
			TrackObjectN(0, CallBack, H1, X1,Y1,Z1);
			If H1 <> Nil then
				Begin
					If Command then 
						Begin
							N1:=IntDialog('Enter Number for this Object.', Num2Str(0,N1));
							S1:=StrDialog('Enter Prefix for String', S1);
						End;
					SetName(H1,Concat(S1,Num2Str(0,N1)));
					N1:=N1+1;
				End
			Else	B2:=True;
		End;
End;

Run(PickAndName2);

 

Link to comment
  • 2 months later...

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