Is this possible with python
-
On 14/05/2014 at 21:45, xxxxxxxx wrote:
Can you create a polygon object from a file(Text file)
if I have the polygon structure of a object and put it in a Text File, can I recreate it with python from that Text File.
Is this even possible ???? -
On 15/05/2014 at 01:54, xxxxxxxx wrote:
Of course, read the file with all the information and create the object based on that input.
E.g. a cube shaped object could be like:
recube = c4d.BaseObject(c4d.Opolygon) recube.ResizeObject(8,6) #8 vertexes (points) and 6 polygones recube.SetPoint(0,vertex1) recube.SetPoint(1,vertex2) recube.SetPoint(2,vertex3) recube.SetPoint(3,vertex4) recube.SetPoint(4,vertex5) recube.SetPoint(5,vertex6) recube.SetPoint(6,vertex7) recube.SetPoint(7,vertex8) recube.SetPolygon(0,c4d.CPolygon(0,1,2,3)) recube.SetPolygon(1,c4d.CPolygon(4,5,1,0)) recube.SetPolygon(2,c4d.CPolygon(7,6,5,4)) recube.SetPolygon(3,c4d.CPolygon(3,2,6,7)) recube.SetPolygon(4,c4d.CPolygon(1,5,6,2)) recube.SetPolygon(5,c4d.CPolygon(0,4,7,3)) recube.Message (c4d.MSG_UPDATE)
-
On 15/05/2014 at 05:11, xxxxxxxx wrote:
recube.SetPoint(0,vertex1) recube.SetPoint(1,vertex2) recube.SetPoint(2,vertex3) recube.SetPoint(3,vertex4) recube.SetPoint(4,vertex5) recube.SetPoint(5,vertex6) recube.SetPoint(6,vertex7) recube.SetPoint(7,vertex8) recube.SetPolygon(0,c4d.CPolygon(0,1,2,3)) recube.SetPolygon(1,c4d.CPolygon(4,5,1,0)) recube.SetPolygon(2,c4d.CPolygon(7,6,5,4)) recube.SetPolygon(3,c4d.CPolygon(3,2,6,7)) recube.SetPolygon(4,c4d.CPolygon(1,5,6,2)) recube.SetPolygon(5,c4d.CPolygon(0,4,7,3)) This code above I want python to read it for me from a file and then create a object from it.
-
On 15/05/2014 at 07:58, xxxxxxxx wrote:
I think I can explain better: _<_img src="http://www.c4dcafe.com/ipb/public/style_emoticons/default/oops.gif" border="0" alt=":oops:" title=":oops:" /_>_
I want to do these steps in python:
1] Create a empty polygon
2] Import the points from a ASCII File
3] Import the polygons from a ASCII FileBasically build the object from these steps in python
I see you can almost achieve this with call commands
import c4d
#Welcome to the world of Pythondef main() :
c4d.CallCommand(13039) # Empty Polygon Object
c4d.CallCommand(12530) # Points mode in Structure
c4d.CallCommand(13018) # Import ASCII Data (Points)
c4d.CallCommand(12532) # Polygons mode in Structure
c4d.CallCommand(13018) # Import ASCII Data (Polygons)if __name__=='__main__':
main() -
On 16/05/2014 at 01:25, xxxxxxxx wrote:
Sorry, is this working for you or do you still have some questions?
-
On 16/05/2014 at 01:38, xxxxxxxx wrote:
I still need help
refer to my second post
-
On 16/05/2014 at 04:08, xxxxxxxx wrote:
Ok, here a small example how to read ascii data.
#the world of Python in CINEMA 4D import c4d from c4d import storage, gui # # read ascii file and create object # def ReadAscii() : pointFile = "D:\Users\pgrooff\Documents\pim\c4d R15\import -export ascii\simple cube.txt" try: fpoints = open(pointFile) except IOError, e: gui.MessageDialog(e) return polysFile = "D:\Users\pgrooff\Documents\pim\c4d R15\import -export ascii\simple cube polys.txt" try: fpolys = open(polysFile) except IOError, e: gui.MessageDialog(e) return #split the file into line list lines = fpoints.readlines() #how many lines? so points nrPoints = len(lines) #split the file into line list linesPolys = fpolys.readlines() #how many lines? so polys nrPolys = len(linesPolys) #-1 for first line print "Nr points-polys: ", nrPoints-1, nrPolys-1 #create polygon object with point count of lines and count of polygons recube = c4d.BaseObject(c4d.Opolygon) recube.ResizeObject(nrPoints-1, nrPolys-1) #Points for i, line in enumerate(lines) : #split line into components coord = line.split(",") #ignore corrupt csv line if len(coord)<4: continue try: nr = int(coord[0]) x = float(coord[1]) y = float(coord[2]) z = float(coord[3]) except ValueError, e: continue recube.SetPoint(i-1,c4d.Vector(x,y,z)) print "Point inserted: ", i-1,x,y,z #Polys for i, line in enumerate(linesPolys) : #split line into components coord = line.split(",") #ignore corrupt csv line if len(coord)<5: continue try: nr = int(coord[0]) p1 = int(coord[1]) p2 = int(coord[2]) p3 = int(coord[3]) p4 = int(coord[4]) except ValueError, e: continue recube.SetPolygon(nr,c4d.CPolygon(p1,p2,p3,p4)) print "Poly inserted: ", nr,x,y,z doc.InsertObject(recube) recube.Message (c4d.MSG_UPDATE) c4d.EventAdd() if __name__=='__main__': ReadAscii()
I used the following input files. One for points and one for the polys.
I got these files by exporting a cube data to these files.
Later I edited the files, to add some ",".
But you can choose the format you want.Point file:
Point X Y Z 0, -100, -100 , -100 1, -100 , 100 , -100 2, 100, -100 , -100 3, 100 , 100 , -100 4, 100 , -100 , 100 5, 100 , 100, 100 6, -100, -100, 100 7, -100 , 100 , 100
Polygon file:
Polygon A B C D 0, 0, 1, 3, 2 1, 2, 3, 5, 4 2, 4, 5, 7, 6 3, 6, 7, 1, 0 4, 1, 7, 5, 3 5, 6, 0, 2, 4
-
On 16/05/2014 at 04:42, xxxxxxxx wrote:
Thanks pgroof _<_img src="http://www.c4dcafe.com/ipb/public/style_emoticons/default/thisrocks.gif" border="0" alt=":thisrocks:" title=":thisrocks:" /_>_
Will look at it tonight in detail -
On 16/05/2014 at 05:26, xxxxxxxx wrote:
Thanks pgroof you _<_img src="http://www.c4dcafe.com/ipb/public/style_emoticons/default/thisrocks.gif" border="0" alt=":thisrocks:" title=":thisrocks:" /_>_
Exactly what I was looking for&n;_<_img src="http://www.c4dcafe.com/ipb/public/style_emoticons/default/signthankspin.gif" border="0" alt=":signthankspin:" title=":signthankspin:" /_>_" />