I am working in a plugin code to export a sketchup file containing a room to other applications.
In order to work with the exported room it is very important to provide a unique number to each of
the surfaces (Sketchup::Face) in the room, such that if the room is modified (for example by
deleting some of the surfaces or creating new ones) then the numbers of deleted surfaces are ignored
and new numbers (starting from maxSurfaceNumber) are used to numbering new surfaces. This is useful
for example to asses materials to the surfaces and retain this information even though the room is
with this aim I am attaching an attribute dictionary to the entities that are Sketchup::Face.
if (entity.is_a? Sketchup::Face) value = entity.get_attribute "MyDictoinary", "SurfaceNo",0 if (value==0) #this is a new surface not numbered before maxSurfaceNumber+=1 entity.set_attribute "MyDictoinary", "SurfaceNo", maxSurfaceNumber end end
where MaxSurfaceNumber is obtained beforehand looking at faces and keeping the highest value.
if (entity.is_a? Sketchup::Face) value = entity.get_attribute "MyDictoinary", "SurfaceNo",0 if (value > maxSurfaceNumber) maxSurfaceNumber = value end end
My problem is that when the face I am looking at is a “copy” of another face in the model (for example
if it is part of a ComponentInstance or a Group constructed by copying a master surface) then changing the
SurfaceNo in the copy is modifiying the master surface number and not the one of the copy I am looking at.
I figured out a way to do this if the copies belong to a ComponentInstance by using “make_unique” on
ComponentInstances that are copies before numbering the surfaces. Also notice that if I edit the groups
that are copies manually in SU (don’t know how to edit a group using ruby api) then I am getting individual
surfaces that can be numbered using the above code. Other solution is exploding Groups/Components in
the model before numbering.
I have the following questions:
1.- Is there any way to make this numbering of surfaces leaving the model unchanged?
2.- Is it possible to store this maxSurfaceNumber in the model once the numbering is done such that
we don’t need to look at all surfaces numbers every time the room is modified?
Thank you very much for your help, please let me know if you need further information to give me an answer.