RecalculateSizes in the middle of a script

I’m trying to write a little script that allows me to size entities to my liking. One of the first steps is to set RecalculateSizes = true. After this, I want set it back to false and do my own sizing. All of my sizing is vertical. The issue is that setting it to true doesn’t update the width like I want. Is there a way to force the resize in the middle of a script?

Thanks for reading!

Hi,

can you send us the script, please? You can attach it here or send it to modeling@quest.com.

BTW: do you call Model.RefreshModel() at the end of your sizing script execution?

Regards,

Vaclav

function Main(){

var App = System.GetInterface(“Application”);

var Model = App.ActiveModel;

var WS = App.ActiveWorkSpace;

var Log = System.CreateObject(“Log”);

if(Model==null) return;

if(WS==null) return;

var i, SelectObject, Entity, lines, a, Attribute;

for(i=0; i<This.Count;i++)

{

SelectObject = This.GetObject(i);

if (SelectObject.ObjectType == 2502) //entity shape on WorkSpace

{

SelectObject.Lock();

Entity = SelectObject.ParentBase;

Entity.Lock();

//Log.Information(Entity.Name + " = " + SelectObject.measuretext())

SelectObject.Lock();

SelectObject.RecalculateSizes = true;

//SelectObject.SetModified(true);

SelectObject.Unlock();

Model.RefreshWorkspace(WS.Id);

Log.Information("Display Mode = " + SelectObject.DisplayMode);

lines = 1;

for (a=0; a<Entity.Attributes.Count; a++) // iterate attributes

{

Attribute = Entity.Attributes.GetObject(a);

if (Attribute.IsPrimaryKey == 1) // check if attribute is PK

{

if (SelectObject.DisplayMode > 1)

lines += 1

}

else

{

if ((Attribute.FKForeignKeys.Count !=0) && (SelectObject.DisplayMode > 2))

lines += 1

else

{

if ((Attribute.Unique) && (SelectObject.DisplayMode > 3))

lines += 1

else

{

if (SelectObject.DisplayMode == 5)

lines += 1

}

}

}

}

if (lines == 1) lines = 1.5;

Log.Information("Lines = " + lines);

SelectObject.RecalculateSizes = false;

SelectObject.Height = Math.round(((SelectObject.FontHeight * -1.4 * lines) - (SelectObject.FontHeight / SelectObject.FontSize * SelectObject.PenWidth)));

Entity.Unlock();

SelectObject.Unlock();

//Model.RefreshWorkspace(WS.Id);

}

}

Model.RefreshWorkspace(WS.Id);

}

To see what I want, run the script on an entity that has recalculate active. It will shrink or grow the height. Now resize the same entity. Run it again. Only the height is modified even though the script tried to activate recalculate.

Hi,

the matter is a bit more complicated due to the method how and when lines are drawn. Probably the best possible solution is to split the code into two macros. In first macro se the Recalculate Size to true. In the second do the rest.

Explanation: Recalculate Size is not executed immediately during script execution, but after all messages in application/graphics queue are processed. In result, the custom script finishes before Recalculate Size is executed. In your case, the recalculate size is set back to false.

I hope it helps,

Vaclav & Petr