[Closed] Select last detached Object of the same name?
This is my current code.
macroScript DetachDoor category:"My Tools"
-- select a polygon(s), and run.
-- Will detach polygon(s) and name it door01 then,
-- open up the properties.
(
$.modifiers[#Edit_Poly].DetachToObject "door01"
max select none
select $door01
max properties
)
When I do this, the next time I run the script, it selects the first portal and not the new portal. How can get it to select the new detached object? Such as door02.
What you can do is to have a new name for each door instead of calling all of them door01. That way you won’t have problems selecting them. So what you should do is to generate dinamically the name of the door and then using it both for the detach and the select. I think it’s easier to understand watching the code than with my clumsy explanation (sorry):
myDoorName = uniquename “door”
$.modifiers[#Edit_Poly].DetachToObject myDoorName
max select none
select (getNodebyname myDoorName)
max properties
hope this helps
/Lui
Thanks! This work great.
Now I’ve added the script to a menu, and since then I’ve discovered the ability to make the menu disabled base on the condition. Right now, an object has to be selected to be able to pick the menu item. Can I force the menu item to only be active if a polygon (edit poly) is selected? Below is my working code, but I wan’t to replace the “(selection.count >=1) with what would be selection is a polygon selected.
(
on isEnabled return (selection.count >= 1)
on Execute do
(
myDoorName = uniquename "door"
$.modifiers[#Edit_Poly].DetachToObject myDoorName
max select none
select (getNodebyname myDoorName)
max properties
)
Thank You for your help and input!
try using
on isEnabled return (selection.count == 1 and $.modifiers[#edit_Poly] != undefined)
(I think you want it to work just if there’s one object selected and no more…)
/Lui
That worked fine. I needed Polygons and not mesh, so this shows up in the menu as being disable if the user is selecting a sub-object that’s not a polygon. Although you can select a vert, and it will still be enable, it’s better than before.
Thanks! I’m slowly learning.
try adding
and subObjectLevel == 4
subObjectLevel lets you get and set the sub-object level in the Modify panel if it is open:
1: vertex
2: edge
3: border
4: polygon
5: element
/Lui
It can’t normal work, why ?
myDoorName = uniquename “door”
polyop.detachFaces $ (getFaceSelection $) delete:true asNode:true name:“door”
subobjectLevel = 0
max select none
select (getNodebyname myDoorName)