VS:ImportResToCurFileN: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
m (1 revision)
No edit summary
 
(10 intermediate revisions by the same user not shown)
Line 5: Line 5:
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<desc>
<desc>
Imports the indicated resource from the specified list to the current file, if it is not already in the current file, and returns the handle to the resource.
Imports the indicated resource from the specified list to the current file, if it is not already in the current file, and returns the handle to the resource. It will use a callback procedure to determine how to handle the duplicate resource.
 
The function does a comparison between the resource being imported and the resources currently in the file. If there is an exact match, then is not considered a conflict, the resource is not imported and the Callback procedure is not called.</desc>
This function is similar to [[VS:ImportResourceToCurrentFile]] but it will not show a dialog when there is a conflict during the import.
</desc>


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<def>
<def>
<funcDef lang="vs">
<funcDef lang="vs">
FUNCTION ImportResToCurFileN(listID: LONGINT; index: LONGINT; callback: FUNCTION) : HANDLE;;
FUNCTION ImportResToCurFileN(listID:LONGINT; index:LONGINT; callback:PROCEDURE) : HANDLE;
</funcDef>
</funcDef>
<funcDef lang="py">
<funcDef lang="py">
Line 24: Line 22:
<params>
<params>
<lineList ident=1>
<lineList ident=1>
<line>
type
INTEGER
the type of resource to put in the list
</line>
<line>
<line>
listID
listID
LONGINT
LONGINT
an ID for a resource list created by the [[VS:BuildResourceList]] or [[VS:BuildResourceListN]] command
 
</line>
</line>
<line>
<line>
index
index
LONGINT
LONGINT
an index into the list.
 
</line>
</line>
<line>
<line>
callback
callback
FUNCTION
PROCEDURE
a callback function used to resolve conflicts silently.
 
</line>
</line>
</lineList>
</lineList>
Line 48: Line 41:


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<remark>
<remark>Return values from callback determine how any conflict is handled:
The call back function will be called for a resource that cannot be imported due to a name conflict. The callback function should have the following definition:
 
<code lang="vs">
eImportResourceConflictResult_DoNotImport = 0
FUNCTION ImportResourceCallback(VAR resourceName:DYNARRAY OF CHAR) : INTEGER;
 
</code>
eImportResourceConflictResult_Replace = 1
The 'resourceName' parameter contains the name of the conflict resource. The user might change the value in order to rename the imported resource.
 
The return value will tell Vectorworks how to resolve the conflict. The following values are defined:
eImportResourceConflictResult_Rename = 2
* 0 - Do Not Import -- the conflict resource will be skipped during import.
 
* 1 - Replace -- the conflict resource will replace the existing in the document.
The callback will be executed only when there are conflicts, and the return value will define how the conflict should be resolved (much like the radio buttons in the dialog) If you want to rename, then change the var parameter with a new unique name, otherwise it will execute the callback again.
* 2 - Rename -- the conflict resource will be imported under the new 'resourceName' parameter value. If there is still conflict the callback function will be called again with the new name.
 
 
'''January 23, 2023 Pat Stanford'''
Per forum discussion with Lada Arsenyuk of Vectorworks, we have determined that ImportRestoCurFileN does a comparison check of the resource you are attempting to import and the resources in the current file. If the resource you are trying to import is an exact duplicate of a resource in the current file, then the resource is not imported and the Callback function is not called.  
 
If you always want to see the conflict dialog box then use ImportResourceToCurrentFile instead.
 
See this thread for more discussion.
 
https://forum.vectorworks.net/index.php?/topic/104434-importrestocurfilen-and-callback-function/&do=findComment&comment=457282
</remark>
</remark>
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<sample>
<sample>
<code lang="vs">
<code lang='vs'>
{ try this on a file with some symbol folders }
PROCEDURE testResCountSymFolders;
PROCEDURE testResCountSymFolders;  
VAR
VAR  
     resList : LONGINT;
     resList : LONGINT;  
     numRes : INTEGER;
     numRes : INTEGER;  
     h : HANDLE;
     h : HANDLE;  


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


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


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<seeAlso>
<seeAlso></seeAlso>
VS Functions:
[[VS:ImportResourceToCurrentFile]] | [[VS:BuildResourceList]] |[[VS:BuildResourceListN]]
</seeAlso>


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<version>
<version>
Availability: from Vectorworks 2012
Availability: from Vectorworks 2014


</version>
</version>

Latest revision as of 14:10, 1 September 2023

.VectorScript|VectorScript ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix

Description

Imports the indicated resource from the specified list to the current file, if it is not already in the current file, and returns the handle to the resource. It will use a callback procedure to determine how to handle the duplicate resource.

The function does a comparison between the resource being imported and the resources currently in the file. If there is an exact match, then is not considered a conflict, the resource is not imported and the Callback procedure is not called.

FUNCTION ImportResToCurFileN(
listID :LONGINT;
index :LONGINT;
callback :PROCEDURE) : HANDLE;
def vs.ImportResToCurFileN(listID, index, callback):
    return HANDLE

Parameters

listID LONGINT
index LONGINT
callback PROCEDURE

Remarks

Return values from callback determine how any conflict is handled:

eImportResourceConflictResult_DoNotImport = 0

eImportResourceConflictResult_Replace = 1

eImportResourceConflictResult_Rename = 2

The callback will be executed only when there are conflicts, and the return value will define how the conflict should be resolved (much like the radio buttons in the dialog) If you want to rename, then change the var parameter with a new unique name, otherwise it will execute the callback again.


January 23, 2023 Pat Stanford Per forum discussion with Lada Arsenyuk of Vectorworks, we have determined that ImportRestoCurFileN does a comparison check of the resource you are attempting to import and the resources in the current file. If the resource you are trying to import is an exact duplicate of a resource in the current file, then the resource is not imported and the Callback function is not called.

If you always want to see the conflict dialog box then use ImportResourceToCurrentFile instead.

See this thread for more discussion.

https://forum.vectorworks.net/index.php?/topic/104434-importrestocurfilen-and-callback-function/&do=findComment&comment=457282

Example

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);

Version

Availability: from Vectorworks 2014