Jump to content
Mickey

Mass Class renaming

Recommended Posts

I asked about this a few years ago, and there was nothing possible. That was back in V11. So I ask again.

When I bring an autocad file it brings with it sometimes thousands of classes. If they would just use a dash instead of a space it would sub class them so much better.

See below for a partial list of classes in one document.

classes.jpg

What I want to do is assign these to the class "Set-" and have them keep all the rest of their class name.

Any idea if that's possible?

Share this post


Link to post

VW2009 (and I think VW2008) do have an option to automatically add a prefix when you import a DWG/DXF.

Even better, you can now use Design Layer Viewports to encapsulate the autocad layers in a single file so they don't add to your class list in your working file.

Share this post


Link to post

Mickey, it's your lucky day: I happen to be in a good mood!

Instead of adding a prefix when importing, one can rename existing classes with a script

PROCEDURE RenameClasses; { ? Petri Sakkinen 1997 } 

VAR
className, newName, firstPart, secondPart : STRING;
i, n : INTEGER;
BEGIN
FOR i:=3 TO CLASSNUM DO BEGIN
	className:=CLASSLIST(i);
	n := POS(' ', className);

	firstPart := COPY(className, 1, n-1);
	secondPart := COPY(className, n+1, LEN(className));
	newName:=CONCAT(firstPart, '-', secondPart);
	RENAMECLASS(className, newName);
END;
END;

RUN(RenameClasses);

Share this post


Link to post

Excuse my ignorance. I created a new script in my object resource browser, but I don't think I'm filling out the script correctly. Am I supposed to list all the class names that need to get re-named?

Mickey, it's your lucky day: I happen to be in a good mood!

Instead of adding a prefix when importing, one can rename existing classes with a script

PROCEDURE RenameClasses; { ? Petri Sakkinen 1997 } 

VAR
className, newName, firstPart, secondPart : STRING;
i, n : INTEGER;
BEGIN
FOR i:=3 TO CLASSNUM DO BEGIN
	className:=CLASSLIST(i);
	n := POS(' ', className);

	firstPart := COPY(className, 1, n-1);
	secondPart := COPY(className, n+1, LEN(className));
	newName:=CONCAT(firstPart, '-', secondPart);
	RENAMECLASS(className, newName);
END;
END;

RUN(RenameClasses);

Share this post


Link to post

Ahh! That script renames all classes with a space in their names. (A quick modification of a stock script that I sometimes use immediately after import.)

This is a bit cleverer: it renames only classes with names starting with the trigger string.

PROCEDURE RenameClasses; { ? Petri Sakkinen 1997 - 2009 } 
CONST
trigger = 'Set '; { change this as needed - note the space! } 
replacement = 'Set-'; 

VAR
className, newName : STRING;
i, j, n : INTEGER;

BEGIN
j := LEN(trigger);  
FOR i := 3 TO CLASSNUM DO BEGIN
	className := CLASSLIST(i);
	n := POS(trigger, className);
	IF (n=1) THEN BEGIN 
		newName := className; 
		DELETE(newName, 1, j);  
		RENAMECLASS(className, CONCAT(replacement, newName)); 
	END; 
END;
END;

RUN(RenameClasses);

Share this post


Link to post

hi, i don't understand any of the above. I am struggling with the class mapping dialogue tool. How do I run a script and where do you get it?

I hoped once I had saved a few class mapping files I could re-use them on many autocad drawings. Sadly each new drawing from each new consultant with all their xrefs bring in a huge array of nonsensical encrypted garbage classes (totally counterproductive by making it too complicated to apply any discipline so that nothing is in its correct layer and the drawing is a clumsy useless bag of poo). I have to merge this tosh with my sensible, plain english, set of classes each time.

I was going to ask if there was a way of introducing a wildcard to cover say the front part of an xref set but i see the discussion is more sophisticated already. But can anyone assist? Also - I'm only on VW 12.0.1 Is the answer simply to upgrade?

Share this post


Link to post

Renardruse, there is another way of mapping Classes.

When you import a DWG there's an option under the Graphic Attributes tab called 'Add prefix to imported layers' (don't ask me why it's under the Graphic Attributes tab). Check this and specify a prefix and this will allow you to map all classes to a new top level Class.

Doesn't allow you to map individual Classes as Class Mapping does but it may suit your purposes.

Share this post


Link to post

That's a pretty awesome Script...looking at making it more user friendly with input dialogs for what the 'trigger' and the 'replacement' could be..

Share this post


Link to post

So I added dialog boxes so anyone can just type in the strings of text that need replacing...

PROCEDURE FindRenameClasses; { Modded by Andrew Chau based on Renameclasses by ? Petri Sakkinen 1997 - 2009 } 

VAR
className, newName, cs1, cs2 {cs1 is the trigger or to be replaced, cs2 is the replacement} : STRING;
i, j, n : INTEGER;

BEGIN
cs1:=StrDialog(Concat('Find text string in class name to rename...',Chr(13),Chr(13),'Find:'), 'S_');
IF NOT DidCancel THEN cs2:=StrDialog(Concat('Rename text string in class name...',Chr(13),Chr(13),'Replace:'),'X_S-');
j := LEN(cs1);  
FOR i := 3 TO CLASSNUM DO BEGIN
	className := CLASSLIST(i);
	n := POS(cs1, className);
	IF (n=1) THEN BEGIN 
		newName := className; 
		DELETE(newName, 1, j);  
		RENAMECLASS(className, CONCAT(cs2, newName)); 
	END; 
END;
END;

RUN(FindRenameClasses);

Edited by Ajychau
  • Like 1

Share this post


Link to post

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.


 

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.

×
×
  • Create New...