On 01/12/2016 at 17:08, xxxxxxxx wrote:
I think I have come up with a script that will delete the inner polygons for you.
I've only tested it with a few cubes. But it seems to work.
*This a specific script targeted to your specific task(combining cubes). And probably won't work for objects other than cubes.
There is no error checking in this. So please be sure that you do this before running the script:
1 - Converted all of the cubes to polygon type objects first
2 - Have your cubes butted against each other properly so two polygons share the same position
3 - Selected all of the cube objects you want to combine
#This script combines all selected cube objects that are butted together into a single mesh
#Then it get's the center positions for all of the polygons
#Then it compares these positions to see if any two polygon's are in the same position (the inner polygons)
#Then it selects them if they are in the same position and deletes them
#Finally..it runs the optimize points command on the object's points
import c4d
def main() :
c4d.CallCommand(16768) #Connect Objects + Delete
obj = doc.GetActiveObject()
objmg = obj.GetMg()
poly = obj.GetAllPolygons()
PolyS = obj.GetPolygonS()
centers = []
#Loop through the list of polygons to get their points
for p in poly:
ptA = obj.GetPoint(p.a)
ptB = obj.GetPoint(p.b)
ptC = obj.GetPoint(p.c) #These are local point values
ptD = obj.GetPoint(p.d)
polyCenterL = (ptA + ptB + ptC + ptD)/4 #This is the local Midpoint position
polyCenterG = polyCenterL * objmg #Convert it to a global position
centers.append(polyCenterG)
#Find any two polygons that share the same center positions and select them
for i in xrange(len(centers)) :
for j in xrange(i + 1, len(centers)) :
if centers[i] == centers[j]:
PolyS.Select(i)
PolyS.Select(j)
#Delete the selected polygons
c4d.utils.SendModelingCommand(command=c4d.MCOMMAND_DELETE,
list=[obj],
mode=c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
doc=doc)
#Optimize (weld) the object's points
bc = c4d.BaseContainer()
bc.SetData(c4d.MDATA_OPTIMIZE_TOLERANCE, 1.5)
bc.SetData(c4d.MDATA_OPTIMIZE_POINTS, True)
bc.SetData(c4d.MDATA_OPTIMIZE_UNUSEDPOINTS,True)
c4d.utils.SendModelingCommand(c4d.MCOMMAND_OPTIMIZE, list = [obj], mode = c4d.MODIFY_ALL, bc=bc, doc = doc)
c4d.EventAdd()
if __name__=='__main__':
main()
-ScottA