Jump to content

ImportResToCurFileN and callback function


Recommended Posts

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

I don't think that ImportResToCurFileN does what we think it does.  I can't make the sample work either.

 

If run on a file with no Resources, it imports the first symbol from my Favorites files. But the ImportResCallback function never runs.

 

Take a look at using ResList_ImportItemN instead.  It takes a value (0,1,2,3) on what to do on a conflict.  3 should open the dialog box and ask what you want to do.

 

HTH

Link to comment

Hello Pat,

 

Thank you for your feedback, I've been stuck on this function for a while now, so somewhere it reassures me!

 

I'll check out the ResList_ImportItemN function and let you know if I got it to work.

 

Thanks again and have a nice day

 

Bonjour Pat,

 

Merci de votre retour, ça fait un moment que je bloque sur cette fonction donc quelque part ça me rassure!

Je vais voir avec la fonction ResList_ImportItemN et je vous dirais si je suis arrivé à la faire fonctionner.

 

Merci encore et bonne journée

Link to comment

Hello Pat,

 

I did several tries and searched for examples of ResList_ImportItemN but couldn't come up with a choice when conflicting.

 

For me the uniqueID is the unique name of the item to import and doConflict would be the choice when conflicting.

 

FUNCTION ResList_ImportItemN(uniqueID: STRING; doConflict: LONGINT): HANDLE;

 

Below is the code I tried to test, but it doesn't work as described: If you see what the problem is I'm interested!

 

The file is attached.

 

Thanks and good day,

 

Bonjour Pat,

 

J'ai fait plusieurs essais et recherché des exemples de ResList_ImportItemN mais je ne suis pas arrivé à avoir un choix lors de conflit.

Pour moi l'uniqueID est le nom unique de l'élément à importer et doConflict serait le choix lors de conflit.

 

FUNCTION ResList_ImportItemN( uniqueID : STRING ; doConflict : LONGINT ) : HANDLE ;

 

Ci-dessous le code que j'ai essayé pour tester, mais qui ne fonctionne pas comme dans la description :

Si vous voyez ce qui pose problème ça m'intéresse!

Le fichier est en pièce jointe.

 

Merci et bonne journée,

PROCEDURE testResList_ImportItemN;
{$DEBUG}

{FUNCTION ResList_ImportItemN(
               uniqueID     :STRING;
               doConflict   :LONGINT) : HANDLE;}

CONST
	ObjectType=16; { Symbol Definition } 
	FolderIndex=14; 
	{si -14 ne va chercher que dans le dossier de symbol par défaut et du coup ne peut pas vérifier si hatch=NIL,} 
	{sauf en faisant une liste en plus qui ne concerne que le document } 
	{Préférence Vector, dossier utilisateurs, dossier partagé}
	SubFolderName=''; { Nul subfolder get all folders and subfolders }
	doConflict=2;
	
VAR
	uniqueID: STRING;
	MyName: STRING;
    MyList: LONGINT;
    NumItems: LONGINT;
    hatch: HANDLE;
    
	
BEGIN
	MyList:= BuildResourceList(ObjectType, FolderIndex, '', NumItems);
	MyName:= GetNameFromResourceList(MyList, 5); { change this number to get the names of other symbol } 
	AlrtDialog( Concat(Date(2, 2), Chr(13), 'The Name is: ', MyName, Chr(13), 'Total items in list: ', NumItems));
	
		{IF (hatch= NIL) THEN}
		hatch:= ResList_ImportItemN(MyName, doConflict);
		{hatch:= ImportResourceToCurrentFile(MyList, 5);}
		
		DeleteResourceFromList(MyList, 5);
    END;
    RUN(testResList_ImportItemN);

 

 

Link to comment

@Thomas W Sorry to send you on a wild goose chase. ResList_ImportItemN is not what you want either. It imports the item selected in a Resource Popup rather than one you are specifying from a list.

 

@Conrad Preen Back in 2014 you posted some information on ImportResToCurFileN to the Vectorscript list and said you also edited the Dev site. 

 

The current sample code on the dev site does not work. Any chance you can help us out?

 

I use the sample script and it imports the first item to my file. When I run the script again, it never calls the conflict handling procedure.

 

Any ideas or some working sample code?

Link to comment

@Pat Stanford Well I think I was unlucky on this one!

But thank you for your return which avoids me to search too long.

It would be good if they modified these explanations on the Dev site and on the local file, I will also send an email to the hotline in this direction.

Anyway thank you and I'll look for another solution for what I want to achieve and I'll do another post I think.

 

Thank you and good day

 

 

 

Bon je crois que je n'ai pas eu de chance sur ce coup là!

Mais merci de votre retour qui m'évite de chercher trop longtemps.

Ce serait bien qu'ils modifient ces explications sur le site Dev et sur le fichier en local, je vais également faire un mail à la hotline dans ce sens.

En tous cas merci et je vais chercher une autre solution pour ce que je souhaite réaliser et je ferais un autre poste je pense.

 

Merci et bonne journée

Link to comment
  • Vectorworks, Inc Employee

