Jump to content
avictorgm

New layers script + date + separation layer.

Recommended Posts

Hello,

 

I am glad that I can see some evolution in my skills.

And thanks to this forum I can manage more tedious work easy and nice.

 

In reward here is the first really useful script in vectorscript.

 

It creates some layers all together with date and different text. I hope you enjoy.

 

 

 

Notes:

-If the layer exist give back an alert and do not create the layer.

{///////////////////////////////////////////
CreateDifferentNewLayers V 1.3
with extra separation layer with date
By Ing. Victor Garzon (2018) distribute freely
avictorgm@gmail.com

Using as codebase from Vectorworks:
(c) 2001 Nemetschek North America. Distribute freely.

///////////////////////////////////////////}

PROCEDURE CreateDifferentNewLayers;
VAR
newname : STRING;
Rahmen : STRING;
LayA : STRING;
LayZERO : STRING;
LayB : STRING;
LayC : STRING;
LayD : STRING;
LayE : STRING;
LayF : STRING;
LayG : STRING;
LayH : STRING;


TextoAlert :STRING;
Texto1 :STRING;
Texto2 :STRING;
ch : HANDLE;
BEGIN
Texto1:= 'The Layer for the Stand ';
Texto2:= ' will be created at the top of the list';
newname:= StrDialog('Enter name of new layer:','Untitled Layer');
LayZERO:= Concat('-------', newname, Date(2,1), '--------------------');
IF NOT DidCancel THEN BEGIN
ch:= GetObject(LayZERO);
IF (ch = NIL) THEN
TextoAlert:= Concat(Texto1, LayZERO, Texto2);
Layer(LayZERO)
END
ELSE
AlrtDialog('Layer Layers created already exists.');


LayH:= Concat(newname, '_8_Frei');
IF NOT DidCancel THEN BEGIN
ch:= GetObject(LayH);
IF (ch = NIL) THEN
TextoAlert:= Concat(Texto1, LayH, Texto2);
Layer(LayH)
END
ELSE
AlrtDialog('Layer name already exists.');






LayG:= Concat(newname, '_7_Standfläche');
IF NOT DidCancel THEN BEGIN
ch:= GetObject(LayG);
IF (ch = NIL) THEN
TextoAlert:= Concat(Texto1, LayG, Texto2);
Layer(LayG)
END
ELSE
AlrtDialog('Layer name already exists.');
LayF:= Concat(newname, '_6_Traversen');
IF NOT DidCancel THEN BEGIN
ch:= GetObject(LayF);
IF (ch = NIL) THEN
TextoAlert:= Concat(Texto1, LayF, Texto2);
Layer(LayF)
END
ELSE
AlrtDialog('Layer name already exists.');
  LayD:= Concat(newname, '_5_Lasten');
IF NOT DidCancel THEN BEGIN
ch:= GetObject(LayD);
IF (ch = NIL) THEN
TextoAlert:= Concat(Texto1, LayD, Texto2);
Layer(LayD)
END
ELSE
AlrtDialog('Layer name already exists.');
LayE:= Concat(newname, '_4_Punkte');
IF NOT DidCancel THEN BEGIN
ch:= GetObject(LayE);
IF (ch = NIL) THEN
TextoAlert:= Concat(Texto1, LayE, Texto2);
Layer(LayE)
END
ELSE
AlrtDialog('Layer name already exists.');

LayA:= Concat(newname, '_3_Maße_Lasten');
IF NOT DidCancel THEN BEGIN
ch:= GetObject(LayA);
IF (ch = NIL) THEN
TextoAlert:= Concat(Texto1, LayA, Texto2);
Layer(LayA)
END
ELSE
AlrtDialog('Layer name already exists.');

LayB:= Concat(newname, '_2_Maße_Punkte');
IF NOT DidCancel THEN BEGIN
ch:= GetObject(LayB);
IF (ch = NIL) THEN
TextoAlert:= Concat(Texto1, LayB, Texto2);
Layer(LayB)
END
ELSE
AlrtDialog('Layer name already exists.');


       LayC:= Concat(newname, '_1_Maße_Träger');
IF NOT DidCancel THEN BEGIN
ch:= GetObject(LayC);
IF (ch = NIL) THEN
TextoAlert:= Concat(Texto1, LayC, Texto2);
Layer(LayC)
END
ELSE
AlrtDialog('Layer name already exists.');




END;

Run(CreateDifferentNewLayers);

 

Edited by avictorgm
insert <>

Share this post


Link to post

The script looks great.  You might want to put in some comments so you can figure out how it worked in 6 months.

 

Another idea. When you are editing a post, you will see the <> in the menu bar at the top of the edit screen. This is for entering code and have it located in a separate block. The nicest thing about this is that is understands indentation and does nor force everything to be left aligned.

 

If I take a snippet from your code above

 

LayH:= Concat(newname, '_8_Frei');

IF NOT DidCancel THEN BEGIN

ch:= GetObject(LayH);

IF (ch = NIL) THEN

TextoAlert:= Concat(Texto1, LayH, Texto2);

Layer(LayH)

END

ELSE

AlrtDialog('Layer name already exists.');

 

I would indent it something like as follows to make it easier to read. Code blocks let that happen.

 

LayH:= Concat(newname, '_8_Frei');
IF NOT DidCancel THEN 
	BEGIN
		ch:= GetObject(LayH);
		IF (ch = NIL) THEN
			TextoAlert:= Concat(Texto1, LayH, Texto2);
		Layer(LayH)
	END
ELSE
	AlrtDialog('Layer name already exists.');

 

Note that I put the begin on a new line rather than after the THEN. I like to keep my BEGINS and ENDS at the same indentation. For me this makes it much easier to figure out the code.

 

And my putting it in a code block, all you have to do is tell someone to select everything in the Code block and copy.  Many times someone will forget to copy the Procedure line or the Run line and then want to know why the script does not compile.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

 

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.

×