Jump to content

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 <>
Link to comment

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.

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