bool IGH_TypeHint.Cast(object data, out object target) { bool toReturn = base.Cast(data, out target); if (toReturn && target != null) { Type t = target.GetType(); if (t == typeof(Line)) target = new LineCurve((Line)target); else if (t == typeof(Arc)) target = new ArcCurve((Arc)target); else if (t == typeof(Circle)) target = new ArcCurve((Circle)target); else if (t == typeof(Ellipse)) target = ((Ellipse)target).ToNurbsCurve(); else if (t == typeof(Box)) target = Brep.CreateFromBox((Box)target); else if (t == typeof(BoundingBox)) target = Brep.CreateFromBox((BoundingBox)target); else if (t == typeof(Rectangle3d)) target = ((Rectangle3d)target).ToNurbsCurve(); else if (target is Polyline) target = new PolylineCurve((Polyline)target); } return toReturn; }
bool IGH_TypeHint.Cast(object data, out object target) { bool toReturn = base.Cast(data, out target); if (m_component.DocStorageMode == DocReplacement.DocStorage.AutomaticMarshal && target != null) { Type t = target.GetType(); if (t == typeof (Line)) target = new LineCurve((Line) target); else if (t == typeof (Arc)) target = new ArcCurve((Arc) target); else if (t == typeof (Circle)) target = new ArcCurve((Circle) target); else if (t == typeof (Ellipse)) target = ((Ellipse) target).ToNurbsCurve(); else if (t == typeof (Box)) target = Brep.CreateFromBox((Box) target); else if (t == typeof (BoundingBox)) target = Brep.CreateFromBox((BoundingBox) target); else if (t == typeof (Rectangle3d)) target = ((Rectangle3d) target).ToNurbsCurve(); else if (t == typeof (Polyline)) target = new PolylineCurve((Polyline) target); } return toReturn; }
/// <summary> /// Initializes a new <see cref="ArcCurve"/> instance, /// copying values from another <see cref="ArcCurve"/>. /// </summary> /// <param name="other">Another ArcCurve.</param> public ArcCurve(ArcCurve other) { IntPtr pOther = IntPtr.Zero; if (null != other) pOther = other.ConstPointer(); IntPtr ptr = UnsafeNativeMethods.ON_ArcCurve_New(pOther); ConstructNonConstObject(ptr); }
/***************************************************/ public static bool IsEqual(this BHG.Arc bhArc, RHG.ArcCurve rhArc, double tolerance = BHG.Tolerance.Distance) { if (bhArc == null & rhArc == null) { return(true); } RHG.Arc innerArc; rhArc.TryGetArc(out innerArc); return(bhArc.IsEqual(innerArc, tolerance)); }
/// <summary> /// Initializes a new <see cref="ArcCurve"/> instance, /// copying values from another <see cref="ArcCurve"/>. /// </summary> /// <param name="other">Another ArcCurve.</param> public ArcCurve(ArcCurve other) { IntPtr pOther = IntPtr.Zero; if (null != other) { pOther = other.ConstPointer(); } IntPtr ptr = UnsafeNativeMethods.ON_ArcCurve_New(pOther); ConstructNonConstObject(ptr); }
bool IGH_TypeHint.Cast(object data, out object target) { bool toReturn = base.Cast(data, out target); if (toReturn && _component.DocStorageMode == DocReplacement.DocStorage.AutomaticMarshal && target != null) { Type t = target.GetType(); if (t == typeof (Circle)) target = new ArcCurve((Circle) target); } return toReturn; }
/***************************************************/ public static BHG.ICurve FromRhino(this RHG.ArcCurve arcCurve) { if (arcCurve == null) { return(null); } if (arcCurve.IsCompleteCircle) { RHG.Circle circle; arcCurve.TryGetCircle(out circle); return(circle.FromRhino()); } else { return(arcCurve.Arc.FromRhino()); } }
internal static GeometryBase CreateGeometryHelper(IntPtr pGeometry, object parent, int subobjectIndex) { if (IntPtr.Zero == pGeometry) { return(null); } var type = UnsafeNativeMethods.ON_Geometry_GetGeometryType(pGeometry); if (type < 0) { return(null); } GeometryBase rc = null; switch (type) { case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Curve: //1 rc = new Curve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_NurbsCurve: //2 rc = new NurbsCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PolyCurve: // 3 rc = new PolyCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PolylineCurve: //4 rc = new PolylineCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_ArcCurve: //5 rc = new ArcCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_LineCurve: //6 rc = new LineCurve(pGeometry, parent, subobjectIndex); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Mesh: //7 rc = new Mesh(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Point: //8 rc = new Point(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_TextDot: //9 rc = new TextDot(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Surface: //10 rc = new Surface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Brep: //11 rc = new Brep(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_NurbsSurface: //12 rc = new NurbsSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_RevSurface: //13 rc = new RevSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PlaneSurface: //14 rc = new PlaneSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_ClippingPlaneSurface: //15 rc = new ClippingPlaneSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Hatch: // 17 rc = new Hatch(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_SumSurface: //19 rc = new SumSurface(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepFace: //20 { int faceindex = -1; IntPtr ptr_brep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref faceindex); if (ptr_brep != IntPtr.Zero && faceindex >= 0) { Brep b = new Brep(ptr_brep, parent); rc = b.Faces[faceindex]; } } break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepEdge: // 21 { int edgeindex = -1; IntPtr ptr_brep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref edgeindex); if (ptr_brep != IntPtr.Zero && edgeindex >= 0) { Brep b = new Brep(ptr_brep, parent); rc = b.Edges[edgeindex]; } } break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_InstanceReference: // 23 rc = new InstanceReferenceGeometry(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Extrusion: //24 rc = new Extrusion(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PointCloud: // 26 rc = new PointCloud(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DetailView: // 27 rc = new DetailView(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Light: //32 rc = new Light(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PointGrid: //33 rc = new Point3dGrid(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_MorphControl: //34 rc = new MorphControl(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepLoop: //35 { int loopindex = -1; IntPtr ptr_brep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref loopindex); if (ptr_brep != IntPtr.Zero && loopindex >= 0) { Brep b = new Brep(ptr_brep, parent); rc = b.Loops[loopindex]; } } break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepTrim: // 36 { int trimindex = -1; IntPtr ptr_brep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref trimindex); if (ptr_brep != IntPtr.Zero && trimindex >= 0) { Brep b = new Brep(ptr_brep, parent); rc = b.Trims[trimindex]; } } break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Leader: // 38 rc = new Leader(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_SubD: // 39 rc = new SubD(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimLinear: //40 rc = new LinearDimension(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimAngular: //41 rc = new AngularDimension(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimRadial: //42 rc = new RadialDimension(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimOrdinate: //43 rc = new OrdinateDimension(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Centermark: //44 rc = new Centermark(pGeometry, parent); break; case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Text: //45 rc = new TextEntity(pGeometry, parent); break; default: rc = new UnknownGeometry(pGeometry, parent, subobjectIndex); break; } return(rc); }
internal static GeometryBase CreateGeometryHelper(IntPtr pGeometry, object parent, int subobject_index) { if (IntPtr.Zero == pGeometry) return null; int type = UnsafeNativeMethods.ON_Geometry_GetGeometryType(pGeometry); if (type < 0) return null; GeometryBase rc = null; switch (type) { case idxON_Curve: //1 rc = new Curve(pGeometry, parent, subobject_index); break; case idxON_NurbsCurve: //2 rc = new NurbsCurve(pGeometry, parent, subobject_index); break; case idxON_PolyCurve: // 3 rc = new PolyCurve(pGeometry, parent, subobject_index); break; case idxON_PolylineCurve: //4 rc = new PolylineCurve(pGeometry, parent, subobject_index); break; case idxON_ArcCurve: //5 rc = new ArcCurve(pGeometry, parent, subobject_index); break; case idxON_LineCurve: //6 rc = new LineCurve(pGeometry, parent, subobject_index); break; case idxON_Mesh: //7 rc = new Mesh(pGeometry, parent); break; case idxON_Point: //8 rc = new Point(pGeometry, parent); break; case idxON_TextDot: //9 rc = new TextDot(pGeometry, parent); break; case idxON_Surface: //10 rc = new Surface(pGeometry, parent); break; case idxON_Brep: //11 rc = new Brep(pGeometry, parent); break; case idxON_NurbsSurface: //12 rc = new NurbsSurface(pGeometry, parent); break; case idxON_RevSurface: //13 rc = new RevSurface(pGeometry, parent); break; case idxON_PlaneSurface: //14 rc = new PlaneSurface(pGeometry, parent); break; case idxON_ClippingPlaneSurface: //15 rc = new ClippingPlaneSurface(pGeometry, parent); break; case idxON_Annotation2: // 16 rc = new AnnotationBase(pGeometry, parent); break; case idxON_Hatch: // 17 rc = new Hatch(pGeometry, parent); break; case idxON_TextEntity2: //18 rc = new TextEntity(pGeometry, parent); break; case idxON_SumSurface: //19 rc = new SumSurface(pGeometry, parent); break; case idxON_BrepFace: //20 { int faceindex = -1; IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref faceindex); if (pBrep != IntPtr.Zero && faceindex >= 0) { Brep b = new Brep(pBrep, parent); rc = b.Faces[faceindex]; } } break; case idxON_BrepEdge: // 21 { int edgeindex = -1; IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref edgeindex); if (pBrep != IntPtr.Zero && edgeindex >= 0) { Brep b = new Brep(pBrep, parent); rc = b.Edges[edgeindex]; } } break; case idxON_InstanceDefinition: // 22 rc = new InstanceDefinitionGeometry(pGeometry, parent); break; case idxON_InstanceReference: // 23 rc = new InstanceReferenceGeometry(pGeometry, parent); break; #if USING_V5_SDK case idxON_Extrusion: //24 rc = new Extrusion(pGeometry, parent); break; #endif case idxON_LinearDimension2: //25 rc = new LinearDimension(pGeometry, parent); break; case idxON_PointCloud: // 26 rc = new PointCloud(pGeometry, parent); break; case idxON_DetailView: // 27 rc = new DetailView(pGeometry, parent); break; case idxON_AngularDimension2: // 28 rc = new AngularDimension(pGeometry, parent); break; case idxON_RadialDimension2: // 29 rc = new RadialDimension(pGeometry, parent); break; case idxON_Leader: // 30 rc = new Leader(pGeometry, parent); break; case idxON_OrdinateDimension2: // 31 rc = new OrdinateDimension(pGeometry, parent); break; case idxON_Light: //32 rc = new Light(pGeometry, parent); break; case idxON_PointGrid: //33 rc = new Point3dGrid(pGeometry, parent); break; case idxON_MorphControl: //34 rc = new MorphControl(pGeometry, parent); break; case idxON_BrepLoop: //35 { int loopindex = -1; IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref loopindex); if (pBrep != IntPtr.Zero && loopindex >= 0) { Brep b = new Brep(pBrep, parent); rc = b.Loops[loopindex]; } } break; case idxON_BrepTrim: // 36 { int trimindex = -1; IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref trimindex); if (pBrep != IntPtr.Zero && trimindex >= 0) { Brep b = new Brep(pBrep, parent); rc = b.Trims[trimindex]; } } break; default: rc = new UnknownGeometry(pGeometry, parent, subobject_index); break; } return rc; }
/***************************************************/ public static void RenderRhinoWires(RHG.ArcCurve arc, Rhino.Display.DisplayPipeline pipeline, Color bhColour, int thickness) { pipeline.DrawArc(arc.Arc, bhColour, thickness); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; View activeView = doc.ActiveView; //duplicated in the helper file! remember to change both double scale = 304.8; //string path = @"C:\Users\gbrog\Desktop\test.3dm"; string path = @"C:\Users\giovanni.brogiolo\Desktop\ST00-0221.3dm"; File3dm rhinoModel = File3dm.Read(path); List <Rhino.DocObjects.Layer> m_layers = rhinoModel.AllLayers.ToList(); List <string> layers = Get_RhinoLayerNames(rhinoModel); File3dmObject[] rhinoObjects = Get_RhinoObjects(rhinoModel); List <Rhino.Geometry.LineCurve> rh_lines = new List <Rhino.Geometry.LineCurve>(); List <Rhino.Geometry.ArcCurve> rh_arc = new List <Rhino.Geometry.ArcCurve>(); List <Rhino.Geometry.TextEntity> rh_text = new List <TextEntity>(); List <Rhino.Geometry.Leader> rh_textLeader = new List <Rhino.Geometry.Leader>(); List <Rhino.Geometry.LinearDimension> rh_linearDimension = new List <LinearDimension>(); List <List <Rhino.Geometry.Point3d> > rh_polylineCurvePoints = new List <List <Point3d> >(); List <Tuple <string, XYZ> > rh_Blocks = new List <Tuple <string, XYZ> >(); foreach (var item in rhinoObjects) { GeometryBase geo = item.Geometry; // check if geometry is a curve if (geo is Rhino.Geometry.LineCurve) { // add curve to list Rhino.Geometry.LineCurve ln = geo as Rhino.Geometry.LineCurve; rh_lines.Add(ln); } if (geo is Rhino.Geometry.ArcCurve) { // add curve to list Rhino.Geometry.ArcCurve arc = geo as Rhino.Geometry.ArcCurve; rh_arc.Add(arc); } if (!item.Attributes.IsInstanceDefinitionObject && geo is Rhino.Geometry.PolylineCurve) { PolylineCurve pc = geo as PolylineCurve; Polyline pl = pc.ToPolyline(); rh_polylineCurvePoints.Add(pl.ToList()); } if (geo is Rhino.Geometry.TextEntity) { TextEntity te = geo as Rhino.Geometry.TextEntity; rh_text.Add(te); } if (geo is Rhino.Geometry.Leader) { rh_textLeader.Add(geo as Rhino.Geometry.Leader); //var text = geo as Rhino.Geometry.Leader; //TaskDialog.Show("r", text.PlainText); } if (geo is Rhino.Geometry.AnnotationBase) { var text = geo as Rhino.Geometry.AnnotationBase; //TaskDialog.Show("r", text.PlainText); } if (geo is Rhino.Geometry.LinearDimension) { LinearDimension ld = geo as Rhino.Geometry.LinearDimension; rh_linearDimension.Add(ld); } if (geo is Rhino.Geometry.InstanceReferenceGeometry) { InstanceReferenceGeometry refGeo = (InstanceReferenceGeometry)geo; // Lookup the parent block definition System.Guid blockDefId = refGeo.ParentIdefId; InstanceDefinitionGeometry def = rhinoModel.AllInstanceDefinitions.FindId(blockDefId); // block definition name string defname = def.Name; //TaskDialog.Show("R", defname); // transform data for block instance Rhino.Geometry.Transform xform = refGeo.Xform; double x = refGeo.Xform.M03 / scale; double y = refGeo.Xform.M13 / scale; XYZ placementPt = new XYZ(x, y, 0); rh_Blocks.Add(new Tuple <string, XYZ>(defname, placementPt)); } } //TaskDialog.Show("r", rh_linearDimension.Count.ToString()); Rhynamo.clsGeometryConversionUtils rh_ds = new Rhynamo.clsGeometryConversionUtils(); using (Transaction t = new Transaction(doc, "Convert lines")) { t.Start(); rh_ds.Convert_rhLinesToRevitDetailCurve(doc, rh_lines, "3 Arup Continuous Line"); rh_ds.Convert_PolycurveToLines(doc, rh_polylineCurvePoints, "1 Arup Continuous Line"); rh_ds.Convert_ArcsToDS(doc, rh_arc); rh_ds.RhinoTextToRevitNote(doc, rh_text); rh_ds.RhinoLeaderToRevitNote(doc, rh_textLeader); rh_ds.RhinoToRevitDimension(doc, rh_linearDimension); rh_ds.Convert_rhBlocks(doc, rh_Blocks); t.Commit(); } TaskDialog.Show("r", "Done"); return(Result.Succeeded); }