Jump to content
Developer Wiki and Function Reference Links ×

Copy items from one file to one or more other files - Copier des éléments d'un fichier vers un ou plusieurs autres fichiers


Thomas W

Recommended Posts

Hi all,

 

The vectorscripts and codes are new to me but bring an interesting and complementary vision to the different possibilities!

 

We work with 1 basic file which contains about 15 modules then we have 15 separate files for the manufacture of each module.

I'm looking for the best way to keep all elements of these 15 files up to date with the base file (symbols, database format, labels...).

So I searched in VS:Function_Reference and tested some scripts like BuildResourceList, BuildResourceListN, GetNameFromResourceList, ImportResourceToCurrentFile, Name2Index...

 

The 1st objective would be to replace from an open file the elements present in this open file by the elements of the same name of the base file.

The 2nd objective, if it is feasible, would be to replace the elements of several files which are each in different folders, by the elements of the same name of the base file.

 

I did several tests but I have trouble with certain functions or loops.

I manage to make a list of the open file and a closed file by indicating the path, to import a symbol according to its name, to find its index according to its name, but I can't get it all to work whole.

 

Since I couldn't get the Procedure CallBack from VS:ImportResToCurFileN to work I tried another way, if anyone has an explanation or another example than how to help the Callback function I want Well!

 

Below is a test script and the file attached:

 

Salut à tous,

 

Les vectorscripts et les codes sont nouveaux pour moi mais apportent une vision intéressante et complémentaire aux différentes possibilités!

 

Nous travaillons avec 1 fichier de base qui contient environ 15 modules puis nous avons 15 fichiers à part pour la fabrication de chaque modules.

Je cherche le meilleur moyen de garder tous les éléments de ces 15 fichiers à jour par rapport au fichier de base (symboles, format de base de données, étiquettes...).

J'ai donc cherché dans VS:Function_Reference et j'ai testé certains scripts comme BuildResourceList, BuildResourceListN, GetNameFromResourceList, ImportResourceToCurrentFile, Name2Index...

 

Le 1er objectif serait de remplacer à partir d'un fichier ouvert les éléments présents dans ce fichier ouvert par les éléments de même nom du fichier de base.

Le 2ème objectif, si c'est réalisable, serait de remplacer les éléments de plusieurs fichiers qui sont chacun dans des dossiers différents, par les éléments de même nom du fichier de base.

 

J'ai fait plusieurs tests mais j'ai du mal avec certaines fonctions ou certaines boucles.

J'arrive à faire une liste du fichier ouvert et d'un fichier fermé en indiquant le chemin, à importer un symbole suivant son nom, à trouver son index en fonction de son nom,  mais je n'arrive pas à faire fonctionner le tout ensemble.

 

Vu que je ne suis pas arriver à faire fonctionner la Procedure CallBack de VS:ImportResToCurFileN j'ai essayé d'une autre manière, si quelqu'un à une explication ou un autre exemple que celle de l'aide de la fonction Callback je veux bien!

 

Ci-dessous un test de script et le fichier en pièce jointe :

 

VS11:BuildResListN_List vers ListN_modifs-FORUM PRESQUE OK-2 :

 

PROCEDURE testGetNameFromRes;
{$DEBUG}



VAR
	resTypeN: INTEGER;
	fullPath: DYNARRAY[] OF CHAR;
	resListN, resList: LONGINT;
	numResN, numRes, i: INTEGER;
	S1: STRING;
	h: HANDLE;
	{numIndexN, numIndex: LONGINT;}
	{resourceName: DYNARRAY OF CHAR;}
	{Exists: BOOLEAN;}
	

BEGIN
resTypeN:=16;

	resList:=BuildResourceList(resTypeN, 0,'', numRes);
	AlrtDialog(CONCAT('Nombre d''éléments de la Liste=', numRes, Chr(13),'ID pour la Liste=', resList));
		
	BEGIN
	FOR i:=1 TO numRes DO
		IF GetNameFromResourceList(resList, i)='My Symbol Name' THEN
		BEGIN
	AlrtDialog(CONCAT('Symbole déjà présent dans ce fichier'));
		END
		{ELSE
	AlrtDialog(CONCAT('Symbole non présent dans le fichier, on va l''importer du fichier source'));}
	END;
	
	fullPath:='Y:\Thomas\Vectorscript Exemple\TW VScript Create list of symbols in resources\TW_VS créer un rectangle_rectangleN_GetBBox_sur bureau COPIE.vwx';
	resListN:=BuildResourceListN(resTypeN, fullPath, numResN);
	AlrtDialog(CONCAT('Nombre d''éléments de la ListeN=', numResN, Chr(13),'ID pour la ListeN=', resListN));
	
	BEGIN
	FOR i:=1 TO numResN DO
	IF GetNameFromResourceList(resListN, i)='My Symbol Name' THEN
	h:=ImportResourceToCurrentFile(resListN, i);
	END;
	
	BEGIN
		IF GetObject('My Symbol Name')<>NIL THEN
		AlrtDialog(CONCAT('Symbole présent dans ce fichier'));
		END;
	END;
		
RUN(testGetNameFromRes);

 

Thank you and I hope the google translation will be understandable enough!

Have a nice day and happy Christmas!

 

Thomas

 

Merci et j'espère que la traduction google sera assez compréhensible!

 

Bonne journée et bonnes fêtes!

 

Thomas

TW test Create List Symbols and Import_Forum.vwx

Link to comment
  • 2 weeks later...

Hello and all my best wishes for this new year!

 

I'm trying to figure out how the ImportResToCurFileN function works.

According to the explanation of the help, we should be able to choose between Don't import, replace or rename?

I tried based on the helper script but when importing an already existing symbol, I can't seem to make this choice appear.

 

The example below is from the help, is it supposed to work or is something missing? :

 

Bonjour et tous mes meilleurs vœux pour cette nouvelle année!

 

Je cherche à comprendre comment fonctionne la fonction ImportResToCurFileN.

D'après l'explication de l'aide lors de conflit on devrait pouvoir choisir entre DoNotImport, Replace ou Rename?

J'ai essayé en me basant sur le script de l'aide mais lors de l'import d'un symbole déjà existant je n'arrive pas à faire apparaître ce choix.

 

L'exemple ci-dessous vient de l'aide, est-il censé fonctionner ou il manque quelque chose? :

 

https://developer.vectorworks.net/index.php/VS:ImportResToCurFileN

 

PROCEDURE testResCountSymFolders;
VAR
    resList : LONGINT;
    numRes : INTEGER;
    h : HANDLE;

    FUNCTION ImportResCallback(VAR resourceName:DYNARRAY OF CHAR) : INTEGER;
        BEGIN
        AlrtDialog( resourceName );
        resourceName := Concat( resourceName , '-1' );
        ImportResCallback := 2;
        END;

BEGIN
    { list symbol folders in curr doc }
    resList := BuildResourceList(16, 23, '', numRes );
    h := ImportResToCurFileN( resList , 1, ImportResCallback );
    alrtDialog(concat('numRes=', numRes , ' h=', h));
END;
RUN(testResCountSymFolders);

 

Thanks in advance and have a nice day!

Merci d'avance et bonne journée!

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