@Pat Stanford 2014 !!! wow that's going back some... I haven't done much Vectorscript for several years now as I and now the team have moved everything to SDK. Once you stop using Vectorscript it feels so good you don't want to go back!  But let me try...

 

First off, any function beginning ResList_ arrived after my transition to SDK. It seems to be something to do with resource popup controls but I have never used this. I have certainly used ImportResToCurFileN in the past and it works. I notice that the callback is wrongly declared as a procedure

 

      FUNCTION ImportResToCurFileN( listID  :LONGINT; index  :LONGINT; callback  :PROCEDURE) : HANDLE;

 

it is a function that should return the values 0, 1, or 2 depending on how you want the conflict to be handled. You need to have defined the function in your code before you use ImportResToCurFileN and make sure it is in scope. The sequence is important. You need to build the reslist, then get the size of it so you can step thru it. If you want to delete stuff then you have to step thru using DOWNTO because you will run off the end of the list and crash. These are the things you have to keep in mind.

 

It certainly did work but it does look like there may be a bug. Do you want to file one Pat?

 

@Thomas W When I was a 3rd party dev I also found the lack of documentation frustrating. At moment no-one is tasked with looking after this and whatever we are able to contribute eats into our spare time. What I found very useful was to download the C++ SDK and burrow around in there. Even if you want to stay with script it's useful to develop the ability to read C++. You get a much better idea of what's going on under the hood. Eventually of course you get sucked in and realise that it's not so difficult to develop in C++ because the tools are way better. That moment when your first SDK plug-in compiles and runs is nerdy thrill second to none!

 

Best regards and wishes for the New Year

 

Conrad

 

  • Like 1
Link to comment

@Conrad Preen 

Hello and thank you for your feedback and your explanations!

 

I will try again ImportResToCurFileN with callback in Function and not in procedure, following your explanations.

As for Vectorscript, I became interested about 2 months ago for certain operations inaccessible without script.

I haven't done any development before, so I looked at vectorscripts and scripts in python, then reading some posts and help I tested some help examples.

I find the code interesting but even if it's a profession in its own right, nothing prevents you from being so interested in having notions.

Previously I used Allplan for 17 years, Archicad for 4 years, Revit for 6 months, then Vector now.

I'm going to read the information I find in the help on these different languages and maybe one of these days I'll get a corny thrill like no other!

 

Have a nice day and all my best wishes!

 

Thomas

 

 

Bonjour et merci pour votre retour et vos explications!

 

Je vais réessayer ImportResToCurFileN avec callback en Fonction et pas en procédure, en suivant vos explications.

 

Pour ce qui est de Vectorscript je mis suis intéressé il y à 2 mois environ pour certaines opérations inaccessible sans script.

Je n'ai pas fait de développement avant, donc j'ai regardé les vectorscripts et les scripts en python, puis en lisant certains posts et l'aide j'ai testé certains exemples de l'aide.

Je trouve le code intéressant mais même si c'est un métier à part entière rien n'empêche de si intéresser pour avoir des notions.

Auparavant j'ai utiliser Allplan pendant 17ans, Archicad pendant 4ans, Revit pendant 6 mois, puis maintenant Vector.

Je vais lire les informations que je trouve dans l'aide sur ces différents langages et peut être qu'un des ces jours j'aurais un frisson ringard sans pareil!

 

Bonne journée et tous mes meilleurs voeux!

 

Thomas

Link to comment

@Conrad Preen

1 hour ago, Conrad Preen said:

2014 !!! wow that's going back some...

 

I have archives of at least some of the old Vectorscript List going back to 2005. And if I search hard enough there are probably some from the Compuserve list before that around somewhere also. 😉  The oldest in the archive from you is 2007 asking about what screen capture software I was using (much missed Snapz Pro). 

 

I will file a bug on ImportRestoCurrentFileN.  The test was using CallBack as a Function even though the definition says Procedure. Nice to know it is broken and not just my using it wrong.

 

 

Link to comment
  • 2 weeks later...
  • Vectorworks, Inc Employee

Hello everyone,

 

I am not an expert in VS, but I looked what ImportResToCurFileN is doing and tested the original script. And here are the results:

It builds a list of all resources in the current document, and then in my Libraries folder. So, the first time I run it, it imports THE FIRST symbol from the list into the current document, because my document is empty. 

ImportResToCurFileN( resList , 1, ImportResCallback ); Second parameter 1 is an index of the symbol in the list.

Second time it again builds the list from the current document + Libraries. And now the first symbol belongs to the current document, and nothing happens.

Because after the resource is imported, the next attempt sees it is already present, and it matches, so it doesn’t require either import or conflict handling.

 

You can loop through all elements of the list, and you will see the conflict eventually.

Other testing suggestions: while looping you can check the name of the resource GetNameFromResourceList(resList, idx), and/or GetResourceFromList(resList, idx), which will return NIL for resources not in the current document. And only for those resources it makes sense to call Import. 

 

Lada

  • Like 1
Link to comment

Hello everyone and thank you Lada for your feedback,

 

I retested ImportResToCurFileN in a blank file by creating a list of symbols from our shared library whose path is in User Folder/Shared Preference Folders:

resList := BuildResourceList(16, -14, '', numRes )

