Jump to content
Developer Wiki and Function Reference Links ×

Deleting a symbol definition from a file


Recommended Posts

Can anyone help explain how to delete a symbol definition from a file?

I have tried using both - DeleteResourceFromList (fldrlist,symindex);

and -DelName(symname); and neither one deletes the symbol defs from the resource browser.

Here is the subroutine that I thought should delete the symbol definitions using DeleteResourceFromList:

PROCEDURE DeleteOldSyms;

VAR
fldrlist, numitems,symindex : LONGINT;
symname : STRING;

BEGIN
fldrlist := BuildResourceList(16,0,'',numitems);

FOR symindex:= numitems DOWNTO 1

DO BEGIN
	symname := GetNameFromResourceList(fldrlist,symindex);
	IF (symname = 'Old Symbol 1') OR
	   (symname = 'Old Symbol 2') 
	THEN DeleteResourceFromList(fldrlist,symindex);
END;
END;

Does anyone know what I am doing wrong?

Link to comment
  • Vectorworks, Inc Employee

DeleteResourceFromList just removes the symbol from the list. If you want to delete the object you need to use DeleteObject();

SymHand := GetObject('Old Symbol 1');

{You should do some other checking here to make sure it's a symbolo def}

If SymHand <> NIL then

DelObject(SymHand);

Link to comment

Thanks I will try that.

But just curious, how can you delete a resource from the list without deleting the resource itself? If the resource is in the file, doesn't it have to be in the resource list somewhere?

So I guess the next question follows. To get rid of the resource (from the file) do you have to both delete the resource using DelObject AND delete the resource from the list using DeleteResourceFromList? If not, then when would you use DeleteResourceFromList?

Link to comment

The resource list is just that, a list of the resources in the file (or in some library file) depending on how you created the list. You can use the VS routines to add to and subtract from that list as you see fit.

For example you could get a list of all the symbols with the name chair and then remove all the ones that included rocking as part of the name.

This would not change the resources in the file, only those that will be acted on my the list.

When you delete the actual resource it is automatically deleted from the list (I think, test for Nil handles before trusting me on this), or at least will not be able to be built into a new list.

HTH

Link to comment

So I guess to try and understand it better, it seems you could say that DeleteResourceFromList only deletes the the resource from the list during the current running VectorScript, so you can perform actions on a custom tailored list.

But when the routine completes, since the actual resource is still in the file, the resource will appear in the list again if you build the same list in a new routine.

Does that sound right?

Link to comment

To delete the symbol definitions try this code:

 
PROCEDURE DelSymDef;
{DEBUG}
CONST
kSYMDEF = 16;
kSYMFDR = 92;
kSUBSTR = 'Old Symbol';
VAR
curSymDef: HANDLE;

PROCEDURE SearchSymDef(curDef: HANDLE);
VAR
	delSym: BOOLEAN;
	symType: INTEGER;
	symName: STRING;
	symDef1,delDef: HANDLE;
BEGIN
WHILE curDef <> NIL DO
	BEGIN
	symType:= GetType(curDef);
	IF symType = kSYMFDR THEN
		BEGIN
		symName:= GetName(curDef);
		symDef1:= FInFolder(curDef);
		SearchSymDef(symDef1);
		END
	ELSE
		BEGIN
		symName:= GetSDName(curDef);
		delSym:= (Pos(kSUBSTR,symName) > 0);
		IF delSym THEN
			BEGIN
			delDef:= curDef;
			curDef:= PrevSymDef(curDef);
			DelObject(delDef);
			END;
		END;
	curDef:= NextSymDef(curDef);
	END;
END;
BEGIN
curSymDef:= FSymDef;
SearchSymDef(curSymDef);
END;
Run(DelSymDef);

Note that the code does not check if symbol instances are still in the drawing before deleting the definitions. I assume you will get a locus at the symbol origin and/or a corrupted file if the instances exist.

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...