Hello,
I have a situation where objects are split in two parts after importing .obj originating from Archicad, named for example:
wall_white_flat_part
wall_white_smooth_part
There might be over 100 object pairs like this. Some objects are not split, thus they have no _..._part suffix.
I'm looking for a script that is able to attach objects by their name suffixes (and to weld vertices), but haven't found any. Anybody have ideas before I start scripting?
Best regards,
Jukka
Comments (6)
Comment policy
try this FN
fn attachParts thresh:0.01 sfx: =
(
local objBySfx = for o in objects where matchPattern o.name pattern:("*"+sfx) ignoreCase:on collect o
if objBySfx.count != 0 do
(
local sourceMesh = converttomesh objBySfx[1]
for i = objBySfx.count to 2 by -1 do attach sourceMesh objBySfx[i]
meshop.weldVertsByThreshold sourceMesh #{1..(sourceMesh.Verts.count)} thresh
)
free objBySfx
)
--example
attachParts thresh:0.001 sfx:"_part"
Barigazy, thanks for the function. I tried it, but it attaches everything to one object.
The point is, that there is always a pair of objects with suffixes "_flat_part" and "_smooth_part" which should be attached together.
I was able to get desired results by this apporoach: first strip name suffixes off the object names and then attach objects with same names together.
If I understand you correctly you want to attach only the pair of objects with same sufix. Post some simple example file for testing, and i try to fix function
example object names
Sorry for the delay, the point was to attach objects with different name suffixes. Example scene with 6 objects, result should be two objects:
from:
OBJ_MAASTO_MAALI_01
OBJ_MAASTO_MAALI_01_FLAT_PART
OBJ_MAASTO_MAALI_01_SMOOTH_PART
OBJ_MAASTO_METALLI_ALUMIINI
OBJ_MAASTO_METALLI_ALUMIINI_FLAT_PART
OBJ_MAASTO_METALLI_ALUMIINI_SMOOTH_PART
to:
OBJ_MAASTO_MAALI_01
OBJ_MAASTO_METALLI_ALUMIINI
The problem is, there is not always this object without any suffix like in this example.
solution#2
Not have the time to test this tool but this is the concept scrit after all.
Just type (or paste) object name OBJ_MAASTO_MAALI_01 (like prefix)
and press the button. Next add next name OBJ_MAASTO_METALLI_ALUMIINI
etc.
try(destroyDialog ::bgaRoll)catch()
rollout bgaRoll "attach By Prefix"
(
fn attachParts thresh: prx: =
(
local sourceMesh = getNodeByName prx
if sourceMesh != undefined and isKindOf sourceMesh GeometryClass do
(
sourceMesh = converttomesh sourceMesh
local objByPrx = for o in objects where o.name != prx and matchPattern o.name pattern:(prx+"*") ignoreCase:on collect o
if objByPrx.count != 0 do
(
for i = objByPrx.count to 2 by -1 do attach sourceMesh objByPrx[i]
meshop.weldVertsByThreshold sourceMesh #{1..(sourceMesh.Verts.count)} thresh
)
free objByPrx
)
)
label lbl "Object Name Prefix:"pos:[7,5]
edittext objname "" pos:[0,22] width:195 height:17
spinner thresh "Weld Threshold: " type:#float range:[0.001,1e3,0.01] pos:[7,45]
button doit "A t t a c h !" pos:[5,65] width:190 height:20
on doit pressed do
(
if txt = objname.text != "" do attachParts thresh:(thresh.value) prx:txt
)
)
createDialog bgaRoll 200 90 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)
sorry Kino but can't resist :)
you said almost 3 months ago:
Anybody have ideas before I start scripting?
are you start scripting finally?
and if so, show what you done so far