/// <summary> /// Compute the Eastings, Northings, OrthogonalHeight from the selected SiteTransformationBasis and scale values /// </summary> /// <param name="doc">The document</param> /// <param name="wcsBasis">The selected coordinate base</param> /// <returns>A Tuple of scaled values for Eastings, Northings, and OrthogonalHeight</returns> public static (double eastings, double northings, double orthogonalHeight) ScaledGeoReferenceInformation(Document doc, SiteTransformBasis wcsBasis) { (double eastings, double northings, double orthogonalHeight)geoRef = GeoReferenceInformation(doc, wcsBasis); FormatOptions lenFormatOptions = doc.GetUnits().GetFormatOptions(SpecTypeId.Length); ForgeTypeId lengthUnit = lenFormatOptions.GetUnitTypeId(); geoRef.eastings = UnitUtils.ConvertFromInternalUnits(geoRef.eastings, lengthUnit); geoRef.northings = UnitUtils.ConvertFromInternalUnits(geoRef.northings, lengthUnit); geoRef.orthogonalHeight = UnitUtils.ConvertFromInternalUnits(geoRef.orthogonalHeight, lengthUnit); return(geoRef); }
private ForgeTypeId GetLengthUnitType(Document document) { ForgeTypeId specTypeId = SpecTypeId.Length; Units projectUnit = document.GetUnits(); try { FormatOptions formatOption = projectUnit.GetFormatOptions(specTypeId); return(formatOption.GetUnitTypeId()); } catch (System.Exception /*e*/) { return(UnitTypeId.Feet); } }
/// <summary> /// Compute the Eastings, Northings, OrthogonalHeight from the selected SiteTransformationBasis and scale values /// </summary> /// <param name="doc">The document</param> /// <param name="wcsBasis">The selected coordinate base</param> /// <returns>A Tuple of scaled values for Eastings, Northings, and OrthogonalHeight</returns> public static (double eastings, double northings, double orthogonalHeight, double angleTN, double origAngleTN) ScaledGeoReferenceInformation (Document doc, SiteTransformBasis wcsBasis, ProjectLocation projLocation = null) { (double eastings, double northings, double orthogonalHeight, double angleTN, double origAngleTN)geoRef = GeoReferenceInformation(doc, wcsBasis, projLocation); FormatOptions lenFormatOptions = doc.GetUnits().GetFormatOptions(SpecTypeId.Length); ForgeTypeId lengthUnit = lenFormatOptions.GetUnitTypeId(); geoRef.eastings = UnitUtils.ConvertFromInternalUnits(geoRef.eastings, lengthUnit); geoRef.northings = UnitUtils.ConvertFromInternalUnits(geoRef.northings, lengthUnit); geoRef.orthogonalHeight = UnitUtils.ConvertFromInternalUnits(geoRef.orthogonalHeight, lengthUnit); FormatOptions angleFormatOptions = doc.GetUnits().GetFormatOptions(SpecTypeId.Angle); ForgeTypeId angleUnit = angleFormatOptions.GetUnitTypeId(); geoRef.angleTN = UnitUtils.ConvertFromInternalUnits(geoRef.angleTN, angleUnit); return(geoRef); }
/// <summary> /// Reads pipe fitting family, segment, size, schedule, and routing preference data from a document and summarizes it in Xml. /// </summary> /// <returns>An XDocument containing an Xml summary of routing preference information</returns> public XDocument CreateXmlFromAllPipingPolicies(ref bool pathsNotFound) { //To export the full path name of all .rfa family files, use the FindFolderUtility class. FindFolderUtility findFolderUtility = new FindFolderUtility(m_document.Application); XDocument routingPreferenceBuilderDoc = new XDocument(); XElement xroot = new XElement(XName.Get("RoutingPreferenceBuilder")); FormatOptions formatOptionPipeSize = m_document.GetUnits().GetFormatOptions(SpecTypeId.PipeSize); string unitStringPipeSize = formatOptionPipeSize.GetUnitTypeId().TypeId; xroot.Add(new XAttribute(XName.Get("pipeSizeUnits"), unitStringPipeSize)); FormatOptions formatOptionRoughness = m_document.GetUnits().GetFormatOptions(SpecTypeId.PipingRoughness); string unitStringRoughness = formatOptionRoughness.GetUnitTypeId().TypeId; xroot.Add(new XAttribute(XName.Get("pipeRoughnessUnits"), unitStringRoughness)); foreach (FamilySymbol familySymbol in this.m_fittings) { xroot.Add(CreateXmlFromFamily(familySymbol, findFolderUtility, ref pathsNotFound)); } foreach (PipeType pipeType in m_pipeTypes) { xroot.Add(CreateXmlFromPipeType(pipeType)); } foreach (PipeScheduleType pipeScheduleType in m_pipeSchedules) { xroot.Add(CreateXmlFromPipeScheduleType(pipeScheduleType)); } foreach (PipeSegment pipeSegment in m_segments) { xroot.Add(CreateXmlFromPipeSegment(pipeSegment)); } foreach (PipeType pipeType in m_pipeTypes) { xroot.Add(CreateXmlFromRoutingPreferenceManager(pipeType.RoutingPreferenceManager)); } routingPreferenceBuilderDoc.Add(xroot); return(routingPreferenceBuilderDoc); }
public static double ConvertValueDocumentUnits(double decimalFeet, Autodesk.Revit.DB.Document document) { FormatOptions formatOption = document.GetUnits().GetFormatOptions(SpecTypeId.PipeSize); return(UnitUtils.ConvertFromInternalUnits(decimalFeet, formatOption.GetUnitTypeId())); }
private string FormatBoundedValue(IFCPropertyValue propertyValue) { if (IFCUnit != null) { FormatValueOptions formatValueOptions = new FormatValueOptions(); FormatOptions specFormatOptions = IFCImportFile.TheFile.Document.GetUnits().GetFormatOptions(IFCUnit.Spec); specFormatOptions.Accuracy = 1e-8; if (specFormatOptions.CanSuppressTrailingZeros()) { specFormatOptions.SuppressTrailingZeros = true; } formatValueOptions.SetFormatOptions(specFormatOptions); // If ScaleValues is false, value is in source file units, but 'UnitFormatUtils.Format' expects // it in internal units and it then converts it to display units, which should be the same as // the source file units. double value = Importer.TheProcessor.ScaleValues ? propertyValue.AsDouble() : UnitUtils.ConvertToInternalUnits(propertyValue.AsDouble(), specFormatOptions.GetUnitTypeId()); return(UnitFormatUtils.Format(IFCImportFile.TheFile.Document.GetUnits(), IFCUnit.Spec, value, false, formatValueOptions)); } else { return(propertyValue.ValueAsString()); } }
/// <summary> /// Reads data from an Xml source and loads pipe fitting families, creates segments, sizes, schedules, and routing preference rules from the xml data. /// </summary> /// <param name="xDoc">The Xml data source to read from</param> public void ParseAllPipingPoliciesFromXml(XDocument xDoc) { if (m_pipeTypes.Count() == 0) { throw new RoutingPreferenceDataException("No pipe pipes defined in this project. At least one must be defined."); } FormatOptions formatOptionPipeSize = m_document.GetUnits().GetFormatOptions(SpecTypeId.PipeSize); string docPipeSizeUnit = formatOptionPipeSize.GetUnitTypeId().TypeId; string xmlPipeSizeUnit = xDoc.Root.Attribute("pipeSizeUnits").Value; if (docPipeSizeUnit != xmlPipeSizeUnit) { throw new RoutingPreferenceDataException("Units from XML do not match current pipe size units."); } FormatOptions formatOptionRoughness = m_document.GetUnits().GetFormatOptions(SpecTypeId.PipingRoughness); string docRoughnessUnit = formatOptionRoughness.GetUnitTypeId().TypeId; string xmlRoughnessUnit = xDoc.Root.Attribute("pipeRoughnessUnits").Value; if (docRoughnessUnit != xmlRoughnessUnit) { throw new RoutingPreferenceDataException("Units from XML do not match current pipe roughness units."); } Transaction loadFamilies = new Transaction(m_document, "Load Families"); loadFamilies.Start(); IEnumerable <XElement> families = xDoc.Root.Elements("Family"); FindFolderUtility findFolderUtility = new FindFolderUtility(m_document.Application); foreach (XElement xfamily in families) { try { ParseFamilyFromXml(xfamily, findFolderUtility); //Load families. } catch (Exception ex) { loadFamilies.RollBack(); throw ex; } } loadFamilies.Commit(); Transaction addPipeTypes = new Transaction(m_document, "Add PipeTypes"); addPipeTypes.Start(); IEnumerable <XElement> pipeTypes = xDoc.Root.Elements("PipeType"); foreach (XElement xpipeType in pipeTypes) { try { ParsePipeTypeFromXml(xpipeType); //Define new pipe types. } catch (Exception ex) { addPipeTypes.RollBack(); throw ex; } } addPipeTypes.Commit(); Transaction addPipeSchedules = new Transaction(m_document, "Add Pipe Schedule Types"); addPipeSchedules.Start(); IEnumerable <XElement> pipeScheduleTypes = xDoc.Root.Elements("PipeScheduleType"); foreach (XElement xpipeScheduleType in pipeScheduleTypes) { try { ParsePipeScheduleTypeFromXml(xpipeScheduleType); //Define new pipe schedule types. } catch (Exception ex) { addPipeSchedules.RollBack(); throw ex; } } addPipeSchedules.Commit(); //The code above have added some new pipe types, schedules, or fittings, so update the lists of all of these. UpdatePipeTypesList(); UpdatePipeTypeSchedulesList(); UpdateFittingsList(); Transaction addPipeSegments = new Transaction(m_document, "Add Pipe Segments"); addPipeSchedules.Start(); IEnumerable <XElement> pipeSegments = xDoc.Root.Elements("PipeSegment"); //Define new segments. foreach (XElement xpipeSegment in pipeSegments) { try { ParsePipeSegmentFromXML(xpipeSegment); } catch (Exception ex) { addPipeSchedules.RollBack(); throw ex; } } addPipeSchedules.Commit(); UpdateSegmentsList(); //More segments may have been created, so update the segment list. //Now that all of the various types that routing preferences use have been created or loaded, add all the routing preferences. Transaction addRoutingPreferences = new Transaction(m_document, "Add Routing Preferences"); addRoutingPreferences.Start(); IEnumerable <XElement> routingPreferenceManagers = xDoc.Root.Elements("RoutingPreferenceManager"); foreach (XElement xroutingPreferenceManager in routingPreferenceManagers) { try { ParseRoutingPreferenceManagerFromXML(xroutingPreferenceManager); } catch (Exception ex) { addRoutingPreferences.RollBack(); throw ex; } } addRoutingPreferences.Commit(); }