Then when importing with index #1: h:= ImportResToCurFileN( resList , 1, ImportResCallback ) the symbol with index 1 is imported into the blank file, with no message.

If I run it a second time nothing happens.

On the other hand, if I modify the imported symbol and run the script, it imports the symbol and renames it with '-1' as specified in the Function.

If I understood correctly when there is a conflict, the callback used will be the one defined in the function, in the case below it will be rename.

And if we want to use Replace, we should configure it in the same way in the Function ImportResCallback?

 

I was expecting something different from the description on developer.vectorworks.net, I thought you could choose for each conflict between Do nothing, Replace or Rename.

 

Thank you for your feedback which prompted me to test again and see that it works in some cases, even if I find it does not correspond too much to the description on the site!

 

I had a return from the .eu hotline saying that they had reported the problem to Vectorworks inc. but that they did not know when a solution might be available.

 

Have a good day,

 

Bonjour à tous et merci Lada pour votre retour,

 

J'ai re testé ImportResToCurFileN dans un fichier vierge en créant une liste des symboles de notre bibliothèque partagée dont le chemin est dans Dossier Utilisateur/ Dossiers de préférences partagés : resList := BuildResourceList(16, -14, '', numRes )

Puis lors de l'import avec l'index n°1 : h := ImportResToCurFileN( resList , 1, ImportResCallback ) le symbole dont l'index est 1 est importé dans le fichier vierge, sans message.

Si je l'exécute une 2ème fois rien ne se passe.

Par contre si je modifie le symbole importé et que j'exécute le script il importe le symbole et le renomme avec '-1' comme précisé dans la Fonction.

Si j'ai bien compris lorsqu'il y a un conflit le callback utilisé sera celui définit dans la function, dans le cas ci-dessous ce sera renommer.

Et si on veut utiliser Remplacer il faudrait le paramétrer de la même manière dans la Function ImportResCallback?

 

Je m'attendais à un autre fonctionnement d'après la description sur le site developer.vectorworks.net, je pensais qu'on pouvait le choix pour chaque conflit entre Ne rien faire, Remplacer ou Renommer.

 

Merci de votre retour qui m'a poussé à re tester et à voir que ça fonctionne dans certains cas, même si je trouve ça ne correspond pas trop à la description sur le site! 

 

J'avais eu un retour de la hotline .eu disant qu'ils avaient reporté le problème auprès de Vectorworks inc. mais qu'ils ne savaient pas quand une solution pourrait être disponible.

 

Bonne journée,

 

 

PROCEDURE testResCountSymFolders;
{$DEBUG}
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, -14, '', numRes );
    h := ImportResToCurFileN( resList , 1, ImportResCallback );
    alrtDialog(concat('numRes=', numRes , ' h=', h));
END;
RUN(testResCountSymFolders);

 

 

 

Link to comment
  • Vectorworks, Inc Employee

Hello Thomas,

Thank you for testing. You are right, you can configure the callback to do any of Do Not Import (return 0), Replace (return 1) or Rename (return 2). For Rename you need to change the var parameter.

Alternatively, you can use  ImportResourceToCurrentFile which does not provide a callback function. In this case you will see the dialog for each conflict.

  • Like 1
Link to comment

@Lada I think the part that is confusing us is that there appears to be logic inside the c command that is doing checking on the imported object that is not described in the documentation.

 

In our discussion on the Bug I submitted you said that the reason it was not importing is that it "knew" that the resource already imported was identical to the one already imported to the file. Therefore it did not import the new one, nor did it call the Callback procedure to check and see how to handle the duplicate because VW did not consider it a duplicate.

 

I think what @Thomas W and I are expecting is that the Callback would be called even if the objects are identical so we can choose what to do.

 

Alternatively we need an additional procedure that returns a flag that tells us that the resource we are attempting to import is identical to the one already in the file.

 

Procedure  ImportResToCurFileN2 ( listID:LONGINT;   index:LONGINT;   ALLREADY IN FILE:BOOLEAN; callback:PROCEDURE ) :HANDLE ;

 

Also, note that the ImportResToCurFileN documentation is wrong and calls it a Function when it is actually a Procedure.

 

Thank you for your help on this.

  • Like 1
Link to comment
  • Vectorworks, Inc Employee

Hi Pat.

Thank you for the clarification. I believe, it is implemented the same way as it works in the application if you do import from Resource manager. If the object is already present and it matches, it doesn’t require either import or conflict handling.

I agree that the documentation should be corrected.

Please, submit an enhancement request if you feel there is a need for another flavor of this procedure. 

  • Like 2
Link to comment

Thanks to both of you for your feedback and explanations.

@Pat Stanford: yes I was expecting a callback to choose different options!

(but I'm doing other tests, I'll do another post depending on the results...)

 

See you soon and have a nice day,

 

Thomas

 

 

Merci à vous 2 pour vos retours et vos explications.

@Pat Stanford: oui je m'attendais à un rappel permettant de choisir différentes options!

(mais je suis entrain de faire d'autres tests, je ferai un autre post suivant les résultats...)

 

A bientôt et bonne journée,

 

Thomas

 

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