Adding an LabelQuadrangle to a Workspace

I'm trying to Create a script standardisess the look of our models to that end I want to be able to add a Text Box in the Upper Left hand corner of All those Models.

In the text box I want to display specific information so that thing like the author, last update date etc are in line of site of the viewer.

However I'm really struggling with this one.

I can create Label but I just can't get the label onto each or any of the workspaces.

I just don't seem to be able to;

  • create the workspace shape without it creating an TDM exception
  • set the ParentBaseID of the label for a Workspaceshape object

Help Please :frowning:

Hi Sandy,

Can you show me your existing script?

Thank you
Petr

Hi Petr,

Here is the latest code that I gave up on;

//WorkSpace = Model.Workspaces.GetObjectByName("All Items")

//Log.Information("Workspace = "+WorkSpace.Name);

//ShapeList = WorkSpace.List;

//WorkSpaceShapeLabelQuadrangle = WorkSpace.CreateNewObject(1510);

//WorkSpaceShapeLabelQuadrangle.Name = "DEInformationBox";

//WorkSpaceShapeLabelQuadrangle.UseWorkSpaceRecalculateSizes = 0;

//WorkSpaceShapeLabelQuadrangle.Height = 1000;

//WorkSpaceShapeLabelQuadrangle.Width = 500;

//WorkSpaceShapeLabelQuadrangle.Top = 50;

//WorkSpaceShapeLabelQuadrangle.Left = 50;

//Label = Model.CreateNewObject(1077);

//Label.Name = "ModelInformation";

//Label.Text = "The quick brown fox";

//NewObject = WorkSpace.CreateNewObject(1510);

//NewObject.Name = "Stuff";

//NewObject.ParentBaseID = Label.Id;

I tried looking at the XML that was produced when I did it manually but just couldn’t reproduce it.

The WorkspaceShapeLabelQuadrangle seems to get created but it gives an exception error. I can see the resultant elements and attributes appear in the XML.

Below is the kind of thing I want as a text box.

image002.jpg

Regards

Sandy

Hi Sandy,

You can inspire by the following script:

var WorkSpace = Model.Workspaces.GetObjectByName("All Items")
var labR = Model.CreateNewObject(1077);
labR.Name = 'testName';
labR.Text = 'text';
var WSlabR = WorkSpace.NewWorkSpaceShape(1510, labR);
WSlabR.Name = labR.Name;

Regards
Petr

Hi Petr,

That worked a treat.
However I don't seem to be able to find a method or property to align your text to the left. Is there one?

Hi Sandy,
unfortunately there is no setting to align text in label rectangle to left.
Maybe you can use instead text label just t a text. And if you want to have rectangle around you can combine it with rectangle. So script will be similar

function main(){
  var WorkSpace = Model.Workspaces.GetObjectByName("All Items")
  var SimpleText = Model.CreateNewObject(1076);//Simple Text
  SimpleText.Name = 'testName';
  SimpleText.SimpleText = 'text as asd f f \r\n fasdf asdf';
  var wsSimpleText = WorkSpace.NewWorkSpaceShape(1509, SimpleText);
  wsSimpleText.Name = SimpleText.Name;
  
  var Rect = Model.CreateNewObject(1074);//Rectange  
  var wsRect = WorkSpace.NewWorkSpaceShape(1507, Rect);
  wsRect.ZOrder = -10; //We want to rectangle will be always on backward 
}

Regard
Petr