def CreateSpline(interpolation = 2): doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document selection = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER) # Get active object selection (selection order enabled) positions = [] # Initialize empty list for objects' positions points = [] # Initialize empty list for spline points if interpolation < 2: interpolation = 2 # If too few points, fix it try: # Try to execute following script for obj in selection: # Loop through object in selection pos = obj.GetMg().off # Get objects global position positions.append(pos) # Insert object's position to position list doc.AddUndo(c4d.UNDOTYPE_BITS, obj) # Add undo command for changing bits obj.DelBit(c4d.BIT_ACTIVE) # Deselect object in Object Manager pointCount = interpolation*(len(positions)-1) # Calculate point count for x in range(0, len(positions)-1): # Loop through for i in range(0, interpolation): # Loop through step = 1.0/float((interpolation-1.0)) # Calculate new step for point point = u.MixVec(positions[x],positions[x+1],step*float(i)) # Calculate point position points.append(point) # Insert point position to points list spline = c4d.SplineObject(pointCount, c4d.SPLINETYPE_LINEAR) # Initialize spline object spline.SetAllPoints(points) # Set spline points from points list doc.InsertObject(spline) # Insert spline object to document doc.AddUndo(c4d.UNDOTYPE_NEW, spline) # Add undo command spline[c4d.SPLINEOBJECT_TYPE] = 0 # Set spline's type to Linear spline[c4d.SPLINEOBJECT_INTERPOLATION] = 0 # Set spline's interpolation to None doc.AddUndo(c4d.UNDOTYPE_CHANGE, spline) # Add undo command for making changes to spline object CenterAxis(spline) # Center spline's axis doc.AddUndo(c4d.UNDOTYPE_BITS, spline) # Add undo command for changing bits spline.SetBit(c4d.BIT_ACTIVE) # Select spline object in Object Manager c4d.CallCommand(14039) # Optimize, remove overlapping points except: # If something went wrong pass # Do nothing
def fusionSplines(lst_sp, nom = None, closed = True): """fusionne toute les splines de la liste en une seule en une""" pts = [] nb_seg = 0 seg = [] for sp in lst_sp: mg = sp.GetMg() pts.extend([p*mg for p in sp.GetAllPoints()]) if sp.GetSegmentCount(): for id in range(sp.GetSegmentCount()): seg.append(sp.GetSegment(id)['cnt']) nb_seg+=1 else : seg.append(sp.GetPointCount()) nb_seg+=1 nb_pts = sum([s.GetPointCount() for s in lst_sp]) res = c4d.SplineObject(nb_pts, c4d.SPLINETYPE_LINEAR) if nom : res.SetName(nom) res[c4d.SPLINEOBJECT_CLOSED] = closed res.ResizeObject(nb_pts,nb_seg) res.SetAllPoints(pts) for id,cnt in enumerate(seg): res.SetSegment(id,cnt,closed = closed) res.Message(c4d.MSG_UPDATE) return res
def main(): fn = '/Users/donzeo/SWITCHdrive/PYTHON/Requests_ESRI_REST_API/CARTE_NATIONALE_25K_1956_2009.json' fn = '/Users/donzeo/SWITCHdrive/PYTHON/Requests_ESRI_REST_API/CARTES_DUFOUR_1845_1935.json' fn = '/Users/donzeo/SWITCHdrive/PYTHON/Requests_ESRI_REST_API/PLAN_BASE_ARCHIVE_1936_2002.json' res = c4d.BaseObject(c4d.Onull) res.SetName(os.path.basename(fn)) origin = doc[CONTAINER_ORIGIN] if not origin: doc[CONTAINER_ORIGIN] = O_DEFAUT origin = O_DEFAUT with open(fn) as f: data = json.load(f) url = data['url'] for feat in data['features']: attr = feat['attributes'] geom = feat['geometry']['rings'][0] pts = [c4d.Vector(x, 0, y) - origin for x, y in geom] name = attr['Name'] sp = c4d.SplineObject(len(pts), c4d.SPLINETYPE_LINEAR) sp.SetName(name) sp.SetAllPoints(pts) sp.Message(c4d.MSG_UPDATE) sp.InsertUnderLast(res) doc.InsertObject(res) c4d.EventAdd()
def main(): a = doc.SearchObject("Null") if cF == 0: # only runs on frame 0 l = [] # loop iteration store list for x in xrange(nTimes): randindextv = random.randint( 0, (len(tV) - 1)) # Generates a random [i] for rM randrM = random.randint( 0, (len(rM) - 1)) # a random value is returned from rM list global X, Y, Z X = rM[randrM] # X vector is generated Y = rM[randrM] # Y vector is generated Z = rM[randrM] # Z vector is generated spline = c4d.SplineObject( (nTimes), c4d.SPLINETYPE_LINEAR ) # A spline with nTimes divisions is created if randindextv == 0: tV[0] += X # should these be globals? working in console though tV[1] += 0 tV[2] += 0 #print x, tV if randindextv == 1: #Y tV[0] += 0 tV[1] += Y tV[2] += 0 #print x, tV if randindextv == 2: tV[0] += 0 tV[1] += 0 tV[2] += Z #print x, tV l2 = [tV[0], tV[1], tV[2]] l.append(l2) for y in xrange(nTimes): spline.SetPoint(y, v(l[y][0], l[y][1], l[y][2])) spline[c4d.SPLINEOBJECT_CLOSED] = False if op: spline.InsertUnder(a) else: doc.InsertObject(spline) random.shuffle(l) else: return
def main(): path = '/Users/olivier.donze/TEMP/SHP_PRODUIT_CAD_BATI_3D/*.shp' res = c4d.BaseObject(c4d.Onull) for fn in glob(path): print(os.path.basename(fn)) analys = {} with shapefile.Reader(fn) as reader: if not reader.shapeType == shapefile.MULTIPATCH: print(fn) print('pas multipatch') #print(reader.fields) origin = doc[CONTAINER_ORIGIN] if not origin: xmin, ymin, xmax, ymax = reader.bbox origin = c4d.Vector((xmin + xmax) / 2, 0, (ymin + ymax) / 2) doc[CONTAINER_ORIGIN] = origin for shp in reader.iterShapes(): pts = [ c4d.Vector(x, z, y) - origin for (x, y), z in zip(shp.points, shp.z) ] segs = [] print(shp.parts) print(shp.partTypes) return #pour l'analyse des types de parts rencontrés #SITG/bati3D en 2020 uniquement type 2 (OUTER_RING) et 3 (INNER_RING) #for partType in shp.partTypes: #n = analys.get(partType,0) #analys[partType] = n+1 for p1, p2 in zip(shp.parts[:-1], shp.parts[1:]): nb_pts = p2 - p1 segs.append(nb_pts) sp = c4d.SplineObject(len(pts), c4d.SPLINETYPE_LINEAR) sp.SetAllPoints(pts) sp.ResizeObject(len(pts), len(segs)) for i, cnt in enumerate(segs): sp.SetSegment(i, cnt, closed=True) sp.Message(c4d.MSG_UPDATE) #sp.InsertUnderLast(res) print(analys) print('--------------------------') #doc.InsertObject(res) c4d.EventAdd()
def CreateSpline(pointCount, pointPositions): spline = c4d.SplineObject( pointCount, c4d.SPLINETYPE_LINEAR) # Initialize a spline object spline.SetAllPoints(pointPositions) # Set spline points spline[c4d.SPLINEOBJECT_TYPE] = 0 # Set spline's type to Linear spline[ c4d. SPLINEOBJECT_INTERPOLATION] = 0 # Set spline's interpolation to None return spline # Return the spline
def add_spline(row_count, points): spline = c4d.SplineObject(row_count, c4d.SPLINETYPE_BEZIER) doc.InsertObject(spline) doc.AddUndo(c4d.UNDOTYPE_NEW, spline) spline.SetAllPoints(points) c4d.EventAdd()
def GetSpline(self, origine=c4d.Vector(0)): """renvoie une spline c4d de la bbox""" res = c4d.SplineObject(4, c4d.SPLINETYPE_LINEAR) res[c4d.SPLINEOBJECT_CLOSED] = True res.SetAllPoints([ c4d.Vector(self.min.x, 0, self.max.z) - origine, c4d.Vector(self.max.x, 0, self.max.z) - origine, c4d.Vector(self.max.x, 0, self.min.z) - origine, c4d.Vector(self.min.x, 0, self.min.z) - origine ]) res.Message(c4d.MSG_UPDATE) return res
def CreateSpline(interpolation = 2): doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document selection = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER) # Get active object selection (selection order enabled) positions = [] # Initialize empty list for objects' positions points = [] # Initialize empty list for spline points if interpolation < 2: interpolation = 2 # If too few points, fix it try: # Try to execute following script for obj in selection: # Loop through object in selection pos = obj.GetMg().off # Get objects global position positions.append(pos) # Insert object's position to position list doc.AddUndo(c4d.UNDOTYPE_BITS, obj) # Add undo command for changing bits obj.DelBit(c4d.BIT_ACTIVE) # Deselect object in Object Manager pointCount = interpolation*(len(positions)-1) # Calculate point count for x in range(0, len(positions)-1): # Loop through for i in range(0, interpolation): # Loop through step = 1.0/float((interpolation-1.0)) # Calculate new step for point point = u.MixVec(positions[x],positions[x+1],step*float(i)) # Calculate point position points.append(point) # Insert point position to points list spline = c4d.SplineObject(pointCount, c4d.SPLINETYPE_LINEAR) # Initialize spline object spline.SetAllPoints(points) # Set spline points from points list doc.InsertObject(spline) # Insert spline object to document doc.AddUndo(c4d.UNDOTYPE_NEW, spline) # Add undo command for creating new object spline[c4d.SPLINEOBJECT_TYPE] = 3 # Set spline's type to B-Spline spline[c4d.SPLINEOBJECT_INTERPOLATION] = 2 # Set spline's interpolation to Uniform doc.AddUndo(c4d.UNDOTYPE_CHANGE, spline) # Add undo command for making changes to spline object CenterAxis(spline) # Center spline's axis splinePointsCount = len(spline.GetAllPoints()) # Get spline point count pointSelection = spline.GetPointS() # Get spline point selection # Point A pointSelection.DeselectAll() # Deselect all spline points pointSelection.Select(0) # Select spline's first point objectA = selection[0] # First object constraintTagA = spline.MakeTag(1018074) # Create hair constraint tag constraintTagA[c4d.HAIR_CONSTRAINTS_TAG_ANCHOR_LINK] = objectA # Set link doc.ExecutePasses(None, 0, 1, 1, 0) # Needed when pressing buttons virtually c4d.CallButton(constraintTagA, c4d.HAIR_CONSTRAINTS_TAG_SET_ANCHOR) # Press 'Set' button c4d.EventAdd() # Refresh Cinema 4D # Point B pointSelection.DeselectAll() # Deselect all spline points pointSelection.Select(splinePointsCount-1) # Select spline's first point objectB = selection[1] # Second object constraintTagB = spline.MakeTag(1018074) # Create hair constraint tag constraintTagB[c4d.HAIR_CONSTRAINTS_TAG_ANCHOR_LINK] = objectB # Set link doc.ExecutePasses(None, 0, 1, 1, 0) # Needed when pressing buttons virtually c4d.CallButton(constraintTagB, c4d.HAIR_CONSTRAINTS_TAG_SET_ANCHOR) # Press 'Set' button c4d.EventAdd() # Refresh Cinema 4D # Rest of the stuff spline.InsertTag(c4d.BaseTag(1018068)) # Insert spline dynamics tag doc.AddUndo(c4d.UNDOTYPE_BITS, spline) # Add undo command for changing bits spline.SetBit(c4d.BIT_ACTIVE) # Select spline object in Object Manager c4d.CallCommand(14039) # Optimize, remove overlapping points except: # If something went wrong pass # Do nothing
def main(): doc.StartUndo() selo = doc.GetActiveObjects(0) if len(selo) > 0: positions = [] for o in selo: # store positions md = mo.GeGetMoData(o) if md is None: return False cnt = md.GetCount() marr = md.GetArray(c4d.MODATA_MATRIX) for i in reversed(xrange(0, cnt)): positions.append(marr[i].off + o.GetAbsPos()) o.DelBit(c4d.BIT_ACTIVE) # make splines matrixA = positions[:len(positions) / 2] matrixB = positions[len(positions) / 2:] for x in xrange(0, len(matrixA)): points = [] c = 10 spline = c4d.SplineObject(c, c4d.SPLINETYPE_LINEAR) a = matrixA[x] # first point b = matrixB[x] # last point # subd spline for k in xrange(0, c): t = u.RangeMap(k, 0, c - 1, 0, 1, True) point = u.MixVec(a, b, t) points.append(point) spline.SetAllPoints(points) select_points = spline.GetPointS() pc = len(spline.GetAllPoints()) select_points.DeselectAll() select_points.Select(0) select_points.Select(pc - 1) spline.InsertTag(c4d.BaseTag(1018068)) tag = spline.MakeTag(1018068) doc.InsertObject(spline) doc.AddUndo(c4d.UNDOTYPE_NEW, spline) spline.SetBit(c4d.BIT_ACTIVE) c4d.CallButton(tag, c4d.HAIR_SDYNAMICS_TAG_SET_FIXED) c4d.EventAdd() doc.EndUndo()
def add_spline(row_count, points): #Create splie in memory #spline = c4d.BaseObject(c4d.Ospline) spline = c4d.SplineObject(row_count, c4d.SPLINETYPE_BEZIER) #Set obj names #spline.SetName("{} Spline Year {}".format(str(num).zfill(2), name)) #insert disc into the doc doc.InsertObject(spline) doc.AddUndo(c4d.UNDOTYPE_NEW, spline) spline.SetAllPoints(points) c4d.EventAdd()
def GuideSpline(cam, length): positions = [] pos1 = cam.GetMg().off m = c4d.Matrix() m.off = c4d.Vector(0, 0, length) mpos2 = cam.GetMg() * m pos2 = mpos2.off positions.append(pos1) positions.append(pos2) splineObject = c4d.SplineObject(2, c4d.SPLINETYPE_LINEAR) splineObject.SetAllPoints(positions) return splineObject
def GenerateSpline(self, name, color, position, d_points): i = 0 spline_product = c4d.SplineObject(len(d_points), 0) spline_product.SetName(name) spline_product[c4d.ID_BASEOBJECT_USECOLOR] = 2 spline_product[c4d.ID_BASEOBJECT_COLOR] = self.Colorize(color) for coords in d_points: try: spline_vec = c4d.Vector(coords[0], coords[1], coords[2]) spline_product.SetPoint(i, spline_vec) except IndexError: pass i = i + 1 return spline_product
def main(): doc.StartUndo() s = doc.GetSelection() p = int(gui.InputDialog("Subd multiplier",0)) spline = c4d.SplineObject(len(s), c4d.SPLINETYPE_LINEAR) points = [] for x in s: pos = x.GetMg().off points.append(pos) x.DelBit(c4d.BIT_ACTIVE) spline.SetAllPoints(points) doc.InsertObject(spline) doc.AddUndo(c4d.UNDOTYPE_NEW, spline) spline.SetBit(c4d.BIT_ACTIVE) for i in xrange(0, p): c4d.CallCommand(14047) c4d.EventAdd() doc.EndUndo()
def polyline(self, shp): pts = [c4d.Vector(x, 0, y) - self.centre for x, y in shp.points] nb_pts = len(pts) sp = c4d.SplineObject(nb_pts, c4d.SPLINETYPE_LINEAR) sp.SetAllPoints(pts) # SEGMENTS nb_seg = len(shp.parts) if nb_seg > 1: sp.ResizeObject(nb_pts, nb_seg) shp.parts.append(nb_pts) segs = [ fin - dbt for dbt, fin in zip(shp.parts[:-1], shp.parts[1:]) ] for i, n in enumerate(segs): sp.SetSegment(i, n, closed=True) sp.Message(c4d.MSG_UPDATE) sp.InsertUnderLast(self.geoms)
def shpPoly2spline(shp,centre,hasZ = False): pts = [] if hasZ: pts = [c4d.Vector(x, z, y) - centre for (x, y), z in zip(shp.points, shp.z)] else: pts = [c4d.Vector(x, 0, y) - centre for x, y in shp.points] nb_pts = len(pts) sp = c4d.SplineObject(nb_pts, c4d.SPLINETYPE_LINEAR) sp[c4d.SPLINEOBJECT_CLOSED] = True sp.SetAllPoints(pts) # SEGMENTS nb_seg = len(shp.parts) if nb_seg > 1: sp.ResizeObject(nb_pts, nb_seg) shp.parts.append(nb_pts) segs = [fin - dbt for dbt, fin in zip(shp.parts[:-1], shp.parts[1:])] for i, n in enumerate(segs): sp.SetSegment(i, n, closed=True) sp.Message(c4d.MSG_UPDATE) return sp
def shp2splines(fn, origin): """renvoie une liste de splines multisegments""" res = [] with shapefile.Reader(fn) as reader : if reader.shapeType not in [shapefile.POLYLINE, shapefile.POLYGON,shapefile.POLYLINEZ, shapefile.POLYGONZ]: return False if not origin: xmin,ymin,xmax,ymax = reader.bbox origin = c4d.Vector((xmin+ymin)/2,0,(xmax+ymax)/2) doc = c4d.documents.GetActiveDocument() doc[CONTAINER_ORIGIN] = origin closed = False if reader.shapeType in [shapefile.POLYGON, shapefile.POLYGONZ]: closed = True hasZ = False if reader.shapeType in [shapefile.POLYLINEZ, shapefile.POLYGONZ]: hasZ = True for shp in reader.iterShapes(): pts = getPts(shp, origin, hasZ) nb_pts = len(pts) sp = c4d.SplineObject(nb_pts, c4d.SPLINETYPE_LINEAR) sp.SetAllPoints(pts) # SEGMENTS nb_seg = len(shp.parts) if nb_seg > 1: sp.ResizeObject(nb_pts, nb_seg) shp.parts.append(nb_pts) segs = [fin - dbt for dbt, fin in zip(shp.parts[:-1], shp.parts[1:])] for i, n in enumerate(segs): sp.SetSegment(i, n, closed=closed) sp[c4d.SPLINEOBJECT_CLOSED] = closed sp.Message(c4d.MSG_UPDATE) res.append(sp) return res
def polygon(self,shp): pts = [c4d.Vector(x,0,y)-self.centre for x,y in shp.points] nb_pts = len(pts) #OBJET EXTRUSION extr = c4d.BaseObject(c4d.Oextrude) extr[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0) sp = c4d.SplineObject(nb_pts,c4d.SPLINETYPE_LINEAR) sp[c4d.SPLINEOBJECT_CLOSED] = True sp.SetAllPoints(pts) #SEGMENTS nb_seg = len(shp.parts) if nb_seg>1: sp.ResizeObject(nb_pts,nb_seg) shp.parts.append(nb_pts) segs = [fin-dbt for dbt,fin in zip(shp.parts[:-1], shp.parts[1:])] for i,n in enumerate(segs): sp.SetSegment(i,n,closed = True) sp.Message(c4d.MSG_UPDATE) sp.InsertUnder(extr) extr.InsertUnderLast(self.geoms)
def makeSpline(): selo = doc.GetActiveObjects(0) points = [] for o in selo: spline = c4d.SplineObject(2, c4d.SPLINETYPE_LINEAR) pos = o.GetMg().off points.append(pos) p = int(gui.InputDialog("Subd multiplier",4)) for x in selo: x.DelBit(c4d.BIT_ACTIVE) spline.SetAllPoints(points) doc.InsertObject(spline) doc.AddUndo(c4d.UNDOTYPE_NEW, spline) spline.SetBit(c4d.BIT_ACTIVE) # subdivide spline for i in xrange(0, p): c4d.CallCommand(14047) c4d.EventAdd() return spline
def main(): circle = c4d.SplineObject(pcnt=0, type=c4d.SPLINETYPE_BEZIER) circle[c4d.ID_BASELIST_NAME] = "Circle" circle[c4d.SPLINEOBJECT_CLOSED] = True bc0 = c4d.GetCustomDatatypeDefault(c4d.DTYPE_GROUP) bc0[c4d.DESC_NAME] = "Circle Attribute" bc0[c4d.DESC_DEFAULT] = 1 bc0[c4d.DESC_PARENTGROUP] = c4d.DescID(0) DesID0 = circle.AddUserData(bc0) bc1 = c4d.GetCustomDatatypeDefault(c4d.DTYPE_REAL) bc1[c4d.DESC_NAME] = "Radius" bc1[c4d.DESC_DEFAULT] = 200 bc1[c4d.DESC_MIN] = 0 bc2 = c4d.GetCustomDatatypeDefault(c4d.DTYPE_LONG) bc2[c4d.DESC_NAME] = "Point Number" bc2[c4d.DESC_DEFAULT] = 4 bc2[c4d.DESC_MIN] = 2 DescIDLs = [] for item in [bc1, bc2]: item[c4d.DESC_PARENTGROUP] = DesID0 DescID = circle.AddUserData(item) DescIDLs.append(DescID) circle[DescIDLs[0]] = 200 circle[DescIDLs[1]] = 4 # Core code in python tag pythonTag = c4d.BaseTag(c4d.Tpython) pythonTag[c4d.ID_BASELIST_NAME] = "Circle Modifier" pythonTag[c4d.TPYTHON_CODE] = ( """# Description: A script to create an arbitrary-number-of-point circle with bezier spline # Author: eZioPan # Page: github.com/eZioPan # License: Creative Commons Attribution Share Alike 4.0 # Version: 0.0.1 # Last Update: 2018Nov2 import c4d, math #Welcome to the world of Python deg = math.pi/180.0 def main(): circle = op.GetObject() pCnt = circle[c4d.ID_USERDATA,3] # Here is the point count radius = circle[c4d.ID_USERDATA,2] # Here is the radius of circle #Prepare the data tangentLength = (4/3)*math.tan(math.pi/(2*pCnt))*radius # single side tangent handle length pointPosLs = [] tangentLs = [] for i in range(0,pCnt): angle = i*(2*math.pi)/pCnt # caculate the angle # caculate point position y = math.sin(angle)*radius x = math.cos(angle)*radius pointPosLs.append(c4d.Vector(x, y, 0)) # tangent position lx = math.sin(angle)*tangentLength ly = -math.cos(angle)*tangentLength rx = -lx ry = -ly vl = c4d.Vector(lx, ly, 0) vr = c4d.Vector(rx, ry, 0) tangentLs.append([vl, vr]) # resize bezier curve circle.ResizeObject(pcnt=pCnt, scnt=1) circle.SetSegment(id=0, cnt=pCnt, closed=True) circle.SetAllPoints(pointPosLs) # set point position # set tangent position for i in range(0, pCnt): circle.SetTangent(i, tangentLs[i][0], tangentLs[i][1]) circle.Message(c4d.MSG_UPDATE) return circle """) circle.InsertTag(pythonTag) doc = c4d.documents.GetActiveDocument() doc.StartUndo() doc.InsertObject(circle) doc.SetActiveObject(circle, mode=c4d.SELECTION_NEW) doc.AddUndo(c4d.UNDOTYPE_NEW, circle) doc.EndUndo() c4d.EventAdd()
def main(): source = op.GetDown() source_spline = op[c4d.ID_USERDATA, 8].GetRealSpline().GetClone() if source_spline: random.seed(op[c4d.ID_USERDATA, 4]) initial_points = source_spline.GetAllPoints() if len(initial_points) > 1: duplicates = [initial_points] * (op[c4d.ID_USERDATA, 5] + 1) bolts = [ dict(points=bolt_points, iteration=0) for bolt_points in duplicates ] max_offset = op[c4d.ID_USERDATA, 3] for i in xrange(0, op[c4d.ID_USERDATA, 6]): new_branches = [] for bolt_data in bolts: bolt = bolt_data['points'] new_bolt = [bolt[0]] for pid in xrange(0, len(bolt) - 1): sp = bolt[pid] ep = bolt[pid + 1] np = (sp + ep) * .5 line_dir = (ep - sp).GetNormalized() up = c4d.Vector(random.uniform(-1, 1), random.uniform(-1, 1), random.uniform(-1, 1)).GetNormalized() offset_dist = random.uniform(-1, 1) * max_offset offset = line_dir.Cross( up).GetNormalized() * offset_dist np += offset new_bolt.extend([np, ep]) if random.random() > op[c4d.ID_USERDATA, 7]: new_branches.append([np, np + np - sp + offset]) bolt_data['points'] = new_bolt new_branches_data = [ dict(points=bolt_points, iteration=i) for bolt_points in new_branches ] bolts.extend(new_branches_data) max_offset *= .5 null = c4d.BaseObject(c4d.Onull) for bolt_data in bolts: bolt = bolt_data['points'] iteration = bolt_data['iteration'] spline = c4d.SplineObject(len(bolt), c4d.SPLINETYPE_LINEAR) spline.SetAllPoints(bolt) sweep = c4d.BaseObject(c4d.Osweep) spline.InsertUnder(sweep) crossection = source.GetClone() crossection.SetRelScale( c4d.Vector(1.0 / math.pow( (iteration + 1), (1 - op[c4d.ID_USERDATA, 1]) * 3))) crossection.InsertUnder(sweep) sweep.InsertUnder(null) sweep.SetPhong(True, True, 80) return null
def lineStringToSpline(ls): pts = [listToVector(p) for p in ls.coords] sp = c4d.SplineObject(len(pts), c4d.SPLINETYPE_LINEAR) sp.SetAllPoints(pts) sp.Message(c4d.MSG_UPDATE) return sp
def main(): # gui.MessageDialog('Hello World!') txt_fpath = "/Users/DML/OneDrive/Soccer Python/passing-networks-in-python-master/player_info.csv" txt_fpath_pass_values = "/Users/DML/OneDrive/Soccer Python/passing-networks-in-python-master/pair_pass_values.csv" # Nulls Names names = c4d.BaseObject(c4d.Onull) names[c4d.ID_BASELIST_NAME] = "Player Names" doc.InsertObject(names) c4d.EventAdd() # Nulls Circles circles = c4d.BaseObject(c4d.Onull) circles[c4d.ID_BASELIST_NAME] = "Player Circles" doc.InsertObject(circles) c4d.EventAdd() with open(txt_fpath, 'r') as read_obj: csv_reader = reader(read_obj) next(csv_reader) for row in csv_reader: c4d.CallCommand(5164, 5164) # Disc selected = doc.GetActiveObject() selected[c4d.PRIM_DISC_ORAD] = float(row[3]) * 10 selected[c4d.PRIM_DISC_IRAD] = float(row[3]) * 10 - 10 - float( row[3]) * 3 selected[c4d.ID_BASELIST_NAME] = row[0] selected[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_X] = 10500 * float(row[1]) - 10500 / 2 selected[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Z] = 6800 * float(row[2]) - 6800 / 2 selected.InsertUnder(circles) # place in Spline Null Object c4d.CallCommand(1019268, 1019268) # MoText selected = doc.GetActiveObject() selected[c4d.PRIM_TEXT_TEXT] = row[0] selected[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_X] = -1.571 selected[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Y] = -1.571 selected[c4d.PRIM_TEXT_ALIGN] = 1 selected[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_X] = 10500 * float(row[1]) - 10500 / 2 selected[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Z] = 6800 * float(row[2]) - 6800 / 2 selected[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Y] = 200 selected[c4d.PRIM_TEXT_HEIGHT] = 100 selected[c4d.MGTEXTOBJECT_SPLINEMOVE] = 0 selected.InsertUnder(names) # place in Spline Null Object pointCount = 3 with open(txt_fpath_pass_values, 'r') as read_obj: csv_reader = reader(read_obj) next(csv_reader) # Null Passes Low spline_null_low = c4d.BaseObject(c4d.Onull) spline_null_low[c4d.ID_BASELIST_NAME] = "Null_Spline_Low" doc.InsertObject(spline_null_low) c4d.EventAdd() # Null Passes High spline_null_high = c4d.BaseObject(c4d.Onull) spline_null_high[c4d.ID_BASELIST_NAME] = "Null_Spline_High" doc.InsertObject(spline_null_high) c4d.EventAdd() for line in csv_reader: # PASSES LOW if line[2] > 0: for i in range(int(round(float(line[2])))): Spline = c4d.SplineObject(pointCount, 0) Spline[c4d.SPLINEOBJECT_TYPE] = 3 Spline[c4d.SPLINEOBJECT_ANGLE] = 0 n = 0 # start point pos = c4d.Vector() pos.x = float(line[4]) * 10500 - 10500 / 2 pos.y = 0 pos.z = float(line[5]) * 6800 - 6800 / 2 Spline.SetPoint(n, pos) # distance between points # middle point pos2 = c4d.Vector() pos2.x = ( (float(line[4]) + float(line[6])) / 2) * 10500 - 10500 / 2 + random.randint(-100, 100) pos2.y = 20 # pos2.y = (line[10]*100) + ((line[10]*100)*0.9) - (52.5 - line[5]) # + random.randint(-100, 200) # pos2.y = ((line[7]+line[10])/2) *100 # (line[10]*100) + ((line[10]*100)*0.9) pos2.z = ((float(line[5]) + float(line[7])) / 2) * 6800 - 6800 / 2 + random.randint(-100, 100) Spline.SetPoint(n + 1, pos2) # end point Spline.SetPoint(n, pos) pos3 = c4d.Vector() pos3.x = float(line[6]) * 10500 - 10500 / 2 pos3.y = 0 pos3.z = float(line[7]) * 6800 - 6800 / 2 Spline.SetPoint(n + 2, pos3) n += 1 # distance between points dist_btw = calculateDistance(pos.x, pos.y, pos3.x, pos3.y) doc.InsertObject(Spline, checknames=True) myobject = doc.GetFirstObject() active().InsertUnder( spline_null_low) # place in Spline Null Object if line[2] > 0: for i in range(int(round(float(line[3])))): Spline = c4d.SplineObject(pointCount, 0) Spline[c4d.SPLINEOBJECT_TYPE] = 3 Spline[c4d.SPLINEOBJECT_ANGLE] = 0 n = 0 pos1x = float(line[4]) * 10500 - 10500 / 2 pos1z = float(line[5]) * 6800 - 6800 / 2 pos3x = float(line[6]) * 10500 - 10500 / 2 pos3z = float(line[7]) * 6800 - 6800 / 2 # start point pos = c4d.Vector() pos.x = pos1x pos.y = 0 pos.z = pos1z Spline.SetPoint(n, pos) # distance between points dist_btw = calculateDistance(pos.x, pos.y, pos3.x, pos3.y) # middle point pos2 = c4d.Vector() pos2.x = ( (float(line[4]) + float(line[6])) / 2) * 10500 - 10500 / 2 + random.randint(-100, 100) pos2.y = dist_btw / 3 + random.randint(-100, 100) # pos2.y = (line[10]*100) + ((line[10]*100)*0.9) - (52.5 - line[5]) # + random.randint(-100, 200) # pos2.y = ((line[7]+line[10])/2) *100 # (line[10]*100) + ((line[10]*100)*0.9) pos2.z = ((float(line[5]) + float(line[7])) / 2) * 6800 - 6800 / 2 + random.randint(-100, 100) Spline.SetPoint(n + 1, pos2) # end point Spline.SetPoint(n, pos) pos3 = c4d.Vector() pos3.x = pos3x pos3.y = 0 pos3.z = pos3z Spline.SetPoint(n + 2, pos3) n += 1 doc.InsertObject(Spline, checknames=True) myobject = doc.GetFirstObject() active().InsertUnder( spline_null_high) # place in Spline Null Object # combine null spline low selected = doc.SearchObject("Null_Spline_Low") doc.SetActiveObject(selected) c4d.CallCommand(100004768, 100004768) # Select Children c4d.CallCommand(16768, 16768) # Connect Objects + Delete selected = doc.GetActiveObject() selected[c4d.SPLINEOBJECT_ANGLE] = 0 selected[c4d.ID_BASELIST_NAME] = "Null_Spline_Low" # combine null spline high selected = doc.SearchObject("Null_Spline_High") doc.SetActiveObject(selected) c4d.CallCommand(100004768, 100004768) # Select Children c4d.CallCommand(16768, 16768) # Connect Objects + Delete selected = doc.GetActiveObject() selected[c4d.SPLINEOBJECT_ANGLE] = 0 selected[c4d.ID_BASELIST_NAME] = "Null_Spline_High" # Nulls Sweep Low sweep_low = c4d.BaseObject(c4d.Osweep) sweep_low[c4d.ID_BASELIST_NAME] = "Sweep Low" doc.InsertObject(sweep_low) c4d.EventAdd() # Nulls Sweep High sweep_high = c4d.BaseObject(c4d.Osweep) sweep_high[c4d.ID_BASELIST_NAME] = "Sweep High" doc.InsertObject(sweep_high) c4d.EventAdd() # Sweep rectangle low sweep_rect = c4d.BaseObject(c4d.Osplinerectangle) sweep_rect[c4d.PRIM_RECTANGLE_WIDTH] = 4 sweep_rect[c4d.PRIM_RECTANGLE_HEIGHT] = 4 sweep_rect[c4d.ID_BASELIST_NAME] = "Sweep Rect" doc.InsertObject(sweep_rect) c4d.EventAdd() # Sweep rectangle high sweep_rect_high = c4d.BaseObject(c4d.Osplinerectangle) sweep_rect_high[c4d.PRIM_RECTANGLE_WIDTH] = 4 sweep_rect_high[c4d.PRIM_RECTANGLE_HEIGHT] = 4 sweep_rect_high[c4d.ID_BASELIST_NAME] = "Sweep Rect High" doc.InsertObject(sweep_rect_high) c4d.EventAdd() # combine null sweep & rect selected = doc.SearchObject("Null_Spline_Low") doc.SetActiveObject(selected) selected.InsertUnder(sweep_low) selected = doc.SearchObject("Sweep Rect") doc.SetActiveObject(selected) selected.InsertUnder(sweep_low) selected = doc.SearchObject("Null_Spline_High") doc.SetActiveObject(selected) selected.InsertUnder(sweep_high) selected = doc.SearchObject("Sweep Rect High") doc.SetActiveObject(selected) selected.InsertUnder(sweep_high)