Jump to content
Developer Wiki and Function Reference Links ×

Rename Classes?


Recommended Posts

Here is an example;

PROCEDURE RenameClassName;

CONST

kTOT_CLASS = 20;

VAR

i: INTEGER;

curClass: STRING;

oldList: ARRAY[1..kTOT_CLASS] OF STRING:

newList: ARRAY[1..kTOT_CLASS] OF STRING:

PROCEDURE ChangeName(objHdl: HANDLE);

BEGIN

SetClass(objHdl,newList);

END;

BEGIN

oldList[1]:= 'old Name 1';

oldList[2]:= 'old Name 2';

.....

oldList[N]:= 'old Name N';

newList[1]:= 'new Name 1';

newList[2]:= 'new Name 2';

.....

newList[N]:= 'new Name N';

FOR i:= 1 TO kTOT_CLASS DO

BEGIN

curClass:= oldList;

ForEachObject(ChangeName,((C=curClass)));

END;

END;

Run(RenameClassName);

I added an extra step there by assigning the name to curClass but I prefer this because ForEachObject can sometimes fail if the search string is not passed in simple terms.

Link to comment
  • 2 weeks later...

oldList: ARRAY[1..kTOT_CLASS] OF STRING:

newList: ARRAY[1..kTOT_CLASS] OF STRING:

Hi Andrew,

???Both of these lines end in COLONS and should end in SEMICOLONS. They're typos. Change them as follows and you should be good.

oldList: ARRAY[1..kTOT_CLASS] OF STRING;

newList: ARRAY[1..kTOT_CLASS] OF STRING;

???The remaining errors are only due to the pseudo-code. Put in your specifics and it should compile.

???One thing to note when a compiler kicks an error, sometimes the error is on the immediately preceding line. If you can't find an error on the one reported, look at the previous one.

Raymond

Link to comment
  • 2 weeks later...

Thanks Miguel & Raymond,

I've got the following working as an example, which changes objects classed as 'A' to 'Z'. Unfortunately its not working on objects in symbols.

How might I modify this to include objects inside symbols?

PROCEDURE RenameClassName;

CONST

kTOT_CLASS = 50;

VAR

i: INTEGER;

curClass: STRING;

oldList: ARRAY[1..kTOT_CLASS] OF STRING;

newList: ARRAY[1..kTOT_CLASS] OF STRING;

PROCEDURE ChangeName(objHdl: HANDLE);

BEGIN

SetClass(objHdl,newList);

END;

BEGIN

oldList[1]:= 'A';

newList[1]:= 'Z';

FOR i:= 1 TO kTOT_CLASS DO

BEGIN

curClass:= oldList;

ForEachObject(ChangeName,((C=curClass)));

END;

END;

Run(RenameClassName);

Link to comment

Use ForEachObjectInList() and pass a handle to the first SymbolDef in the Symbol List.

Add the following line and create a similar function that filters object by class so that you don't change everything. This is in addition to the code you already have.

ForEachObjectInList(ChangeNameInSyms, 0, 2, FSymDef); { ALL objs, DEEP, SymDef List }

HTH,

Raymond

Link to comment
  • 6 months later...

Using the Script below to rename classes. Works great - but realized its changing the class setting to 'default' black pen, white fill, lineweight of 1 ect.

What could I remove/add from the script so that renamed class retains the same settings as the old one?

~A

PROCEDURE RenameClassName;

CONST

kTOT_CLASS = 300;

VAR

i: INTEGER;

curClass: STRING;

oldList: ARRAY[1..kTOT_CLASS] OF STRING;

newList: ARRAY[1..kTOT_CLASS] OF STRING;

PROCEDURE ChangeName(objHdl: HANDLE);

BEGIN

SetClass(objHdl,newList);

END;

BEGIN

oldList[1]:= 'WDA-Ext Door-Color 1';

newList[1]:= 'WDA-Ext Door-01';

FOR i:= 1 TO kTOT_CLASS DO

BEGIN

curClass:= oldList;

ForEachObject(ChangeName,(INSYMBOL & INOBJECT & INVIEWPORT & (C=curClass)));

IF Len(curClass) > 0 THEN

DelClass(curClass);

END;

END;

Run(RenameClassName);

Link to comment

You can do that like this.

Get the attribute of the old class and then set the attribute to the new class.

You still need to ad all the other attributes that you want to keep to this exaple though, this example only sets the fore and background fill color.

There's a list of Procedures in the FR under the "Classes" chapter. Most of them are about the attributes of the classes.

{/// cut ///}
	curClass:= oldList[i];
	IF Count(INSYMBOL & INOBJECT & INVIEWPORT & (C=curClass))<>0 THEN
	BEGIN
		GetClFillBack(curClass,red,green,blue);
		SetClFillBack(newList[i],red,green,blue);

		GetClFillFore(curClass,red,green,blue);
		SetClFillFore(newList[i],red,green,blue);

		{and so on}
	END;
	ForEachObject(ChangeName,(INSYMBOL & INOBJECT & INVIEWPORT & (C=curClass)));
{/// cut ///}

EDIT: or like Petri says, that would make it much easier and it will probable executes faster too.

Edited by maarten.
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...