I am starting a new thread for this matter but I actually found one where this was pretty much adressed except that I need to convert many embedded blocks into linked ones.
The script supplied in that thread only works for individuals
I imagine that if you have a file with all the blocks you wish to link inserted, then its just a matter of matching names:
You could select all your 200 embedded blocks on your current file, and when asked which file to obtain the linked blocks from, this file should have the same blocks from your original file, with the exact same name.
Ids = rs.GetObjects("Select blocks to link.", filter=4096, preselect =True)
if Ids is None: return
path = "yourfilepathhere"
for Id in Ids:
name = rs.BlockInstanceName(Id)
filepath = path + "\\" + name + ".3dm"
rs.Command("_-BlockManager _Properties " + chr(34) + name + chr(34) + " _UpdateType _Linked filepath _Enter _Enter", False)
if name == “main”:
LinkBlock()
I can’t test it right now, but something along this should work. you obviously need to replace path with the folder for your parts and have the files named the same as your blocks.Also, double “\” so it won’t escape the sequence.
if you want to browse for each file individually, use:
I am afraid I don’t understand one thing though. Do I need multiple files, (One file for each block) ?
Can’t all blocks be inside one single document and use that document to replace the blocks on the other one?
import rhinoscriptsyntax as rs
def LinkBlock():
Ids = rs.GetObjects("Select blocks to link.", filter=4096, preselect =True)
if Ids is None: return
path = "C:\Users\Shynn\Desktop\BlocksToLink.3dm"
for Id in Ids:
name = rs.BlockInstanceName(Id)
filepath = path + "\\" + name + ".3dm"
rs.Command("_-BlockManager _Properties " + chr(34) + name + chr(34) + " _UpdateType _Linked path _Enter _Enter", False)
if name == “main”:
LinkBlock()
I get this error:
File "C:\Users\Shynn\Desktop\ReplaceBlocksnew.py", line
SyntaxError: Non-ASCII character '\xe2' in file C:\Users\Shynn\Desktop\ReplaceBlocksnew.py on line 17, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details