Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Profile of the
- static List<XYZ> _profilepoints = new List<XYZ>()
- {
- new XYZ (-0.082020997, 0.000000000, 0.000000000),
- new XYZ(0.410104987, 0.000000000, 0.000000000),
- new XYZ (-0.082020997, 0.984251969, 0.000000000),
- new XYZ (-0.082020997, 0.000000000, 0.000000000),
- new XYZ (0.246062992, 0.984251969, 0.000000000),
- new XYZ(-0.082020997, 0.984251969, 0.000000000),
- new XYZ (0.410104987, 0.000000000, 0.000000000),
- new XYZ(0.410104987, 0.820209974, 0.000000000),
- new XYZ (0.246062992, 0.984251969, 0.000000000),
- new XYZ(0.410104987, 0.820209974, 0.000000000)
- };
- static public Document m_doc;
- public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- UIApplication uiapp = commandData.Application;
- UIDocument uidoc = uiapp.ActiveUIDocument;
- m_doc = uidoc.Document;
- IList<Reference> refs = null;
- refs = uidoc.Selection.PickObjects(ObjectType.Edge);
- Transaction tr = new Transaction(m_doc, "curvemodel");
- tr.Start();
- ReferenceArray rArr = new ReferenceArray();
- foreach (Reference r in refs)
- {
- Options op = new Options();
- op.ComputeReferences = true;
- Element e = m_doc.GetElement(r.ElementId);
- GeometryElement ge = e.get_Geometry(op);
- foreach (GeometryObject go in ge)
- {
- Solid solid = go as Solid;
- foreach (Edge edg in solid.Edges)
- {
- if (edg.Reference.ConvertToStableRepresentation(m_doc) == r.ConvertToStableRepresentation(m_doc))
- {
- SketchPlane plan = SketchPlane.Create(m_doc, edg.GetFace(0).Reference);
- ModelCurve mc = m_doc.FamilyCreate.NewModelCurve(edg.AsCurve(), plan);
- rArr.Append(mc.GeometryCurve.Reference);
- }
- }
- }
- }
- tr.Commit();
- Transaction t = new Transaction(m_doc, "Create Sweep2d");
- t.Start();
- createcurbs(m_doc, rArr); //Create 3D sweep
- t.Commit();
- return Result.Succeeded;
- }
- ///3Dsweep Method
- public void createcurbs(Document doc, ReferenceArray path3D)
- {
- FamilyItemFactory factory = doc.FamilyCreate;
- IList<Curve> cel = new List<Curve>();
- for (int i = 0; i < _profilepoints.Count; i = i + 2)
- {
- try
- {
- cel.Add(Line.CreateBound(_profilepoints[i], _profilepoints[i + 1]) as Curve);
- }
- catch (Exception)
- {
- cel.Add(Line.CreateBound(_profilepoints[i], _profilepoints[0]) as Curve);
- }
- }
- CurveArray sweepArray = DrawLoops.convert2Array(cel); //method to arrange Curves inorder to create a contiguous loop and then convert it to Array
- CurveArrArray swerarar = new CurveArrArray();
- swerarar.Append(sweepArray);
- SweepProfile swpprof = doc.Application.Create.NewCurveLoopsProfile(swerarar); // this is the profile
- // Create sweep solid
- Sweep sweep3D = factory.NewSweep(true, path3D, swpprof, 0, ProfilePlaneLocation.Start);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement