Select the groups first, and then run this code to save it as a single SKP file with the same file name and suffix in the current file directory
增加个数字,防止群组重名
Add a number to prevent duplicate group names
# 这段是默认代码,您可以选择使用或删除。。。
mod = Sketchup.active_model # 打开模型
ent = mod.entities # 模型中的所有实体
sel = mod.selection # 当前选择
num=1
sel.grep(Sketchup::Group) do | grp |
gname=grp.name
grp1= grp.copy
ins = grp1.to_component
defn = ins.definition
new_skp= mod.path.gsub(/.skp$/,'_' + gname + num.to_s + '.skp')
puts new_skp
defn.name = gname
defn.save_as(new_skp)
ent.erase_entities ins
num=num+1
end
I think the OP was expecting the group instance names to be unique, and when they were not (or were blank) the code repeatedly oversaved the same export file.
In the 2nd post this was corrected to “difference” the files names.
这组代码将解决总装图到零件图.也就是将模型中的图批量按群组保存为单个SKP文件.
不管你的模型有多复杂,均可按组生成的零件(SKP).从而达到批量保存的目的.
This is codes will solve the problem from general assembly drawing to part drawing, that is, save the drawings in the model in batches as a single SKP file
No matter how complex your model is, you can generate parts by group (SKP), so as to achieve the purpose of batch saving.
分享快乐,快乐分享
Share happiness, share happiness
因为我搜索了整个网站,都没有这样的代码,于是就参照写了一个.并分享出来.
感谢各位的关注.
Because I searched the whole website without such code, I wrote one by reference and shared it
Thank you for your attention