def CreateRecordText(record): results = "" if record.cause != TRecordCause.rcInfoError: pass else: results = results + "DE-SERIALISED PAYLOAD:" if None != record.schema: results = results + "\n schema = " + str( record.schema) results = results + "\n cause specified = " + str( record.causeSpecified) results = results + "\n cause = " + str(record.cause) if None != record.Frame: results = results + "\n frame = " + str( record.Frame) if None != record.Summary: results = results + "\n summary = " + str( record.Summary) if None != record.Overview: results = results + "\n overview = " + str( record.Overview) if None != record.SourceCodeReference: results = results + "\n sourcecode reference line specified = " + str( record.SourceCodeReference.lineSpecified) results = results + "\n sourcecode reference line = " + str( record.SourceCodeReference.line) results = results + "\n sourcecode reference line description = " + str( record.SourceCodeReference.description) results = results + "\n sourcecode reference line path = " + str( record.SourceCodeReference.path) if None != record.Field: for field in record.Field: if None != field: results = results + "\n field name = " + str(field.name) for obj in field.Items: if obj is TValue: value = clr.Convert(obj, TValue) if None != value.Text: for svalue in value.Text: results = results + "\n value = " + str( svalue) if None != value.i: index = 0 for svalue in value.i: results = results + "\n value[" + str( index) + "] = " + str(svalue) index = index + 1 elif obj is TField: innerField = clr.Convert(obj, TField) results = results + "\n field name = " + str( innerField.name) if innerField.decodeSpecified: results = results + "\n found decode attribute = " + str( innerField.decode) return results
def toBinaryArray(self, mesh, i): res = List[Byte]() for x in self.getData(mesh, i): if self.isFloat: res.AddRange(BitConverter.GetBytes(clr.Convert(x, Single))) else: res.AddRange(BitConverter.GetBytes(clr.Convert(x, Int32))) return res
def exctractGlazingVertices(hostElement, baseFace, opt): """Return glazing vertices for a window family instance. I was hoping that revit supports a cleaner way for doing this but for now I calculate the bounding box and find the face that it's vertices are coplanar with the host face. """ # get 3d faces for the geometry # TODO: Take all the vertices for daylight modeling faces = (clr.Convert(obj, Solid).Faces for obj in hostElement.get_Geometry(opt)) _outerFace = next(faces)[0].ToProtoType()[0] openings = (tuple(edge.StartVertex.PointGeometry for edge in loop.CoEdges) for face in _outerFace.Faces for loop in face.Loops[:-1]) coordinates = (tuple( tuple(baseFace.ClosestPointTo(pt) for pt in opening) for opening in openings)) # cleaning up (pt.Dispose() for opening in openings for pt in opening) (face.Dispose() for faceGroup in faces for face in faceGroup) filteredCoordinates = tuple(coorgroup if len(set(coorgroup)) > 2 else None for coorgroup in coordinates) return filteredCoordinates
def test_System_DateTime_conversion(self): example = datetime.datetime(2015, 4, 25, 8, 39, 54) result = clr.Convert(example, DateTime) self.assertIsInstance(result, DateTime) expected = DateTime(2015, 4, 25, 8, 39, 54) self.assertEqual(expected, result)
def astype(self, dtype): preshape = self.shape tmp = self.owncls(clr.Convert(self.parent, GetNdClass(dtype).NdArray)) # For some reason the type conversion throws away the shape :( if tmp.shape != preshape: tmp = tmp.reshape(preshape) return tmp
def BytesToGeometryBase(bytes): with System.IO.MemoryStream() as stream: formatter = System.Runtime.Serialization.Formatters.Binary.BinaryFormatter() stream.Write(bytes, 0, bytes.Length) stream.Seek(0, System.IO.SeekOrigin.Begin) obj = formatter.Deserialize(stream) geometry = clr.Convert(obj, Rhino.Geometry.GeometryBase) if geometry and geometry.IsValid: return geometry
def __init__(self): vp = ValidatorParameters() ############################################################### # below are just the default values and can be deleted as is. # ############################################################### # SetAllTables() is the default, but an explicit list also works. vp.SetAllTables() vp.ClearTables() vp.tablesToTest = List[str](['BASE', 'CBDT', 'CBLC', 'CFF ', 'cmap', 'COLR', 'CPAL', 'cvt ', 'DSIG', 'EBDT', 'EBLC', 'EBSC', 'fpgm', 'gasp', 'GDEF', 'glyf', 'GPOS', 'GSUB', 'hdmx', 'head', 'hhea', 'hmtx', 'JSTF', 'kern', 'loca', 'LTSH', 'MATH', 'maxp', 'name', 'OS/2', 'PCLT', 'post', 'prep', 'SVG ', 'VDMX', 'vhea', 'vmtx', 'VORG']) vp.doRastBW = False vp.doRastGray = False vp.doRastClearType = False vp.doRastCTCompWidth = False vp.doRastCTVert = False vp.doRastCTBGR = False vp.doRastCTFractWidth = False vp.xRes = 96 vp.yRes = 96 vp.xform.stretchX = 1.0 vp.xform.stretchY = 1.0 vp.xform.rotation = 0.0 vp.xform.skew = 0.0 # Python does not have single precision, but C# does. # casting from int to Single is automatic, Double to Single isn't. vp.xform.matrix[0,0] = clr.Convert(1.0, Single) vp.xform.matrix[0,1] = 0 vp.xform.matrix[0,2] = 0 vp.xform.matrix[1,0] = 0 vp.xform.matrix[1,1] = 1 vp.xform.matrix[1,2] = 0 vp.xform.matrix[2,0] = 0 vp.xform.matrix[2,1] = 0 vp.xform.matrix[2,2] = 1 vp.sizes = List[int]([4,5,6,7,8,9,10, 11,12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28,29,30, 31,32,33,34,35,36,37,38,39,40, 41,42,43,44,45,46,47,48,49,50, 51,52,53,54,55,56,57,58,59,60, 61,62,63,64,65,66,67,68,69,70, 71,72, 80,88,96,102,110,118,126]) ############################################################### ################## default values end ######################### ############################################################### self.vp = vp
def __init__(self, filename): self.filename = filename self.f = OTFile() self.f.open(filename) for i in range(0, self.f.GetNumFonts()): fn = self.f.GetFont(i) tname = fn.GetTable("name") print tname.GetNameString() print "Name\tCheckSum\tLength\tOffset" print "=========================================" for j in range(0, fn.GetNumTables()): de = fn.GetDirectoryEntry(j) print "%s\t0x%s\t%d\t%d" % (clr.Convert( de.tag, String), de.checkSum.ToString("X8"), de.length, de.offset) print if (self.f.IsCollection()): ttch = self.f.GetTTCHeader() if ((clr.Convert(ttch.DsigTag, String) == "DSIG") and (ttch.DsigOffset > 0)): print "DSIG (offset,length):\t%d,%d" % (ttch.DsigOffset, ttch.DsigLength)
def toBinaryArray(self): res = List[Byte]() res.AddRange(BitConverter.GetBytes(self.position.X)) res.AddRange(BitConverter.GetBytes(self.position.Y)) res.AddRange(BitConverter.GetBytes(self.normal.X)) res.AddRange(BitConverter.GetBytes(self.normal.Y)) res.AddRange(BitConverter.GetBytes(self.normal.Z)) res.AddRange(BitConverter.GetBytes(self.position.Z)) res.AddRange(BitConverter.GetBytes(self.texCoord.X)) res.AddRange(BitConverter.GetBytes(self.texCoord.Y)) res.AddRange(BitConverter.GetBytes(clr.Convert(self.boneIDs[0], Int32))) res.AddRange(BitConverter.GetBytes(clr.Convert(self.boneIDs[1], Int32))) res.AddRange(BitConverter.GetBytes(clr.Convert(self.boneIDs[2], Int32))) res.AddRange(BitConverter.GetBytes(clr.Convert(self.boneIDs[3], Int32))) res.AddRange(BitConverter.GetBytes(self.boneWeights.X)) res.AddRange(BitConverter.GetBytes(self.boneWeights.Y)) res.AddRange(BitConverter.GetBytes(self.boneWeights.Z)) res.AddRange(BitConverter.GetBytes(self.boneWeights.W)) return Enumerable.ToArray(res)
def SampleTextBox(): go = GetTextObject() go.SetCommandPrompt("Select text") go.Get() if go.CommandResult() != Rhino.Commands.Result.Success: return obj = go.Object(0).Object() text = extrusion_obj = clr.Convert(obj, Rhino.DocObjects.TextObject) if not text: return plane = text.TextGeometry.Plane xform = Rhino.Geometry.Transform.ChangeBasis(Rhino.Geometry.Plane.WorldXY, plane) curves = text.TextGeometry.Explode() tbox = Rhino.Geometry.BoundingBox.Empty for crv in curves: bbox = crv.GetBoundingBox(xform) tbox.Union(bbox) rmin = Rhino.Geometry.Interval(tbox.Min.X, tbox.Max.X) rmax = Rhino.Geometry.Interval(tbox.Min.Y, tbox.Max.Y) rect = Rhino.Geometry.Rectangle3d(plane, rmin, rmax) pline = rect.ToPolyline() curve = Rhino.Geometry.PolylineCurve(pline) # Scale based on a percentage of the height of the rectangle. # Change this value to adjust padding scale = 0.1 height = rect.Corner(0).DistanceTo(rect.Corner(3)) * scale tol = sc.doc.ModelAbsoluteTolerance corner_style = Rhino.Geometry.CurveOffsetCornerStyle.Sharp offsets = curve.Offset(plane, height, tol, corner_style) sc.doc.Objects.AddCurve(offsets[0]) sc.doc.Views.Redraw()
def _getAssemblyInfo(self): if not self.assemblies and not self.ref: return for ass in self.assemblies: realass = clr.Convert(ass, Assembly) realassCode = None realassLoc = None realassVer = None realassName = None try: realassVer = realass.GetName().Version.ToString() except (System.NotSupportedException, System.MissingMemberException): pass try: realassCode = realass.CodeBase except (System.NotSupportedException, System.MissingMemberException): pass try: realassLoc = realass.Location except (System.NotSupportedException, System.MissingMemberException): pass if realass: if realass.GetName() and 'System' in realass.GetName().Name and \ '.' not in realass.GetName().Name: self._ipms['sys']['isloaded'] = True if realassVer: self._ipms['sys']['ver'] = realassVer if realassCode: if 'GAC' in realassCode: self._ipms['sys']['isLocal'] = False elif self.appName.strip() in realassCode: self._ipms['sys']['isLocal'] = True self._ipms['sys']['path'] = realassCode if not realassCode and realassLoc == '': self._ipms['sys']['isLocal'] = True if 'IronPython' in realass.GetName().Name and \ '.' not in realass.GetName().Name: self._ipms['ipy']['isloaded'] = True if realassVer: self._ipms['ipy']['ver'] = realassVer if realassCode: if 'GAC' in realassCode: self._ipms['ipy']['isLocal'] = False elif self.appName.strip() in realassCode: self._ipms['ipy']['isLocal'] = True self._ipms['ipy']['path'] = realassCode if not realassCode and realassLoc == '': self._ipms['ipy']['isLocal'] = True sep = ',' assert len(sep) == 1, 'bad sep format' if self.ref: if all(std not in realass.GetName().Name \ for std in self._stdAss): self._aref['name'] = self.ref #reset to make sure it matches with name found in realass realassVer = None realassCode = None realassLoc = None realassName = None try: realassName = realass.GetName().Name except Exception as ex: pass if self.ref and realassName and self.ref in realassName: try: realassVer = realass.GetName().Version.ToString() except Exception as exa: pass try: realassCode = realass.CodeBase except Exception as exb: pass try: realassLoc = realass.Location except Exception as exc: pass if realassVer: self.found = True self._aref['isloaded'] = True self._aref['ver'] = realassVer if realassCode: self._aref['path'] = realassCode if 'GAC' in realassCode: self._aref['isLocal'] = False elif self.ref in realassCode: self._aref['isLocal'] = False if self.ref in realassCode and ':' not in realassCode: self._aref['isLocal'] = True elif not realassCode: if realassLoc == '': self._aref['isLocal'] = True elif self.ref and sys and not self.found or \ (self.ref and not 'StdLib' in self.ref and \ realassVer == "0.0.0.0"): self.found = self._getModules() if self.ref and not self.found and 'StdLib' not in self.ref: self._aref = {self.ref: 'Not Found'} if self.ref and sys and not self.found and not 'StdLib' in self.ref: self.found = self._getModules()
def update_release_date(self, game_obj, model): release_date = game_obj['release_date'] if release_date: model.ReleaseDate = clr.Convert(release_date, System.DateTime)
index) + "] = " + str(svalue) index = index + 1 elif obj is TField: innerField = clr.Convert(obj, TField) results = results + "\n field name = " + str( innerField.name) if innerField.decodeSpecified: results = results + "\n found decode attribute = " + str( innerField.decode) return results if __name__ == "__main__": # 创建 Log server的实例 _alsi = AniteLoggingServerInterface() _alsi = clr.Convert(_alsi, IAniteLoggingServer2) print(_alsi) if _alsi is None: print("object is null") print(_alsi.GetVersion()) print(_alsi.GetBuiltInAlsiSchemaVersion.ToString()) _connection = _alsi.Connection _connection = clr.Convert(_connection, IConnection) _connection.OnConnected += Connected _connection.OnDisconnected += Disconnected print(_connection) # 获取Log Server的信息 status = _alsi.CheckLoggingServerCompatability() print(status) if status.Code == Alsi.StatusCode.Ok: