Jump to content
Developer Wiki and Function Reference Links ×

Help from the Guild - See Classes/Layers in a different file?


Recommended Posts

Nope.  I had to make commands that would export file and class names and their attributes to a text file, and commands that would read those text files creating the layers and classes in the active file from which the import commands were run.  The scheme works well, but it would be nifty to bypass the export and just read layer and class info from another file.  I think you can only read resources from another file, and classes and layers are not resources.  If one of the others knows something that I don't that would be great.

 

Link to comment
2 hours ago, Pat Stanford said:

You can Import Layers/Classes from the Organization

 

I never noticed the "choose..." button in those dialogs.  That's handier.  There are some layer and class sharing workflows that will prefer working with the text files, but they are pretty esoteric.  What is the workflow you envisage that would want a script to query another file not using the layer and class dialogs?

Link to comment

Smart Purge.

 

User wants to be able to purge a file without having to specify the layers/classes/resources that are unused that they want to keep. The idea is to just say Purge and then reload the "wanted" unused item from the template file.

 

Resources are relatively easy.

Classes could be done by importing an object that uses those classes and then deleting it. But better would be to import directly if possible.

Layers are basically impossible with out some kind of list (your text file export, or a manually entered list of names) but if you need any attributes associated then that makes the list more complicated.

 

Or, maybe .... A script that would create a worksheet of the items to be restored. Which could then be imported and used to recreate.  That might work.

 

And that might work for you also and avoid the txt file.

Link to comment
4 minutes ago, Pat Stanford said:

Or, maybe .... A script that would create a worksheet of the items to be restored. Which could then be imported and used to recreate.  That might work.

 

And that might work for you also and avoid the txt file

 

For you, the worksheet seems like a good solution, but the layer and class dialogs do what I need.  The esoteric workflows I mentioned revolve around sharing the created text files in a work group situation.  Not a lot different from just sharing .vwx files and using the layer and class dialogs, just a little less clicking and a little less file size intensive.  And some of my users are just familiar with them.  Familiarity, trumps a lot of "workflow stuff".

Link to comment

I was able to import classes pretty easily with this script:

 

PROCEDURE ImportClasses;

CONST

	kTargetPath = 'C:\Users\cogsw\Desktop\Import Classes Test.vwx';

VAR

	resList,numItems:LONGINT;
	i:INTEGER;
	h:HANDLE;
	
BEGIN
	resList:=BuildResourceListN(94,kTargetPath,numItems);
	
	FOR i:=1 TO numItems DO h:=ImportResourceToCurrentFile(resList,i);
END;

Run(ImportClasses);

 

I imagine you could use a variation on this script for any number of resources from a template file.  I was not able to get layers to import or to appear in the resource list properly.

  • Like 1
Link to comment

Awesome Jesse!!  Amazing the assumptions we make.  

 

I think Sam, Raymond and I all assumed (we all know what what means) that since classes are not "resources" than can be seen in the Resource Manager they would not respond to the BuildResourceList commands. And never bothered (or needed) to test that assumption.

 

Thank you for the help. 👍

Link to comment
10 minutes ago, Pat Stanford said:

I think Sam, Raymond and I all assumed (we all know what what means) that since classes are not "resources" than can be seen in the Resource Manager they would not respond to the BuildResourceList commands. And never bothered (or needed) to test that assumption.

 

I can neither confirm nor deny my ignorance on the matter of Classes as observable resources in other files.

Link to comment

It would be interesting to get a list of object types that can be touched with the BuildResourceList() procedure.  It would be very strange if the object type "21" (polyline) was able to be imported.  Would that import every polyline in the document?  What would the index number even mean?  So...  Maybe all the "...definition" objects can be touched, but that would leave out "Layer", object type "31".  What about Viewports, object type "122"

Is there a list or can a list be made of all the objects the  BuildResourceList() procedure can see and then be imported by the ImportResourceToCurrentFile() procedure?

Link to comment

I think the Resource List can only contain definitions of things, at least when I try the BuildResListN command with an index of a resource "on drawing", the numItems always comes back as 0.  I did do a little further testing, and I think this method could be still be used in the context of the script that @Pat Stanford is trying to write regarding layers.  I that context, you really only need the layer names since they would be empty anyway if they are being purged.  You could use GetActualNameFromResourceList after building the resource list of type "31" to get the names of layers in the template document.  Unfortunately, none of the other data seems to come through (scale, elevation, transparency, etc), so that would have to be manually configured in the script.

 

Or you could institute a "Layer Manifest" worksheet that would be imported from the template document containing all template layers and settings, then delete the manifest worksheet on script completion.

  • Like 1
Link to comment
3 hours ago, Jesse Cogswell said:

Unfortunately, none of the other data seems to come through (scale, elevation, transparency, etc), so that would have to be manually configured in the script.

 

So it would seem that that would mean using the text file approach is the only way to copy scale, elevation, transparency, etc into another file.

Link to comment

After working on this yesterday, I found myself doing a new drawing needing to copy over a bunch of classes from one drawing to another.  In the past, I would do this by copying over any line styles, hatches, or textures and then drawing rectangles with each class.  I would then copy these rectangles from the referenced drawing into the new drawing, effectively importing the classes.  But with my newfound knowledge gained after yesterday, I wrote a menu command to simplify the process.

 

Because there's not a Vectorscript command to open a file browser looking for VW files, I kludged something together using GetFolder instead.  Basically, after selecting a folder, a List Box will be generated with all Vectorworks files in the folder, and selecting one will cause the File Path text field to be filled in.

 

Pressing the Get Classes button will populate the List Browser with classes, which you can select to import.  If the class already exists in the document, its name will be highlighted in blue, and it will be overwritten with the data from the imported class.  If there's a naming conflict with something else in the drawing, the name will be highlighted in red and it will get an additional checkmark as a warning.  If there is a naming conflict, the class will not be imported.

 

Feel free to play around with it and let me know if anything breaks.

 

image.png.4fc2b60a65e4179b4fc8873c442e882e.png

Import Classes from File.vsm

  • Like 2
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...