Han-Symbol replace

From Vectorlab
Jump to: navigation, search


Replaces all instances of a symbol definition through another. Accepts strings. By Orso B. Schmid


{ Orso *********************************************** }
{ replaces all instances of a sym definition on drawing }
{ eventually keeps sym properties }
PROCEDURE H_SymReplace(oldSymDef, newSymDef: STRING; deleting, keepingProps: BOOLEAN);
	VAR
		oldSymDefH, newSymDefH, groupH: HANDLE;
		insertMode, breakMode : INTEGER;
		className : STRING;
		
	
	{ this ensures that the instances on drawing don't mess up }
	PROCEDURE Sym_SwapInstance(h: HANDLE);
		BEGIN
			SetHDef(h, newSymDefH);
		END;
		
	BEGIN { H_SymReplace }
		oldSymDefH := getObject(oldSymDef);
		newSymDefH := getObject(newSymDef);
					
		IF (oldSymDefH <> NIL) & (newSymDefH <> NIL) & (oldSymDefH <> newSymDefH) THEN BEGIN
			ForEachObject(Sym_SwapInstance, (INGROUP & INSYMBOL & INVIEWPORT & (S = oldSymDef)));
				
			IF keepingProps THEN BEGIN
				GetSymbolOptionsN(oldSymDef, insertMode, breakMode, className);
				SetSymbolOptionsN(newSymDef, insertMode, breakMode, className);
			END;
			
			IF deleting AND (Count(S = oldSymDef) = 0) THEN
				DelObject(oldSymDefH); { Deletes sym definition }
		END;				
	END; { H_SymReplace }