Jump to content
Developer Wiki and Function Reference Links ×

script to import DWG's in place in several folders


Recommended Posts

Hi,

 

I have a set of many tiny DWG's spread across dozens of folders that I would want to import in place into VW files. 

 

When I use the import DWG/DXF command then I can import all DWG's into one folder or all DWG's into one file. But what I would really want is is to have a batch import where for each folder of DWG's the import is done into that folder either one VW file with all DWG's from that folder or if that's not possible for each folder containing DWG's the import is done into that folder with one VW file per DWG file. 

 

Even more I would want the DWG geometry to be imported as symbols into the VW files. 

 

Would something like this be possible or should I start thinking about apple script?

 

Edited by Sebastiaan
Link to comment

Ok different aproach. 

 

I used an Automator finder quick action to batch rename the DWG's with a prefix based on the nested folders that the DWG's are in. Before the name was Product abc.dwg and below is the result. This is an anonymised example file and folder structure. 

 

Screenshot2024-03-09at14_07_00.thumb.png.d1278a71f51b6a02656472f4c8cefce8.png

I can now import the DWG's as symbols into 1 file and this will at least sort the imported symbols in the recourse manager in the same order as the folder structure. With two example files this import wil look like this in the RM:

Screenshot2024-03-09at14_08_38.thumb.png.bf01f685c2c314c6254ab6134b8ed8c7.png

 

Now would it be possible with a script to loop through the symbols in the RM and create folders and subfolders based on the prefixes delimited by the '_' in the symbol? The desired result would look like this:

 

Screenshot2024-03-09at14_15_53.thumb.png.b8aee8be0b3dfe84985f3a3f86508782.png

 

Screenshot2024-03-09at14_16_00.thumb.png.228e21ec808d157d02d72bdb157ecc8c.png

 

As far as I can see there won't be an issue with the 63 character limit looks like I am staying under that.

 

The actual data set has 1000's of dwg's to convert so manual operation is not really an option.  The sorted import list is already sort of workable, but if the above script would be possible I would be forever grateful.

Link to comment
  • Sebastiaan changed the title to script to import DWG's in place in several folders

Maybe this topic should be moved to the Python forum because I have been trying some different code snippets in Python. 

 

I can create a folder in a folder or even two folders in one folder with the below code. It would only have to be made dynamic based on then delimited substrings of the symbols. 

vs.NameObject('Audio')
vs.BeginFolderN(16)
vs.NameObject('AudioSubfolder')
vs.BeginFolderN(16)
vs.EndFolder()
vs.NameObject('AudioSubfolderSCND')
vs.BeginFolderN(16)
vs.EndFolder()
vs.EndFolder()

 

I can loop through a list of symbols in a folder and place a symbol in it's folder based on the last substring delimited by '_' However some how it only places one symbol in its folder I have to run the script again to get the next one in its folder?

symid = vs.FInFolder( vs.GetObject( 'DXF_DWG' ) )

while vs.GetTypeN(symid)==16:
	symname=vs.GetName(symid)
	symdepth = symname.count('_')
	fname = vs.SubString(symname,'_',symdepth)
	insrtfldr = vs.GetObject(fname)
	insrtsym = vs.GetObject(symname)
	vs.InsertSymbolInFolder(insrtfldr, insrtsym)
	#vs.AlrtDialog(symdepth,fname)
	
	symid=vs.NextSymDef(symid)

 

So making small steps, it has just been to long ago since I coded anything and these bit of code are copied from various topics. Would anyone be willing to give me a push?

 

Link to comment

update:

 

I managed to get a script working for creating folder based on a substring of the symbol names. And placing the symbols in their corresponding folders. This does not create nested folders yet, but I may leave it at this an enough of a satisfactory result. Maybe I could get it to work to create multiple nested folders if I make a list with a sublist of substrings or something like that. 

 

symid = vs.FInFolder( vs.GetObject( 'DXF_DWG' ) )
fldrlist = []
symlist = []

while vs.GetTypeN(symid)==16:
	symname = vs.GetName(symid)
	symsub = vs.SubString(symname,'_',2)
	#vs.AlrtDialog(symsub)
	fldrlist.append(symsub)
	symlist.append(symname)
	symid=vs.NextSymDef(symid)

cntsym = (len(fldrlist))
vs.AlrtDialog(cntsym)
sym=symid

if vs.GetTypeN(sym)!=16:
	vs.AlrtDialog('All symbols shown')
	
i = 1
while i < len(fldrlist):
	fname = fldrlist[i]
	chkfldr = vs.GetObject(fname)
	if chkfldr == 0:
		#vs.AlrtDialog(fname, ' ', chkfldr)
		vs.NameObject(fname)
		vs.BeginFolder()
		vs.EndFolder()
	i = i + 1

i = 0
while i < len(symlist):
	symname = symlist[i]
	fname = vs.SubString(symname,'_',2)
	insrtfldr = vs.GetObject(fname)
	insrtsym = vs.GetObject(symname)
	#vs.AlrtDialog(insrtsym)
	vs.InsertSymbolInFolder(insrtfldr, insrtsym)
	i = i + 1
#vs.AlrtDialog(vs.SubString(Symname,'_',2))

 

Link to comment
5 hours ago, Pat Stanford said:

Good luck.

 

Hi Pat,

 

Thank you. I must admit I was secretly hoping for you. But by not having the time you motivated me to do it myself ;-). I couldn't let it go and I now have it working for the second level with nested folders too! There are a couple of items in the import that could have been in a third folder but I am not going to bother with that. Very happy with the result and that I managed myself. See the code and example file below:

symid = vs.FInFolder( vs.GetObject( 'DXF_DWG' ) )
fldrlist = []
symlist = []

while vs.GetTypeN(symid)==16:

	symname = vs.GetName(symid)
	symsub = vs.SubString(symname,'_',2)
	
	if symsub not in fldrlist:
		fldrlist.append(symsub)
		
	symlist.append(symname)
	symid=vs.NextSymDef(symid)

cntsym = (len(fldrlist))
cntsym2 = (len(symlist))
sym=symid

scndlist = []

for i in range(len(fldrlist)):
	fldr1 = fldrlist[i]
	
	for j in range(len(symlist)):
		symname = symlist[j]
		scndfldr = vs.SubString(symname,'_',3)
		chkfldr = vs.SubString(symname,'_',2)
		if scndfldr not in scndlist and chkfldr == fldr1 and symname.count('_') >= 3:
			scndlist.append(scndfldr)
			
	vs.NameObject(fldr1)
	vs.BeginFolderN(16)
	
	for k in range(len(scndlist)):
		fldr2 = scndlist[k]
		vs.NameObject(fldr2)
		vs.BeginFolderN(16)
		vs.EndFolder()
	vs.EndFolder()
	scndlist.clear()

for i in range(len(symlist)):
	symname = symlist[i]
	
	if symname.count('_') >= 3:
		fname = vs.SubString(symname,'_',3)
	else:
		fname = vs.SubString(symname,'_',2)
		
	insrtfldr = vs.GetObject(fname)
	insrtsym = vs.GetObject(symname)
	vs.InsertSymbolInFolder(insrtfldr, insrtsym)

Folder script.vwx

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